diff options
Diffstat (limited to 'ext/fg/js/frontend-initialize.js')
-rw-r--r-- | ext/fg/js/frontend-initialize.js | 50 |
1 files changed, 33 insertions, 17 deletions
diff --git a/ext/fg/js/frontend-initialize.js b/ext/fg/js/frontend-initialize.js index db581b93..2cfb6176 100644 --- a/ext/fg/js/frontend-initialize.js +++ b/ext/fg/js/frontend-initialize.js @@ -71,31 +71,47 @@ async function main() { const data = window.frontendInitializationData || {}; const {id, depth=0, parentFrameId, url, proxy=false, isSearchPage=false} = data; + const isIframe = !proxy && (window !== window.parent); + const initEventDispatcher = new EventDispatcher(); - yomichan.on('optionsUpdated', async () => { + const popups = { + iframe: null, + proxy: null, + normal: null + }; + + let frontend = null; + + const applyOptions = async () => { const optionsContext = {depth: isSearchPage ? 0 : depth, url}; const options = await apiOptionsGet(optionsContext); if (isSearchPage) { const disabled = !options.scanning.enableOnSearchPage; initEventDispatcher.trigger('setDisabledOverride', {disabled}); } - }); - - const optionsContext = {depth, url}; - const options = await apiOptionsGet(optionsContext); - - let popup; - if (!proxy && (window !== window.parent) && options.general.showIframePopupsInRootFrame) { - popup = await createIframePopupProxy(url); - } else if (proxy) { - popup = await createPopupProxy(depth, id, parentFrameId, url); - } else { - popup = await getOrCreatePopup(depth); - } - - const frontend = new Frontend(popup, initEventDispatcher); - await frontend.prepare(); + + let popup; + if (isIframe && options.general.showIframePopupsInRootFrame) { + popup = popups.iframe || await createIframePopupProxy(url); + popups.iframe = popup; + } else if (proxy) { + popup = popups.proxy || await createPopupProxy(depth, id, parentFrameId, url); + popups.proxy = popup; + } else { + popup = popups.normal || await getOrCreatePopup(depth); + popups.normal = popup; + } + + if (frontend === null) { + frontend = new Frontend(popup, initEventDispatcher); + await frontend.prepare(); + } + }; + + yomichan.on('optionsUpdated', applyOptions); + + await applyOptions(); } main(); |