From 2e9ea19207a7410f929bb908759d48cb2340f29c Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sun, 25 Feb 2024 11:20:44 -0500 Subject: "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 --- ext/js/background/backend.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'ext/js/background') 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'>} */ -- cgit v1.2.3