summaryrefslogtreecommitdiff
path: root/ext/fg/js/popup-nested.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/fg/js/popup-nested.js')
-rw-r--r--ext/fg/js/popup-nested.js49
1 files changed, 31 insertions, 18 deletions
diff --git a/ext/fg/js/popup-nested.js b/ext/fg/js/popup-nested.js
index 1b24614b..c140f9c8 100644
--- a/ext/fg/js/popup-nested.js
+++ b/ext/fg/js/popup-nested.js
@@ -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,33 @@ async function popupNestedInitialize(id, depth, parentFrameId, url) {
document.body.appendChild(script);
}
}
+
+async function popupNestedInitialize(id, depth, parentFrameId, url) {
+ let optionsApplied = false;
+
+ const applyOptions = async () => {
+ const optionsContext = {depth, url};
+ const options = await apiOptionsGet(optionsContext);
+ const popupNestingMaxDepth = options.scanning.popupNestingMaxDepth;
+
+ const maxPopupDepthExceeded = !(
+ typeof popupNestingMaxDepth === 'number' &&
+ typeof depth === 'number' &&
+ depth < popupNestingMaxDepth
+ );
+ if (maxPopupDepthExceeded || optionsApplied) {
+ return;
+ }
+
+ optionsApplied = true;
+
+ window.frontendInitializationData = {id, depth, parentFrameId, url, proxy: true};
+ injectPopupNested();
+
+ yomichan.off('optionsUpdated', applyOptions);
+ };
+
+ yomichan.on('optionsUpdated', applyOptions);
+
+ await applyOptions();
+}