diff options
| author | marv <rotrobmin@gmail.com> | 2024-07-03 03:00:07 -0700 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-03 10:00:07 +0000 | 
| commit | 066ca66fc4033da39d0aecd73b0f5c200cb3f3ed (patch) | |
| tree | 64d00048c4dd0b422141a72b9c6b1310f59fc496 /ext/js/language | |
| parent | c1f0343feeb8b8a8feaa942022150f971e118659 (diff) | |
Add Option for Scanning Alt Text (#1169)
* Add Option for Scanning Alt Text
* Don't scan alt text if option disabled
* Add scanAltText to Options Schema
* Add `scanning.scanAltText` Update Function
* Bump Options Test Version
* Remove Param Annotation
Diffstat (limited to 'ext/js/language')
| -rw-r--r-- | ext/js/language/text-scanner.js | 13 | 
1 files changed, 12 insertions, 1 deletions
| 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}; |