aboutsummaryrefslogtreecommitdiff
path: root/ext/fg/js/frontend.js
diff options
context:
space:
mode:
authorsiikamiika <siikamiika@users.noreply.github.com>2020-05-03 04:39:24 +0300
committerGitHub <noreply@github.com>2020-05-03 04:39:24 +0300
commit77b744e675f8abf17ff5e8433f4f1717e0c9ffb5 (patch)
tree037cb5c45dc1f9041130ea913d120e7f1526b1e1 /ext/fg/js/frontend.js
parentacfdaa4f483790cf3d70a2c1a59d82a422ebed1f (diff)
Modifier key profile condition (#487)
* update Frontend options on modifier change * add modifier key profile condition * use select element for modifier condition value * support "is" and "is not" modifier key conditions * use plural * remove dead null check it's never null in that function * pass element on rather than assigning to this * rename event * remove Firefox OS key to Meta detection * hide Meta from dropdown on Firefox * move input type
Diffstat (limited to 'ext/fg/js/frontend.js')
-rw-r--r--ext/fg/js/frontend.js27
1 files changed, 26 insertions, 1 deletions
diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js
index 76ad27e0..d979246d 100644
--- a/ext/fg/js/frontend.js
+++ b/ext/fg/js/frontend.js
@@ -50,6 +50,9 @@ class Frontend {
);
this._textScanner.onSearchSource = this.onSearchSource.bind(this);
+ this._activeModifiers = new Set();
+ this._optionsUpdatePending = false;
+
this._windowMessageHandlers = new Map([
['popupClose', () => this._textScanner.clearSelection(false)],
['selectionCopy', () => document.execCommand('copy')]
@@ -90,6 +93,7 @@ class Frontend {
chrome.runtime.onMessage.addListener(this.onRuntimeMessage.bind(this));
this._textScanner.on('clearSelection', this.onClearSelection.bind(this));
+ this._textScanner.on('activeModifiersChanged', this.onActiveModifiersChanged.bind(this));
this._updateContentScale();
this._broadcastRootPopupInformation();
@@ -173,12 +177,21 @@ class Frontend {
}
}
+ async updatePendingOptions() {
+ if (this._optionsUpdatePending) {
+ this._optionsUpdatePending = false;
+ await this.updateOptions();
+ }
+ }
+
async setTextSource(textSource) {
await this.onSearchSource(textSource, 'script');
this._textScanner.setCurrentTextSource(textSource);
}
async onSearchSource(textSource, cause) {
+ await this.updatePendingOptions();
+
let results = null;
try {
@@ -254,12 +267,24 @@ class Frontend {
onClearSelection({passive}) {
this.popup.hide(!passive);
this.popup.clearAutoPlayTimer();
+ this.updatePendingOptions();
+ }
+
+ async onActiveModifiersChanged({modifiers}) {
+ if (areSetsEqual(modifiers, this._activeModifiers)) { return; }
+ this._activeModifiers = modifiers;
+ if (await this.popup.isVisible()) {
+ this._optionsUpdatePending = true;
+ return;
+ }
+ await this.updateOptions();
}
async getOptionsContext() {
const url = this._getUrl !== null ? await this._getUrl() : window.location.href;
const depth = this.popup.depth;
- return {depth, url};
+ const modifierKeys = [...this._activeModifiers];
+ return {depth, url, modifierKeys};
}
_showPopupContent(textSource, optionsContext, type=null, details=null) {