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/fg/js/popup-nested.js | |
parent | 3b9a87b2ebe843e30536924639d6c14afef936cd (diff) | |
parent | 8c16a6e580bfdd70e27df1816ca90807062cf9b5 (diff) |
Merge branch 'master' of https://github.com/FooSoft/yomichan
Diffstat (limited to 'ext/fg/js/popup-nested.js')
-rw-r--r-- | ext/fg/js/popup-nested.js | 49 |
1 files changed, 31 insertions, 18 deletions
diff --git a/ext/fg/js/popup-nested.js b/ext/fg/js/popup-nested.js index 1b24614b..c140f9c8 100644 --- a/ext/fg/js/popup-nested.js +++ b/ext/fg/js/popup-nested.js @@ -19,24 +19,7 @@ * apiOptionsGet */ -let popupNestedInitialized = false; - -async function popupNestedInitialize(id, depth, parentFrameId, url) { - if (popupNestedInitialized) { - return; - } - popupNestedInitialized = true; - - const optionsContext = {depth, url}; - const options = await apiOptionsGet(optionsContext); - const popupNestingMaxDepth = options.scanning.popupNestingMaxDepth; - - if (!(typeof popupNestingMaxDepth === 'number' && typeof depth === 'number' && depth < popupNestingMaxDepth)) { - return; - } - - window.frontendInitializationData = {id, depth, parentFrameId, url, proxy: true}; - +function injectPopupNested() { const scriptSrcs = [ '/mixed/js/text-scanner.js', '/fg/js/frontend-api-sender.js', @@ -52,3 +35,33 @@ async function popupNestedInitialize(id, depth, parentFrameId, url) { document.body.appendChild(script); } } + +async function popupNestedInitialize(id, depth, parentFrameId, url) { + let optionsApplied = false; + + const applyOptions = async () => { + const optionsContext = {depth, url}; + const options = await apiOptionsGet(optionsContext); + const popupNestingMaxDepth = options.scanning.popupNestingMaxDepth; + + const maxPopupDepthExceeded = !( + typeof popupNestingMaxDepth === 'number' && + typeof depth === 'number' && + depth < popupNestingMaxDepth + ); + if (maxPopupDepthExceeded || optionsApplied) { + return; + } + + optionsApplied = true; + + window.frontendInitializationData = {id, depth, parentFrameId, url, proxy: true}; + injectPopupNested(); + + yomichan.off('optionsUpdated', applyOptions); + }; + + yomichan.on('optionsUpdated', applyOptions); + + await applyOptions(); +} |