summaryrefslogtreecommitdiff
path: root/ext/bg
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-01-25 22:05:06 -0500
committerGitHub <noreply@github.com>2021-01-25 22:05:06 -0500
commit981f73b5623249b4c4cead0261eab0e70f620d90 (patch)
treec03dcd0545462da99d168f30dfe6691b41519d73 /ext/bg
parentea1d40f94b2e3d43cc73805018cc5d2ba24a6822 (diff)
Clipboard lookup skip option (#1314)
* Add autoSearchClipboardContent option * Hide header if there is any search text * Add setting for autoSearchClipboardContent * Add support for autoSearchClipboardContent
Diffstat (limited to 'ext/bg')
-rw-r--r--ext/bg/data/options-schema.json7
-rw-r--r--ext/bg/js/options.js3
-rw-r--r--ext/bg/js/search.js13
-rw-r--r--ext/bg/settings2.html23
4 files changed, 39 insertions, 7 deletions
diff --git a/ext/bg/data/options-schema.json b/ext/bg/data/options-schema.json
index dfc553ed..b03f0234 100644
--- a/ext/bg/data/options-schema.json
+++ b/ext/bg/data/options-schema.json
@@ -115,7 +115,8 @@
"maximumClipboardSearchLength",
"popupCurrentIndicatorMode",
"popupActionBarVisibility",
- "popupActionBarLocation"
+ "popupActionBarLocation",
+ "autoSearchClipboardContent"
],
"properties": {
"enable": {
@@ -286,6 +287,10 @@
"type": "string",
"enum": ["left", "right", "top", "bottom"],
"default": "top"
+ },
+ "autoSearchClipboardContent": {
+ "type": "boolean",
+ "default": true
}
}
},
diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js
index 10919ae3..1417c975 100644
--- a/ext/bg/js/options.js
+++ b/ext/bg/js/options.js
@@ -668,6 +668,8 @@ class OptionsUtil {
// Added popupWindow.
// Updated handlebars templates to include "stroke-count" definition.
// Updated global.useSettingsV2 to be true (opt-out).
+ // Added audio.customSourceType.
+ // Added general.autoSearchClipboardContent.
await this._addFieldTemplatesToOptions(options, '/bg/data/anki-field-templates-upgrade-v8.handlebars');
options.global.useSettingsV2 = true;
for (const profile of options.profiles) {
@@ -727,6 +729,7 @@ class OptionsUtil {
windowState: 'normal'
};
profile.options.audio.customSourceType = 'audio';
+ profile.options.general.autoSearchClipboardContent = true;
}
return options;
}
diff --git a/ext/bg/js/search.js b/ext/bg/js/search.js
index 69edfabd..0fcbcd13 100644
--- a/ext/bg/js/search.js
+++ b/ext/bg/js/search.js
@@ -130,7 +130,7 @@ class DisplaySearch extends Display {
case 'terms':
case 'kanji':
animate = !!content.animate;
- valid = content.definitions.length > 0;
+ valid = (typeof source === 'string' && source.length > 0);
this.blurElement(this._queryInput);
break;
case 'clear':
@@ -159,12 +159,12 @@ class DisplaySearch extends Display {
e.preventDefault();
e.stopImmediatePropagation();
this.blurElement(e.currentTarget);
- this._search(true, true);
+ this._search(true, true, true);
}
_onSearch(e) {
e.preventDefault();
- this._search(true, true);
+ this._search(true, true, true);
}
_onCopy() {
@@ -173,12 +173,12 @@ class DisplaySearch extends Display {
}
_onExternalSearchUpdate({text, animate=true}) {
- const {general: {maximumClipboardSearchLength}} = this.getOptions();
+ const {general: {maximumClipboardSearchLength, autoSearchClipboardContent}} = this.getOptions();
if (text.length > maximumClipboardSearchLength) {
text = text.substring(0, maximumClipboardSearchLength);
}
this._queryInput.value = text;
- this._search(animate, false);
+ this._search(animate, false, autoSearchClipboardContent);
}
_onWanakanaEnableChange(e) {
@@ -323,7 +323,7 @@ class DisplaySearch extends Display {
});
}
- _search(animate, history) {
+ _search(animate, history, lookup) {
const query = this._queryInput.value;
const depth = this.depth;
const url = window.location.href;
@@ -346,6 +346,7 @@ class DisplaySearch extends Display {
animate
}
};
+ if (!lookup) { details.params.lookup = 'false'; }
this.setContent(details);
}
diff --git a/ext/bg/settings2.html b/ext/bg/settings2.html
index 98274277..ba37c860 100644
--- a/ext/bg/settings2.html
+++ b/ext/bg/settings2.html
@@ -993,6 +993,29 @@
</div></div>
<div class="settings-item"><div class="settings-item-inner settings-item-inner-wrappable">
<div class="settings-item-left">
+ <div class="settings-item-label">Clipboard text search mode</div>
+ <div class="settings-item-description">Change how the search page reacts to new text in the clipboard.</div>
+ </div>
+ <div class="settings-item-right">
+ <select data-setting="general.autoSearchClipboardContent"
+ data-transform='[
+ {
+ "step": "pre",
+ "type": "toBoolean"
+ },
+ {
+ "step": "post",
+ "type": "toString"
+ }
+ ]'
+ >
+ <option value="true">Search for definitions</option>
+ <option value="false">Update search query only</option>
+ </select>
+ </div>
+ </div></div>
+ <div class="settings-item"><div class="settings-item-inner settings-item-inner-wrappable">
+ <div class="settings-item-left">
<div class="settings-item-label">Size</div>
<div class="settings-item-description">Control the size of the window, in pixels.</div>
</div>