aboutsummaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
Diffstat (limited to 'ext')
-rw-r--r--ext/bg/data/options-schema.json28
-rw-r--r--ext/bg/js/options.js7
-rw-r--r--ext/bg/settings.html10
-rw-r--r--ext/fg/js/frontend.js13
-rw-r--r--ext/mixed/js/display.js3
-rw-r--r--ext/mixed/js/text-scanner.js21
6 files changed, 76 insertions, 6 deletions
diff --git a/ext/bg/data/options-schema.json b/ext/bg/data/options-schema.json
index 2e324984..80f8d782 100644
--- a/ext/bg/data/options-schema.json
+++ b/ext/bg/data/options-schema.json
@@ -320,6 +320,7 @@
"type": "object",
"required": [
"inputs",
+ "preventMiddleMouse",
"touchInputEnabled",
"pointerEventsEnabled",
"selectText",
@@ -454,6 +455,33 @@
}
}
},
+ "preventMiddleMouse": {
+ "type": "object",
+ "required": [
+ "onWebPages",
+ "onPopupPages",
+ "onSearchPages",
+ "onSearchQuery"
+ ],
+ "properties": {
+ "onWebPages": {
+ "type": "boolean",
+ "default": false
+ },
+ "onPopupPages": {
+ "type": "boolean",
+ "default": false
+ },
+ "onSearchPages": {
+ "type": "boolean",
+ "default": false
+ },
+ "onSearchQuery": {
+ "type": "boolean",
+ "default": false
+ }
+ }
+ },
"touchInputEnabled": {
"type": "boolean",
"default": true
diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js
index f9571ec2..cf24645a 100644
--- a/ext/bg/js/options.js
+++ b/ext/bg/js/options.js
@@ -507,6 +507,7 @@ class OptionsUtil {
// Added hideDelay.
// Added inputs to profileOptions.scanning.
// Added pointerEventsEnabled to profileOptions.scanning.
+ // Added preventMiddleMouse to profileOptions.scanning.
for (const {conditionGroups} of options.profiles) {
for (const {conditions} of conditionGroups) {
for (const condition of conditions) {
@@ -531,6 +532,12 @@ class OptionsUtil {
profileOptions.general.usePopupWindow = false;
profileOptions.scanning.hideDelay = 0;
profileOptions.scanning.pointerEventsEnabled = false;
+ profileOptions.scanning.preventMiddleMouse = {
+ onWebPages: false,
+ onPopupPages: false,
+ onSearchPages: false,
+ onSearchQuery: false
+ };
const {modifier, middleMouse} = profileOptions.scanning;
delete profileOptions.scanning.modifier;
diff --git a/ext/bg/settings.html b/ext/bg/settings.html
index 9c8621f7..8dea0245 100644
--- a/ext/bg/settings.html
+++ b/ext/bg/settings.html
@@ -414,6 +414,16 @@
<label><input type="checkbox" id="deep-dom-scan" data-setting="scanning.deepDomScan"> Deep content scan</label>
</div>
+ <div class="checkbox options-advanced">
+ <strong>Prevent middle mouse button actions on:</strong>
+ <div style="margin-left: 1em;">
+ <label><input type="checkbox" id="deep-dom-scan" data-setting="scanning.preventMiddleMouse.onWebPages"> Webpages</label><br>
+ <label><input type="checkbox" id="deep-dom-scan" data-setting="scanning.preventMiddleMouse.onPopupPages"> Popups</label><br>
+ <label><input type="checkbox" id="deep-dom-scan" data-setting="scanning.preventMiddleMouse.onSearchPages"> Search page</label><br>
+ <label><input type="checkbox" id="deep-dom-scan" data-setting="scanning.preventMiddleMouse.onSearchQuery"> Search query</label><br>
+ </div>
+ </div>
+
<div class="form-group options-advanced">
<div class="row">
<div class="col-xs-6">
diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js
index 13b0d80c..95c9eb1b 100644
--- a/ext/fg/js/frontend.js
+++ b/ext/fg/js/frontend.js
@@ -320,6 +320,7 @@ class Frontend {
await this._updatePopup();
+ const preventMiddleMouse = this._getPreventMiddleMouseValueForPageType(scanningOptions.preventMiddleMouse);
this._textScanner.setOptions({
inputs: scanningOptions.inputs,
deepContentScan: scanningOptions.deepDomScan,
@@ -329,7 +330,8 @@ class Frontend {
pointerEventsEnabled: scanningOptions.pointerEventsEnabled,
scanLength: scanningOptions.length,
sentenceExtent: options.anki.sentenceExt,
- layoutAwareScan: scanningOptions.layoutAwareScan
+ layoutAwareScan: scanningOptions.layoutAwareScan,
+ preventMiddleMouse
});
this._updateTextScannerEnabled();
@@ -616,4 +618,13 @@ class Frontend {
await this._updatePendingOptions();
return await this.getOptionsContext();
}
+
+ _getPreventMiddleMouseValueForPageType(preventMiddleMouseOptions) {
+ switch (this._pageType) {
+ case 'web': return preventMiddleMouseOptions.onWebPages;
+ case 'popup': return preventMiddleMouseOptions.onPopupPages;
+ case 'search': return preventMiddleMouseOptions.onSearchPages;
+ default: return false;
+ }
+ }
}
diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js
index e5f12a1a..c7ad8894 100644
--- a/ext/mixed/js/display.js
+++ b/ext/mixed/js/display.js
@@ -251,7 +251,8 @@ class Display extends EventDispatcher {
pointerEventsEnabled: scanning.pointerEventsEnabled,
scanLength: scanning.length,
sentenceExtent: options.anki.sentenceExt,
- layoutAwareScan: scanning.layoutAwareScan
+ layoutAwareScan: scanning.layoutAwareScan,
+ preventMiddleMouse: scanning.preventMiddleMouse.onSearchQuery
}
});
}
diff --git a/ext/mixed/js/text-scanner.js b/ext/mixed/js/text-scanner.js
index aacc683a..b8d4faf5 100644
--- a/ext/mixed/js/text-scanner.js
+++ b/ext/mixed/js/text-scanner.js
@@ -49,6 +49,7 @@ class TextScanner extends EventDispatcher {
this._scanLength = 1;
this._sentenceExtent = 1;
this._layoutAwareScan = false;
+ this._preventMiddleMouse = false;
this._inputs = [];
this._enabled = false;
@@ -113,7 +114,7 @@ class TextScanner extends EventDispatcher {
}
}
- setOptions({inputs, deepContentScan, selectText, delay, touchInputEnabled, pointerEventsEnabled, scanLength, sentenceExtent, layoutAwareScan}) {
+ setOptions({inputs, deepContentScan, selectText, delay, touchInputEnabled, pointerEventsEnabled, scanLength, sentenceExtent, layoutAwareScan, preventMiddleMouse}) {
if (Array.isArray(inputs)) {
this._inputs = inputs.map(({
include,
@@ -151,6 +152,9 @@ class TextScanner extends EventDispatcher {
if (typeof layoutAwareScan === 'boolean') {
this._layoutAwareScan = layoutAwareScan;
}
+ if (typeof preventMiddleMouse === 'boolean') {
+ this._preventMiddleMouse = preventMiddleMouse;
+ }
}
getTextSourceContent(textSource, length, layoutAwareScan) {
@@ -282,9 +286,18 @@ class TextScanner extends EventDispatcher {
return false;
}
- if (e.button === 0) { // Primary
- this._scanTimerClear();
- this.clearSelection(false);
+ switch (e.button) {
+ case 0: // Primary
+ this._scanTimerClear();
+ this.clearSelection(false);
+ break;
+ case 1: // Middle
+ if (this._preventMiddleMouse) {
+ e.preventDefault();
+ e.stopPropagation();
+ return false;
+ }
+ break;
}
}