aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/bg/js')
-rw-r--r--ext/bg/js/backend.js12
-rw-r--r--ext/bg/js/background-main.js25
-rw-r--r--ext/bg/js/context-main.js (renamed from ext/bg/js/context.js)8
-rw-r--r--ext/bg/js/search-main.js (renamed from ext/bg/js/search-frontend.js)12
-rw-r--r--ext/bg/js/search.js8
-rw-r--r--ext/bg/js/settings/popup-preview-frame-main.js25
-rw-r--r--ext/bg/js/settings/popup-preview-frame.js11
7 files changed, 70 insertions, 31 deletions
diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js
index 8a19203f..693a9ad6 100644
--- a/ext/bg/js/backend.js
+++ b/ext/bg/js/backend.js
@@ -496,7 +496,7 @@ class Backend {
async _onApiDefinitionAdd({definition, mode, context, details, optionsContext}) {
const options = this.getOptions(optionsContext);
- const templates = this.defaultAnkiFieldTemplates;
+ const templates = this._getTemplates(options);
if (mode !== 'kanji') {
const {customSourceUrl} = options.audio;
@@ -522,7 +522,7 @@ class Backend {
async _onApiDefinitionsAddable({definitions, modes, context, optionsContext}) {
const options = this.getOptions(optionsContext);
- const templates = this.defaultAnkiFieldTemplates;
+ const templates = this._getTemplates(options);
const states = [];
try {
@@ -945,6 +945,11 @@ class Backend {
return handlebarsRenderDynamic(template, data);
}
+ _getTemplates(options) {
+ const templates = options.anki.fieldTemplates;
+ return typeof templates === 'string' ? templates : this.defaultAnkiFieldTemplates;
+ }
+
static _getTabUrl(tab) {
return new Promise((resolve) => {
chrome.tabs.sendMessage(tab.id, {action: 'getUrl'}, {frameId: 0}, (response) => {
@@ -1054,6 +1059,3 @@ class Backend {
}
}
}
-
-window.yomichanBackend = new Backend();
-window.yomichanBackend.prepare();
diff --git a/ext/bg/js/background-main.js b/ext/bg/js/background-main.js
new file mode 100644
index 00000000..24117f4e
--- /dev/null
+++ b/ext/bg/js/background-main.js
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2020 Yomichan Authors
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+/* global
+ * Backend
+ */
+
+(async () => {
+ window.yomichanBackend = new Backend();
+ await window.yomichanBackend.prepare();
+})();
diff --git a/ext/bg/js/context.js b/ext/bg/js/context-main.js
index e3d4ad4a..e2086a96 100644
--- a/ext/bg/js/context.js
+++ b/ext/bg/js/context-main.js
@@ -51,7 +51,7 @@ function setupButtonEvents(selector, command, url) {
}
}
-window.addEventListener('DOMContentLoaded', async () => {
+async function mainInner() {
await yomichan.prepare();
showExtensionInfo();
@@ -86,4 +86,8 @@ window.addEventListener('DOMContentLoaded', async () => {
}
}, 10);
});
-});
+}
+
+(async () => {
+ window.addEventListener('DOMContentLoaded', mainInner, false);
+})();
diff --git a/ext/bg/js/search-frontend.js b/ext/bg/js/search-main.js
index e534e771..38b6d99a 100644
--- a/ext/bg/js/search-frontend.js
+++ b/ext/bg/js/search-main.js
@@ -16,6 +16,7 @@
*/
/* global
+ * DisplaySearch
* apiOptionsGet
*/
@@ -27,7 +28,7 @@ function injectSearchFrontend() {
'/fg/js/popup.js',
'/fg/js/popup-proxy-host.js',
'/fg/js/frontend.js',
- '/fg/js/frontend-initialize.js'
+ '/fg/js/content-script-main.js'
];
for (const src of scriptSrcs) {
const node = document.querySelector(`script[src='${src}']`);
@@ -51,9 +52,12 @@ function injectSearchFrontend() {
}
}
-async function main() {
+(async () => {
await yomichan.prepare();
+ const displaySearch = new DisplaySearch();
+ await displaySearch.prepare();
+
let optionsApplied = false;
const applyOptions = async () => {
@@ -74,6 +78,4 @@ async function main() {
yomichan.on('optionsUpdated', applyOptions);
await applyOptions();
-}
-
-main();
+})();
diff --git a/ext/bg/js/search.js b/ext/bg/js/search.js
index 006536c0..684ea6d3 100644
--- a/ext/bg/js/search.js
+++ b/ext/bg/js/search.js
@@ -73,12 +73,6 @@ class DisplaySearch extends Display {
]);
}
- static create() {
- const instance = new DisplaySearch();
- instance.prepare();
- return instance;
- }
-
async prepare() {
try {
await super.prepare();
@@ -377,5 +371,3 @@ class DisplaySearch extends Display {
}
}
}
-
-DisplaySearch.instance = DisplaySearch.create();
diff --git a/ext/bg/js/settings/popup-preview-frame-main.js b/ext/bg/js/settings/popup-preview-frame-main.js
new file mode 100644
index 00000000..86c2814c
--- /dev/null
+++ b/ext/bg/js/settings/popup-preview-frame-main.js
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2019-2020 Yomichan Authors
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+/* global
+ * SettingsPopupPreview
+ */
+
+(async () => {
+ const instance = new SettingsPopupPreview();
+ await instance.prepare();
+})();
diff --git a/ext/bg/js/settings/popup-preview-frame.js b/ext/bg/js/settings/popup-preview-frame.js
index fba114e2..420a7c5a 100644
--- a/ext/bg/js/settings/popup-preview-frame.js
+++ b/ext/bg/js/settings/popup-preview-frame.js
@@ -41,12 +41,6 @@ class SettingsPopupPreview {
]);
}
- static create() {
- const instance = new SettingsPopupPreview();
- instance.prepare();
- return instance;
- }
-
async prepare() {
// Setup events
window.addEventListener('message', this.onMessage.bind(this), false);
@@ -178,8 +172,3 @@ class SettingsPopupPreview {
this.setInfoVisible(!this.popupShown);
}
}
-
-SettingsPopupPreview.instance = SettingsPopupPreview.create();
-
-
-