cache created popups
This commit is contained in:
parent
7dd2610ce8
commit
b9035854b2
@ -71,31 +71,47 @@ async function main() {
|
|||||||
const data = window.frontendInitializationData || {};
|
const data = window.frontendInitializationData || {};
|
||||||
const {id, depth=0, parentFrameId, url, proxy=false, isSearchPage=false} = data;
|
const {id, depth=0, parentFrameId, url, proxy=false, isSearchPage=false} = data;
|
||||||
|
|
||||||
|
const isIframe = !proxy && (window !== window.parent);
|
||||||
|
|
||||||
const initEventDispatcher = new EventDispatcher();
|
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 optionsContext = {depth: isSearchPage ? 0 : depth, url};
|
||||||
const options = await apiOptionsGet(optionsContext);
|
const options = await apiOptionsGet(optionsContext);
|
||||||
if (isSearchPage) {
|
if (isSearchPage) {
|
||||||
const disabled = !options.scanning.enableOnSearchPage;
|
const disabled = !options.scanning.enableOnSearchPage;
|
||||||
initEventDispatcher.trigger('setDisabledOverride', {disabled});
|
initEventDispatcher.trigger('setDisabledOverride', {disabled});
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
const optionsContext = {depth, url};
|
|
||||||
const options = await apiOptionsGet(optionsContext);
|
|
||||||
|
|
||||||
let popup;
|
let popup;
|
||||||
if (!proxy && (window !== window.parent) && options.general.showIframePopupsInRootFrame) {
|
if (isIframe && options.general.showIframePopupsInRootFrame) {
|
||||||
popup = await createIframePopupProxy(url);
|
popup = popups.iframe || await createIframePopupProxy(url);
|
||||||
|
popups.iframe = popup;
|
||||||
} else if (proxy) {
|
} else if (proxy) {
|
||||||
popup = await createPopupProxy(depth, id, parentFrameId, url);
|
popup = popups.proxy || await createPopupProxy(depth, id, parentFrameId, url);
|
||||||
|
popups.proxy = popup;
|
||||||
} else {
|
} else {
|
||||||
popup = await getOrCreatePopup(depth);
|
popup = popups.normal || await getOrCreatePopup(depth);
|
||||||
|
popups.normal = popup;
|
||||||
}
|
}
|
||||||
|
|
||||||
const frontend = new Frontend(popup, initEventDispatcher);
|
if (frontend === null) {
|
||||||
|
frontend = new Frontend(popup, initEventDispatcher);
|
||||||
await frontend.prepare();
|
await frontend.prepare();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
yomichan.on('optionsUpdated', applyOptions);
|
||||||
|
|
||||||
|
await applyOptions();
|
||||||
}
|
}
|
||||||
|
|
||||||
main();
|
main();
|
||||||
|
Loading…
Reference in New Issue
Block a user