summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
Diffstat (limited to 'ext')
-rw-r--r--ext/bg/js/search-frontend.js2
-rw-r--r--ext/fg/js/frontend-initialize.js15
-rw-r--r--ext/fg/js/frontend.js18
3 files changed, 30 insertions, 5 deletions
diff --git a/ext/bg/js/search-frontend.js b/ext/bg/js/search-frontend.js
index 18cb6060..e534e771 100644
--- a/ext/bg/js/search-frontend.js
+++ b/ext/bg/js/search-frontend.js
@@ -65,7 +65,7 @@ async function main() {
if (!options.scanning.enableOnSearchPage || optionsApplied) { return; }
optionsApplied = true;
- window.frontendInitializationData = {depth: 1, proxy: false};
+ window.frontendInitializationData = {depth: 1, proxy: false, isSearchPage: true};
injectSearchFrontend();
yomichan.off('optionsUpdated', applyOptions);
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;