summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorsiikamiika <siikamiika@users.noreply.github.com>2020-04-10 01:42:02 +0300
committersiikamiika <siikamiika@users.noreply.github.com>2020-04-11 21:01:27 +0300
commit8c9389e07d21c3f71184f453c0db11ca7cfb8121 (patch)
tree75e0855a8916dbf14439792ba6725ac5fab47ccb /ext
parent82f83970001682018f1f5b595ffdcd13123fed91 (diff)
listen to optionsUpdated in search-frontend.js
Diffstat (limited to 'ext')
-rw-r--r--ext/bg/js/search-frontend.js37
1 files changed, 24 insertions, 13 deletions
diff --git a/ext/bg/js/search-frontend.js b/ext/bg/js/search-frontend.js
index 9cc1436f..48326caf 100644
--- a/ext/bg/js/search-frontend.js
+++ b/ext/bg/js/search-frontend.js
@@ -19,18 +19,7 @@
* apiOptionsGet
*/
-async function searchFrontendSetup() {
- await yomichan.prepare();
-
- const optionsContext = {
- depth: 0,
- url: window.location.href
- };
- const options = await apiOptionsGet(optionsContext);
- if (!options.scanning.enableOnSearchPage) { return; }
-
- window.frontendInitializationData = {depth: 1, proxy: false};
-
+function injectSearchFrontend() {
const scriptSrcs = [
'/mixed/js/text-scanner.js',
'/fg/js/frontend-api-receiver.js',
@@ -62,4 +51,26 @@ async function searchFrontendSetup() {
}
}
-searchFrontendSetup();
+async function main() {
+ await yomichan.prepare();
+
+ const applyOptions = async () => {
+ const optionsContext = {
+ depth: 0,
+ url: window.location.href
+ };
+ const options = await apiOptionsGet(optionsContext);
+ if (!options.scanning.enableOnSearchPage) { return; }
+
+ window.frontendInitializationData = {depth: 1, proxy: false};
+ injectSearchFrontend();
+
+ yomichan.off('optionsUpdated', applyOptions);
+ };
+
+ yomichan.on('optionsUpdated', applyOptions);
+
+ await applyOptions();
+}
+
+main();