listen to optionsUpdated in popup-nested.js

This commit is contained in:
siikamiika 2020-04-10 02:05:34 +03:00
parent 8c9389e07d
commit 9adbc80a70

View File

@ -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();
}