allow disabling scan on search page live

This commit is contained in:
siikamiika 2020-04-10 03:55:25 +03:00
parent 1df59d57b5
commit 92109bb5d2
3 changed files with 30 additions and 5 deletions

View File

@ -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);

View File

@ -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();
}

View File

@ -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;