summaryrefslogtreecommitdiff
path: root/ext/fg/js/popup-nested.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2020-04-18 11:05:35 -0700
committerAlex Yatskov <alex@foosoft.net>2020-04-18 11:05:35 -0700
commitf2186c51e4ef219d158735d30a32bbf3e49c4e1a (patch)
tree61de35513b6182e83b626c1571bc2aa97234e3b0 /ext/fg/js/popup-nested.js
parentb3e79d0e396353de2cbefb945412bfda4bd6ca99 (diff)
parent9e7750125c40d1c4121e8d015957606721bede7c (diff)
Merge branch 'master' into testing
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();
+}