aboutsummaryrefslogtreecommitdiff
path: root/ext/bg
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2017-04-23 11:10:35 -0700
committerAlex Yatskov <alex@foosoft.net>2017-04-23 11:10:35 -0700
commita209228c311a13328ecdda4056a9302885639195 (patch)
treef412a23f65cbd3f325937d8cd94e8ccec5b7ef28 /ext/bg
parent3523b85be0be618b00cd9b6992aaf255de12ebfb (diff)
parent3319d0d3cdaf98a8fd57b7c51e745f60960f607e (diff)
Merge branch 'master' into firefox-amo
Diffstat (limited to 'ext/bg')
-rw-r--r--ext/bg/js/options.js2
-rw-r--r--ext/bg/js/translator.js13
-rw-r--r--ext/bg/js/util.js22
-rw-r--r--ext/bg/js/yomichan.js2
-rw-r--r--ext/bg/options.html8
5 files changed, 35 insertions, 12 deletions
diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js
index 49544840..1ea6ed68 100644
--- a/ext/bg/js/options.js
+++ b/ext/bg/js/options.js
@@ -40,6 +40,7 @@ function formRead() {
optionsNew.scanning.middleMouse = $('#middle-mouse-button-scan').prop('checked');
optionsNew.scanning.selectText = $('#select-matched-text').prop('checked');
optionsNew.scanning.imposter = $('#search-form-text-fields').prop('checked');
+ optionsNew.scanning.alphanumeric = $('#search-alphanumeric').prop('checked');
optionsNew.scanning.delay = parseInt($('#scan-delay').val(), 10);
optionsNew.scanning.length = parseInt($('#scan-length').val(), 10);
@@ -127,6 +128,7 @@ $(document).ready(() => {
$('#middle-mouse-button-scan').prop('checked', options.scanning.middleMouse);
$('#select-matched-text').prop('checked', options.scanning.selectText);
$('#search-form-text-fields').prop('checked', options.scanning.imposter);
+ $('#search-alphanumeric').prop('checked', options.scanning.alphanumeric);
$('#scan-delay').val(options.scanning.delay);
$('#scan-length').val(options.scanning.length);
diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js
index 67430aef..b3b90641 100644
--- a/ext/bg/js/translator.js
+++ b/ext/bg/js/translator.js
@@ -41,10 +41,17 @@ class Translator {
});
}
- findTerms(text, dictionaries, softKatakana) {
+ findTerms(text, dictionaries, softKatakana, alphanumeric) {
const titles = Object.keys(dictionaries);
const cache = {};
+ if (!alphanumeric && text.length > 0) {
+ const c = text[0];
+ if (!jpIsKana(c) && !jpIsKanji(c)) {
+ return Promise.resolve({length: 0, definitions: []});
+ }
+ }
+
return this.findTermsDeinflected(text, titles, cache).then(deinfLiteral => {
const textHiragana = wanakana._katakanaToHiragana(text);
if (text !== textHiragana && softKatakana) {
@@ -84,8 +91,8 @@ class Translator {
});
}
- findTermsGrouped(text, dictionaries, softKatakana) {
- return this.findTerms(text, dictionaries, softKatakana).then(({length, definitions}) => {
+ findTermsGrouped(text, dictionaries, softKatakana, alphanumeric) {
+ return this.findTerms(text, dictionaries, softKatakana, alphanumeric).then(({length, definitions}) => {
return {length, definitions: dictTermsGroup(definitions, dictionaries)};
});
}
diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js
index 64143ffe..09337c63 100644
--- a/ext/bg/js/util.js
+++ b/ext/bg/js/util.js
@@ -31,6 +31,20 @@ function promiseCallback(promise, callback) {
/*
+ * Japanese
+ */
+
+function jpIsKanji(c) {
+ const code = c.charCodeAt(0);
+ return code >= 0x4e00 && code < 0x9fb0 || code >= 0x3400 && code < 0x4dc0;
+}
+
+function jpIsKana(c) {
+ return wanakana.isKana(c);
+}
+
+
+/*
* Commands
*/
@@ -98,6 +112,7 @@ function optionsSetDefaults(options) {
middleMouse: true,
selectText: true,
imposter: true,
+ alphanumeric: true,
delay: 15,
length: 10
},
@@ -489,14 +504,9 @@ function jsonLoadDb(indexUrl, indexLoaded, termsLoaded, kanjiLoaded) {
*/
function handlebarsKanjiLinks(options) {
- const isKanji = c => {
- const code = c.charCodeAt(0);
- return code >= 0x4e00 && code < 0x9fb0 || code >= 0x3400 && code < 0x4dc0;
- };
-
let result = '';
for (const c of options.fn(this)) {
- if (isKanji(c)) {
+ if (jpIsKanji(c)) {
result += `<a href="#" class="kanji-link">${c}</a>`;
} else {
result += c;
diff --git a/ext/bg/js/yomichan.js b/ext/bg/js/yomichan.js
index 51e05c80..172bb1d3 100644
--- a/ext/bg/js/yomichan.js
+++ b/ext/bg/js/yomichan.js
@@ -107,7 +107,7 @@ window.yomichan = new class {
this.translator.findTermsGrouped.bind(this.translator) :
this.translator.findTerms.bind(this.translator);
- return searcher(text, dictEnabledSet(this.options), this.options.general.softKatakana).then(({definitions, length}) => {
+ return searcher(text, dictEnabledSet(this.options), this.options.general.softKatakana, this.options.scanning.alphanumeric).then(({definitions, length}) => {
return {length, definitions: definitions.slice(0, this.options.general.maxResults)};
});
}
diff --git a/ext/bg/options.html b/ext/bg/options.html
index e3168ca1..c3799b61 100644
--- a/ext/bg/options.html
+++ b/ext/bg/options.html
@@ -93,6 +93,10 @@
<label><input type="checkbox" id="search-form-text-fields"> Search form text fields</label>
</div>
+ <div class="checkbox">
+ <label><input type="checkbox" id="search-alphanumeric"> Search alphanumeric text</label>
+ </div>
+
<div class="form-group options-advanced">
<label for="scan-delay">Scan delay</label>
<input type="number" min="1" id="scan-delay" class="form-control">
@@ -200,9 +204,9 @@
<div id="anki-format">
<p class="help-block">
Specify the information you would like included in your flashcards in the field editor below.
- Please be aware that Anki requires the first field in the model to be unique. It is highly recommended
+ As Anki requires the first field in the model to be unique, it is recommended
that you set it to <code>{expression}</code> for term flashcards and <code>{character}</code> for
- Kanji flashcards.
+ Kanji flashcards. You can use multiple markers per field by typing them in directly.
</p>
<ul class="nav nav-tabs">