summaryrefslogtreecommitdiff
path: root/ext/js/background
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2024-02-25 11:20:44 -0500
committerGitHub <noreply@github.com>2024-02-25 16:20:44 +0000
commit2e9ea19207a7410f929bb908759d48cb2340f29c (patch)
treea6bde1297d693bb8d50e4c93a963aa3179e5a2ce /ext/js/background
parent73169f06dff767020718a5715eba97d3575ba7e1 (diff)
"isJapanese" check move (#730)
* Move isStringPartiallyJapanese out of ClipboardMonitor * Create isStringPartiallyJapanese function * Add textMayBeTranslatable * Rename API function * Rename internal function * Add helper * Update translatable check * Pass language to TextScanner * Pass language explicitly * Use textMayBeTranslatable * No redundant translatable check * Update eslint * Remove double newline * Collapse * Rename
Diffstat (limited to 'ext/js/background')
-rw-r--r--ext/js/background/backend.js18
1 files changed, 11 insertions, 7 deletions
diff --git a/ext/js/background/backend.js b/ext/js/background/backend.js
index 79023ac9..6340d021 100644
--- a/ext/js/background/backend.js
+++ b/ext/js/background/backend.js
@@ -34,8 +34,8 @@ import {arrayBufferToBase64} from '../data/sandbox/array-buffer-util.js';
import {DictionaryDatabase} from '../dictionary/dictionary-database.js';
import {Environment} from '../extension/environment.js';
import {ObjectPropertyAccessor} from '../general/object-property-accessor.js';
-import {distributeFuriganaInflected, isCodePointJapanese, isStringPartiallyJapanese, convertKatakanaToHiragana as jpConvertKatakanaToHiragana} from '../language/ja/japanese.js';
-import {getLanguageSummaries} from '../language/languages.js';
+import {distributeFuriganaInflected, isCodePointJapanese, convertKatakanaToHiragana as jpConvertKatakanaToHiragana} from '../language/ja/japanese.js';
+import {getLanguageSummaries, isTextLookupWorthy} from '../language/languages.js';
import {Translator} from '../language/translator.js';
import {AudioDownloader} from '../media/audio-downloader.js';
import {getFileExtensionFromAudioMediaType, getFileExtensionFromImageMediaType} from '../media/media-util.js';
@@ -175,7 +175,7 @@ export class Backend {
['isTabSearchPopup', this._onApiIsTabSearchPopup.bind(this)],
['triggerDatabaseUpdated', this._onApiTriggerDatabaseUpdated.bind(this)],
['testMecab', this._onApiTestMecab.bind(this)],
- ['textHasJapaneseCharacters', this._onApiTextHasJapaneseCharacters.bind(this)],
+ ['isTextLookupWorthy', this._onApiIsTextLookupWorthy.bind(this)],
['getTermFrequencies', this._onApiGetTermFrequencies.bind(this)],
['findAnkiNotes', this._onApiFindAnkiNotes.bind(this)],
['openCrossFramePort', this._onApiOpenCrossFramePort.bind(this)],
@@ -310,7 +310,11 @@ export class Backend {
* @param {import('clipboard-monitor').EventArgument<'change'>} details
*/
async _onClipboardTextChange({text}) {
- const {clipboard: {maximumSearchLength}} = this._getProfileOptions({current: true}, false);
+ const {
+ general: {language},
+ clipboard: {maximumSearchLength}
+ } = this._getProfileOptions({current: true}, false);
+ if (!isTextLookupWorthy(text, language)) { return; }
if (text.length > maximumSearchLength) {
text = text.substring(0, maximumSearchLength);
}
@@ -839,9 +843,9 @@ export class Backend {
return true;
}
- /** @type {import('api').ApiHandler<'textHasJapaneseCharacters'>} */
- _onApiTextHasJapaneseCharacters({text}) {
- return isStringPartiallyJapanese(text);
+ /** @type {import('api').ApiHandler<'isTextLookupWorthy'>} */
+ _onApiIsTextLookupWorthy({text, language}) {
+ return isTextLookupWorthy(text, language);
}
/** @type {import('api').ApiHandler<'getTermFrequencies'>} */