diff options
author | Alex Yatskov <alex@foosoft.net> | 2020-04-16 17:30:09 -0700 |
---|---|---|
committer | Alex Yatskov <alex@foosoft.net> | 2020-04-16 17:30:09 -0700 |
commit | 93c4fb9eab2651da24fb816f20dcb967eae1437e (patch) | |
tree | df8f6d5e04da7e6e78db4712d4d3d92c460454b9 /ext/bg/js/search-frontend.js | |
parent | 3b9a87b2ebe843e30536924639d6c14afef936cd (diff) | |
parent | 8c16a6e580bfdd70e27df1816ca90807062cf9b5 (diff) |
Merge branch 'master' of https://github.com/FooSoft/yomichan
Diffstat (limited to 'ext/bg/js/search-frontend.js')
-rw-r--r-- | ext/bg/js/search-frontend.js | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/ext/bg/js/search-frontend.js b/ext/bg/js/search-frontend.js index 9cc1436f..e534e771 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,29 @@ async function searchFrontendSetup() { } } -searchFrontendSetup(); +async function main() { + await yomichan.prepare(); + + let optionsApplied = false; + + const applyOptions = async () => { + const optionsContext = { + depth: 0, + url: window.location.href + }; + const options = await apiOptionsGet(optionsContext); + if (!options.scanning.enableOnSearchPage || optionsApplied) { return; } + optionsApplied = true; + + window.frontendInitializationData = {depth: 1, proxy: false, isSearchPage: true}; + injectSearchFrontend(); + + yomichan.off('optionsUpdated', applyOptions); + }; + + yomichan.on('optionsUpdated', applyOptions); + + await applyOptions(); +} + +main(); |