summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorsiikamiika <siikamiika@users.noreply.github.com>2020-04-10 02:05:34 +0300
committersiikamiika <siikamiika@users.noreply.github.com>2020-04-11 21:01:27 +0300
commit9adbc80a70ea263ae97a853c3d9bb0b6109503bd (patch)
tree9fa6af62e7f293eabf01eec36dde2ce9ac385b37 /ext
parent8c9389e07d21c3f71184f453c0db11ca7cfb8121 (diff)
listen to optionsUpdated in popup-nested.js
Diffstat (limited to 'ext')
-rw-r--r--ext/fg/js/popup-nested.js47
1 files changed, 29 insertions, 18 deletions
diff --git a/ext/fg/js/popup-nested.js b/ext/fg/js/popup-nested.js
index 1b24614b..f193aa36 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,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();
+}