diff options
Diffstat (limited to 'ext/js')
-rw-r--r-- | ext/js/app/frontend.js | 1 | ||||
-rw-r--r-- | ext/js/data/options-util.js | 12 | ||||
-rw-r--r-- | ext/js/display/display.js | 2 | ||||
-rw-r--r-- | ext/js/language/text-scanner.js | 13 |
4 files changed, 27 insertions, 1 deletions
diff --git a/ext/js/app/frontend.js b/ext/js/app/frontend.js index 8ac27979..c3022908 100644 --- a/ext/js/app/frontend.js +++ b/ext/js/app/frontend.js @@ -513,6 +513,7 @@ export class Frontend { matchTypePrefix: scanningOptions.matchTypePrefix, preventMiddleMouse, sentenceParsingOptions, + scanAltText: scanningOptions.scanAltText, }); this._updateTextScannerEnabled(); diff --git a/ext/js/data/options-util.js b/ext/js/data/options-util.js index 8af299d8..850ac81d 100644 --- a/ext/js/data/options-util.js +++ b/ext/js/data/options-util.js @@ -349,6 +349,7 @@ export class OptionsUtil { enableOnSearchPage: true, enableSearchTags: false, layoutAwareScan: false, + scanAltText: true, }, translation: { @@ -549,6 +550,7 @@ export class OptionsUtil { this._updateVersion39, this._updateVersion40, this._updateVersion41, + this._updateVersion42, ]; /* eslint-enable @typescript-eslint/unbound-method */ if (typeof targetVersion === 'number' && targetVersion < result.length) { @@ -1349,6 +1351,16 @@ export class OptionsUtil { } /** + * - Added scanning.scanAltText + * @type {import('options-util').UpdateFunction} + */ + async _updateVersion42(options) { + for (const profile of options.profiles) { + profile.options.scanning.scanAltText = true; + } + } + + /** * @param {string} url * @returns {Promise<chrome.tabs.Tab>} */ diff --git a/ext/js/display/display.js b/ext/js/display/display.js index 3d18e416..01406382 100644 --- a/ext/js/display/display.js +++ b/ext/js/display/display.js @@ -461,6 +461,7 @@ export class Display extends EventDispatcher { preventMiddleMouse: scanningOptions.preventMiddleMouse.onSearchQuery, matchTypePrefix: false, sentenceParsingOptions, + scanAltText: scanningOptions.scanAltText, }, }); @@ -1984,6 +1985,7 @@ export class Display extends EventDispatcher { layoutAwareScan: scanningOptions.layoutAwareScan, preventMiddleMouse: false, sentenceParsingOptions, + scanAltText: scanningOptions.scanAltText, }); this._contentTextScanner.setEnabled(true); diff --git a/ext/js/language/text-scanner.js b/ext/js/language/text-scanner.js index 249a2eda..759adf20 100644 --- a/ext/js/language/text-scanner.js +++ b/ext/js/language/text-scanner.js @@ -124,6 +124,8 @@ export class TextScanner extends EventDispatcher { this._sentenceBackwardQuoteMap = new Map(); /** @type {import('text-scanner').InputConfig[]} */ this._inputs = []; + /** @type {boolean} */ + this._scanAltText = true; /** @type {boolean} */ this._enabled = false; @@ -255,6 +257,7 @@ export class TextScanner extends EventDispatcher { preventMiddleMouse, sentenceParsingOptions, matchTypePrefix, + scanAltText, }) { if (Array.isArray(inputs)) { this._inputs = inputs.map((input) => this._convertInput(input)); @@ -289,6 +292,9 @@ export class TextScanner extends EventDispatcher { if (typeof matchTypePrefix === 'boolean') { this._matchTypePrefix = matchTypePrefix; } + if (typeof scanAltText === 'boolean') { + this._scanAltText = scanAltText; + } if (typeof sentenceParsingOptions === 'object' && sentenceParsingOptions !== null) { const {scanExtent, terminationCharacterMode, terminationCharacters} = sentenceParsingOptions; if (typeof scanExtent === 'number') { @@ -443,6 +449,11 @@ export class TextScanner extends EventDispatcher { */ async _search(textSource, searchTerms, searchKanji, inputInfo, showEmpty = false) { try { + const isAltText = textSource instanceof TextSourceElement; + if (isAltText && !this._scanAltText) { + return; + } + const inputInfoDetail = inputInfo.detail; const selectionRestoreInfo = ( (typeof inputInfoDetail === 'object' && inputInfoDetail !== null && inputInfoDetail.restoreSelection) ? @@ -468,7 +479,7 @@ export class TextScanner extends EventDispatcher { const result = await this._findDictionaryEntries(textSource, searchTerms, searchKanji, optionsContext); if (result !== null) { ({dictionaryEntries, sentence, type} = result); - } else if (showEmpty || (textSource !== null && textSource instanceof TextSourceElement && await this._isTextLookupWorthy(textSource.fullContent))) { + } else if (showEmpty || (textSource !== null && isAltText && await this._isTextLookupWorthy(textSource.fullContent))) { // Shows a "No results found" message dictionaryEntries = []; sentence = {text: '', offset: 0}; |