change iframe popup live

This commit is contained in:
siikamiika 2020-04-10 15:49:56 +03:00
parent b9035854b2
commit 565e3a8c6a
3 changed files with 19 additions and 7 deletions

View File

@ -86,10 +86,6 @@ async function main() {
const applyOptions = async () => { const applyOptions = async () => {
const optionsContext = {depth: isSearchPage ? 0 : depth, url}; const optionsContext = {depth: isSearchPage ? 0 : depth, url};
const options = await apiOptionsGet(optionsContext); const options = await apiOptionsGet(optionsContext);
if (isSearchPage) {
const disabled = !options.scanning.enableOnSearchPage;
initEventDispatcher.trigger('setDisabledOverride', {disabled});
}
let popup; let popup;
if (isIframe && options.general.showIframePopupsInRootFrame) { if (isIframe && options.general.showIframePopupsInRootFrame) {
@ -103,6 +99,15 @@ async function main() {
popups.normal = popup; popups.normal = popup;
} }
if (isSearchPage) {
const disabled = !options.scanning.enableOnSearchPage;
initEventDispatcher.trigger('setDisabledOverride', {disabled});
}
if (isIframe) {
initEventDispatcher.trigger('popupChange', {popup});
}
if (frontend === null) { if (frontend === null) {
frontend = new Frontend(popup, initEventDispatcher); frontend = new Frontend(popup, initEventDispatcher);
await frontend.prepare(); await frontend.prepare();

View File

@ -29,7 +29,7 @@ class Frontend extends TextScanner {
constructor(popup, initEventDispatcher) { constructor(popup, initEventDispatcher) {
super( super(
window, window,
popup.isProxy() ? [] : [popup.getContainer()], () => this.popup.isProxy() ? [] : [this.popup.getContainer()],
[(x, y) => this.popup.containsPoint(x, y)], [(x, y) => this.popup.containsPoint(x, y)],
() => this.popup.depth <= this.options.scanning.popupNestingMaxDepth && !this._disabledOverride () => 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('setDisabledOverride', this.onSetDisabledOverride.bind(this));
this.initEventDispatcher.on('popupChange', this.onPopupChange.bind(this));
yomichan.on('orphaned', this.onOrphaned.bind(this)); yomichan.on('orphaned', this.onOrphaned.bind(this));
yomichan.on('optionsUpdated', this.updateOptions.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() { getOptionsContext() {
this.optionsContext.url = this.popup.url; this.optionsContext.url = this.popup.url;
return this.optionsContext; return this.optionsContext;
@ -274,7 +281,7 @@ class Frontend extends TextScanner {
} }
_broadcastRootPopupInformation() { _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}); apiBroadcastTab('rootPopupInformation', {popupId: this.popup.id, frameId: this.popup.frameId});
} }
} }

View File

@ -48,7 +48,7 @@ class TextScanner {
} }
onMouseOver(e) { onMouseOver(e) {
if (this.ignoreElements.includes(e.target)) { if (this.ignoreElements().includes(e.target)) {
this.scanTimerClear(); this.scanTimerClear();
} }
} }