aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsiikamiika <siikamiika@users.noreply.github.com>2020-04-10 15:21:13 +0300
committersiikamiika <siikamiika@users.noreply.github.com>2020-04-11 21:03:22 +0300
commitb9035854b2b45979c16f8733bb66993f6ce044fe (patch)
treebc405ab9e6bd80dce6c6a30f8922e320b9486d8f
parent7dd2610ce844986feed72720378d7da601c44d27 (diff)
cache created popups
-rw-r--r--ext/fg/js/frontend-initialize.js50
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();