summaryrefslogtreecommitdiff
path: root/ext/fg/js/popup-nested.js
diff options
context:
space:
mode:
authorsiikamiika <siikamiika@users.noreply.github.com>2020-04-17 01:31:25 +0300
committerGitHub <noreply@github.com>2020-04-17 01:31:25 +0300
commite6053eefa594524c7adcec4986a5a2c499adf192 (patch)
tree5a42ad3163455eda4306fbb5964f8b7fec20bf82 /ext/fg/js/popup-nested.js
parentbf971be15bf8787f992f03bb5943e3ee32c1583a (diff)
parentb6f7f8c02637cef9cadd4ab2b9f253c42903aee6 (diff)
Merge pull request #439 from siikamiika/popup-live-toggle
Popup live toggle
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();
+}