summaryrefslogtreecommitdiff
path: root/ext/fg/js
diff options
context:
space:
mode:
authorsiikamiika <siikamiika@users.noreply.github.com>2020-04-11 16:20:12 +0300
committersiikamiika <siikamiika@users.noreply.github.com>2020-04-11 21:04:30 +0300
commit5c3641eadb78144b7f6305ebbd574bbc6265a4c4 (patch)
tree5bfabfb95105cf32b24d2e3861fb725a85f943bc /ext/fg/js
parentd93e3e1a6727e23547c44d4fc3b82244f560c459 (diff)
simplify frontend disable override
Diffstat (limited to 'ext/fg/js')
-rw-r--r--ext/fg/js/frontend-initialize.js5
-rw-r--r--ext/fg/js/frontend.js15
2 files changed, 12 insertions, 8 deletions
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()) {