From 1df59d57b5dcbf9d3efedcb21a4d5e16524a67c1 Mon Sep 17 00:00:00 2001 From: siikamiika Date: Fri, 10 Apr 2020 02:48:41 +0300 Subject: limit popup depth live --- ext/mixed/js/text-scanner.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'ext/mixed/js') diff --git a/ext/mixed/js/text-scanner.js b/ext/mixed/js/text-scanner.js index a1d96320..1d6e36e0 100644 --- a/ext/mixed/js/text-scanner.js +++ b/ext/mixed/js/text-scanner.js @@ -22,11 +22,13 @@ */ class TextScanner { - constructor(node, ignoreElements, ignorePoints) { + constructor(node, ignoreElements, ignorePoints, canEnable=null) { this.node = node; this.ignoreElements = ignoreElements; this.ignorePoints = ignorePoints; + this.canEnable = canEnable; + this.ignoreNodes = null; this.scanTimerPromise = null; @@ -225,6 +227,10 @@ class TextScanner { } setEnabled(enabled) { + if (this.canEnable !== null && !this.canEnable()) { + enabled = false; + } + if (enabled) { if (!this.enabled) { this.hookEvents(); -- cgit v1.2.3 From 565e3a8c6ad31afa0ddb171ac5a33b6b84e5c3dc Mon Sep 17 00:00:00 2001 From: siikamiika Date: Fri, 10 Apr 2020 15:49:56 +0300 Subject: change iframe popup live --- ext/fg/js/frontend-initialize.js | 13 +++++++++---- ext/fg/js/frontend.js | 11 +++++++++-- ext/mixed/js/text-scanner.js | 2 +- 3 files changed, 19 insertions(+), 7 deletions(-) (limited to 'ext/mixed/js') diff --git a/ext/fg/js/frontend-initialize.js b/ext/fg/js/frontend-initialize.js index 2cfb6176..ce1a6bf6 100644 --- a/ext/fg/js/frontend-initialize.js +++ b/ext/fg/js/frontend-initialize.js @@ -86,10 +86,6 @@ async function main() { const applyOptions = async () => { const optionsContext = {depth: isSearchPage ? 0 : depth, url}; const options = await apiOptionsGet(optionsContext); - if (isSearchPage) { - const disabled = !options.scanning.enableOnSearchPage; - initEventDispatcher.trigger('setDisabledOverride', {disabled}); - } let popup; if (isIframe && options.general.showIframePopupsInRootFrame) { @@ -103,6 +99,15 @@ async function main() { popups.normal = popup; } + if (isSearchPage) { + const disabled = !options.scanning.enableOnSearchPage; + initEventDispatcher.trigger('setDisabledOverride', {disabled}); + } + + if (isIframe) { + initEventDispatcher.trigger('popupChange', {popup}); + } + if (frontend === null) { frontend = new Frontend(popup, initEventDispatcher); await frontend.prepare(); diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js index a6df4b4c..f969df32 100644 --- a/ext/fg/js/frontend.js +++ b/ext/fg/js/frontend.js @@ -29,7 +29,7 @@ class Frontend extends TextScanner { constructor(popup, initEventDispatcher) { super( window, - popup.isProxy() ? [] : [popup.getContainer()], + () => this.popup.isProxy() ? [] : [this.popup.getContainer()], [(x, y) => this.popup.containsPoint(x, y)], () => this.popup.depth <= this.options.scanning.popupNestingMaxDepth && !this._disabledOverride ); @@ -78,6 +78,7 @@ class Frontend extends TextScanner { } this.initEventDispatcher.on('setDisabledOverride', this.onSetDisabledOverride.bind(this)); + this.initEventDispatcher.on('popupChange', this.onPopupChange.bind(this)); yomichan.on('orphaned', this.onOrphaned.bind(this)); yomichan.on('optionsUpdated', this.updateOptions.bind(this)); @@ -242,6 +243,12 @@ class Frontend extends TextScanner { } } + async onPopupChange({popup}) { + this.onSearchClear(true); + this.popup = popup; + await popup.setOptions(this.options); + } + getOptionsContext() { this.optionsContext.url = this.popup.url; return this.optionsContext; @@ -274,7 +281,7 @@ class Frontend extends TextScanner { } _broadcastRootPopupInformation() { - if (!this.popup.isProxy() && this.popup.depth === 0) { + if (!this.popup.isProxy() && this.popup.depth === 0 && this.popup.frameId === 0) { apiBroadcastTab('rootPopupInformation', {popupId: this.popup.id, frameId: this.popup.frameId}); } } diff --git a/ext/mixed/js/text-scanner.js b/ext/mixed/js/text-scanner.js index 1d6e36e0..85be7119 100644 --- a/ext/mixed/js/text-scanner.js +++ b/ext/mixed/js/text-scanner.js @@ -48,7 +48,7 @@ class TextScanner { } onMouseOver(e) { - if (this.ignoreElements.includes(e.target)) { + if (this.ignoreElements().includes(e.target)) { this.scanTimerClear(); } } -- cgit v1.2.3 From 5c3641eadb78144b7f6305ebbd574bbc6265a4c4 Mon Sep 17 00:00:00 2001 From: siikamiika Date: Sat, 11 Apr 2020 16:20:12 +0300 Subject: simplify frontend disable override --- ext/fg/js/frontend-initialize.js | 5 ++++- ext/fg/js/frontend.js | 15 ++++++++------- ext/mixed/js/text-scanner.js | 16 +++++----------- 3 files changed, 17 insertions(+), 19 deletions(-) (limited to 'ext/mixed/js') diff --git a/ext/fg/js/frontend-initialize.js b/ext/fg/js/frontend-initialize.js index 34be6bc6..e794c7c0 100644 --- a/ext/fg/js/frontend-initialize.js +++ b/ext/fg/js/frontend-initialize.js @@ -80,6 +80,7 @@ async function main() { }; let frontend = null; + let frontendPreparePromise = null; const applyOptions = async () => { const optionsContext = {depth: isSearchPage ? 0 : depth, url}; @@ -99,8 +100,10 @@ async function main() { if (frontend === null) { frontend = new Frontend(popup); - await frontend.prepare(); + frontendPreparePromise = frontend.prepare(); + await frontendPreparePromise; } else { + await frontendPreparePromise; if (isSearchPage) { const disabled = !options.scanning.enableOnSearchPage; frontend.setDisabledOverride(disabled); diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js index 288d3589..20bfc638 100644 --- a/ext/fg/js/frontend.js +++ b/ext/fg/js/frontend.js @@ -30,8 +30,7 @@ class Frontend extends TextScanner { super( window, () => this.popup.isProxy() ? [] : [this.popup.getContainer()], - [(x, y) => this.popup.containsPoint(x, y)], - () => this.popup.depth <= this.options.scanning.popupNestingMaxDepth && !this._disabledOverride + [(x, y) => this.popup.containsPoint(x, y)] ); this.popup = popup; @@ -138,10 +137,7 @@ class Frontend extends TextScanner { setDisabledOverride(disabled) { this._disabledOverride = disabled; - // other cases handed by regular options update - if (disabled && this.enabled) { - this.setEnabled(false); - } + this.setEnabled(this.options.general.enable, this._canEnable()); } async setPopup(popup) { @@ -151,7 +147,7 @@ class Frontend extends TextScanner { } async updateOptions() { - this.setOptions(await apiOptionsGet(this.getOptionsContext())); + this.setOptions(await apiOptionsGet(this.getOptionsContext()), this._canEnable()); const ignoreNodes = ['.scan-disable', '.scan-disable *']; if (!this.options.scanning.enableOnPopupExpressions) { @@ -290,6 +286,11 @@ class Frontend extends TextScanner { }); } + _canEnable() { + if (this.options === null) { return true; } // called by updateOptions for the first time + return this.popup.depth <= this.options.scanning.popupNestingMaxDepth && !this._disabledOverride; + } + async _updatePopupPosition() { const textSource = this.getCurrentTextSource(); if (textSource !== null && await this.popup.isVisible()) { diff --git a/ext/mixed/js/text-scanner.js b/ext/mixed/js/text-scanner.js index 85be7119..bff9544f 100644 --- a/ext/mixed/js/text-scanner.js +++ b/ext/mixed/js/text-scanner.js @@ -22,13 +22,11 @@ */ class TextScanner { - constructor(node, ignoreElements, ignorePoints, canEnable=null) { + constructor(node, ignoreElements, ignorePoints) { this.node = node; this.ignoreElements = ignoreElements; this.ignorePoints = ignorePoints; - this.canEnable = canEnable; - this.ignoreNodes = null; this.scanTimerPromise = null; @@ -226,12 +224,8 @@ class TextScanner { } } - setEnabled(enabled) { - if (this.canEnable !== null && !this.canEnable()) { - enabled = false; - } - - if (enabled) { + setEnabled(enabled, canEnable) { + if (enabled && canEnable) { if (!this.enabled) { this.hookEvents(); this.enabled = true; @@ -277,9 +271,9 @@ class TextScanner { ]; } - setOptions(options) { + setOptions(options, canEnable=true) { this.options = options; - this.setEnabled(this.options.general.enable); + this.setEnabled(this.options.general.enable, canEnable); } async searchAt(x, y, cause) { -- cgit v1.2.3