From b9035854b2b45979c16f8733bb66993f6ce044fe Mon Sep 17 00:00:00 2001 From: siikamiika Date: Fri, 10 Apr 2020 15:21:13 +0300 Subject: cache created popups --- ext/fg/js/frontend-initialize.js | 50 ++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 17 deletions(-) (limited to 'ext/fg') 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(); -- cgit v1.2.3