summaryrefslogtreecommitdiff
path: root/ext/js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/js')
-rw-r--r--ext/js/background/backend.js7
-rw-r--r--ext/js/comm/api.js4
-rw-r--r--ext/js/display/display.js4
-rw-r--r--ext/js/language/text-scanner.js15
4 files changed, 27 insertions, 3 deletions
diff --git a/ext/js/background/backend.js b/ext/js/background/backend.js
index 484473c7..3d8c4c4a 100644
--- a/ext/js/background/backend.js
+++ b/ext/js/background/backend.js
@@ -127,7 +127,8 @@ class Backend {
['getOrCreateSearchPopup', {async: true, contentScript: true, handler: this._onApiGetOrCreateSearchPopup.bind(this)}],
['isTabSearchPopup', {async: true, contentScript: true, handler: this._onApiIsTabSearchPopup.bind(this)}],
['triggerDatabaseUpdated', {async: false, contentScript: true, handler: this._onApiTriggerDatabaseUpdated.bind(this)}],
- ['testMecab', {async: true, contentScript: true, handler: this._onApiTestMecab.bind(this)}]
+ ['testMecab', {async: true, contentScript: true, handler: this._onApiTestMecab.bind(this)}],
+ ['textHasJapaneseCharacters', {async: false, contentScript: true, handler: this._onApiTextHasJapaneseCharacters.bind(this)}]
]);
this._messageHandlersWithProgress = new Map([
]);
@@ -727,6 +728,10 @@ class Backend {
return true;
}
+ _onApiTextHasJapaneseCharacters({text}) {
+ return this._japaneseUtil.isStringPartiallyJapanese(text);
+ }
+
// Command handlers
async _onCommandOpenSearchPage(params) {
diff --git a/ext/js/comm/api.js b/ext/js/comm/api.js
index 472e464b..a2eb004c 100644
--- a/ext/js/comm/api.js
+++ b/ext/js/comm/api.js
@@ -168,6 +168,10 @@ class API {
return this._invoke('testMecab', {});
}
+ textHasJapaneseCharacters(text) {
+ return this._invoke('textHasJapaneseCharacters', {text});
+ }
+
// Utilities
_createActionPort(timeout=5000) {
diff --git a/ext/js/display/display.js b/ext/js/display/display.js
index ad9a25b4..8b521d21 100644
--- a/ext/js/display/display.js
+++ b/ext/js/display/display.js
@@ -543,7 +543,7 @@ class Display extends EventDispatcher {
case 'kanji':
{
let query = urlSearchParams.get('query');
- if (!query) { break; }
+ if (query === null) { break; }
this._query = query;
clear = false;
@@ -882,7 +882,7 @@ class Display extends EventDispatcher {
let {definitions} = content;
if (!Array.isArray(definitions)) {
- definitions = lookup ? await this._findDefinitions(isTerms, query, wildcardsEnabled, optionsContext) : [];
+ definitions = lookup && query.length > 0 ? await this._findDefinitions(isTerms, query, wildcardsEnabled, optionsContext) : [];
if (this._setContentToken !== token) { return; }
content.definitions = definitions;
changeHistory = true;
diff --git a/ext/js/language/text-scanner.js b/ext/js/language/text-scanner.js
index 073b1a6c..4994faea 100644
--- a/ext/js/language/text-scanner.js
+++ b/ext/js/language/text-scanner.js
@@ -17,6 +17,7 @@
/* global
* DocumentUtil
+ * TextSourceElement
*/
class TextScanner extends EventDispatcher {
@@ -321,6 +322,12 @@ class TextScanner extends EventDispatcher {
({definitions, sentence, type} = result);
this._inputInfoCurrent = inputInfo;
this.setCurrentTextSource(textSource);
+ } else if (textSource instanceof TextSourceElement && await this._hasJapanese(textSource.fullContent)) {
+ definitions = [];
+ sentence = {sentence: '', offset: 0};
+ type = 'terms';
+ this._inputInfoCurrent = inputInfo;
+ this.setCurrentTextSource(textSource);
}
} catch (e) {
error = e;
@@ -978,4 +985,12 @@ class TextScanner extends EventDispatcher {
}
}
}
+
+ async _hasJapanese(text) {
+ try {
+ return await yomichan.api.textHasJapaneseCharacters(text);
+ } catch (e) {
+ return false;
+ }
+ }
}