From 9adbc80a70ea263ae97a853c3d9bb0b6109503bd Mon Sep 17 00:00:00 2001 From: siikamiika Date: Fri, 10 Apr 2020 02:05:34 +0300 Subject: [PATCH] listen to optionsUpdated in popup-nested.js --- ext/fg/js/popup-nested.js | 47 ++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/ext/fg/js/popup-nested.js b/ext/fg/js/popup-nested.js index 1b24614b..f193aa36 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,31 @@ async function popupNestedInitialize(id, depth, parentFrameId, url) { document.body.appendChild(script); } } + +let popupNestedInitialized = false; + +async function popupNestedInitialize(id, depth, parentFrameId, url) { + if (popupNestedInitialized) { + return; + } + popupNestedInitialized = true; + + const applyOptions = async () => { + 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}; + injectPopupNested(); + + yomichan.off('optionsUpdated', applyOptions); + }; + + yomichan.on('optionsUpdated', applyOptions); + + await applyOptions(); +}