diff options
Diffstat (limited to 'ext/fg/js')
| -rw-r--r-- | ext/fg/js/frontend-initialize.js | 15 | ||||
| -rw-r--r-- | ext/fg/js/frontend.js | 18 | 
2 files changed, 29 insertions, 4 deletions
| diff --git a/ext/fg/js/frontend-initialize.js b/ext/fg/js/frontend-initialize.js index 5af7fdf0..3fe5ac5b 100644 --- a/ext/fg/js/frontend-initialize.js +++ b/ext/fg/js/frontend-initialize.js @@ -28,7 +28,18 @@ async function main() {      await yomichan.prepare();      const data = window.frontendInitializationData || {}; -    const {id, depth=0, parentFrameId, url, proxy=false} = data; +    const {id, depth=0, parentFrameId, url, proxy=false, isSearchPage=false} = data; + +    const initEventDispatcher = new EventDispatcher(); + +    yomichan.on('optionsUpdated', async () => { +        const optionsContext = {depth: isSearchPage ? 0 : depth, url}; +        const options = await apiOptionsGet(optionsContext); +        if (isSearchPage) { +            const disabled = !options.scanning.enableOnSearchPage; +            initEventDispatcher.trigger('setDisabledOverride', {disabled}); +        } +    });      const optionsContext = {depth, url};      const options = await apiOptionsGet(optionsContext); @@ -65,7 +76,7 @@ async function main() {          popup = popupHost.getOrCreatePopup(null, null, depth);      } -    const frontend = new Frontend(popup); +    const frontend = new Frontend(popup, initEventDispatcher);      await frontend.prepare();  } diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js index a6b24c76..a6df4b4c 100644 --- a/ext/fg/js/frontend.js +++ b/ext/fg/js/frontend.js @@ -26,15 +26,19 @@   */  class Frontend extends TextScanner { -    constructor(popup) { +    constructor(popup, initEventDispatcher) {          super(              window,              popup.isProxy() ? [] : [popup.getContainer()],              [(x, y) => this.popup.containsPoint(x, y)], -            () => this.popup.depth <= this.options.scanning.popupNestingMaxDepth +            () => this.popup.depth <= this.options.scanning.popupNestingMaxDepth && !this._disabledOverride          );          this.popup = popup; +        this.initEventDispatcher = initEventDispatcher; + +        this._disabledOverride = false; +          this.options = null;          this.optionsContext = { @@ -73,6 +77,8 @@ class Frontend extends TextScanner {                  window.visualViewport.addEventListener('resize', this.onVisualViewportResize.bind(this));              } +            this.initEventDispatcher.on('setDisabledOverride', this.onSetDisabledOverride.bind(this)); +              yomichan.on('orphaned', this.onOrphaned.bind(this));              yomichan.on('optionsUpdated', this.updateOptions.bind(this));              yomichan.on('zoomChanged', this.onZoomChanged.bind(this)); @@ -228,6 +234,14 @@ class Frontend extends TextScanner {          super.onSearchClear(changeFocus);      } +    onSetDisabledOverride({disabled}) { +        this._disabledOverride = disabled; +        // other cases handed by regular options update +        if (disabled && this.enabled) { +            this.setEnabled(false); +        } +    } +      getOptionsContext() {          this.optionsContext.url = this.popup.url;          return this.optionsContext; |