Skip to content

Commit

Permalink
Add Option for Scanning Alt Text
Browse files Browse the repository at this point in the history
  • Loading branch information
MarvNC committed Jul 2, 2024
1 parent c1f0343 commit 0f3447a
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions ext/js/app/frontend.js
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ export class Frontend {
matchTypePrefix: scanningOptions.matchTypePrefix,
preventMiddleMouse,
sentenceParsingOptions,
scanAltText: scanningOptions.scanAltText,
});
this._updateTextScannerEnabled();

Expand Down
1 change: 1 addition & 0 deletions ext/js/data/options-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ export class OptionsUtil {
enableOnSearchPage: true,
enableSearchTags: false,
layoutAwareScan: false,
scanAltText: true,
},

translation: {
Expand Down
2 changes: 2 additions & 0 deletions ext/js/display/display.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ export class Display extends EventDispatcher {
preventMiddleMouse: scanningOptions.preventMiddleMouse.onSearchQuery,
matchTypePrefix: false,
sentenceParsingOptions,
scanAltText: scanningOptions.scanAltText,
},
});

Expand Down Expand Up @@ -1984,6 +1985,7 @@ export class Display extends EventDispatcher {
layoutAwareScan: scanningOptions.layoutAwareScan,
preventMiddleMouse: false,
sentenceParsingOptions,
scanAltText: scanningOptions.scanAltText,
});

this._contentTextScanner.setEnabled(true);
Expand Down
6 changes: 6 additions & 0 deletions ext/js/language/text-scanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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') {
Expand Down
9 changes: 9 additions & 0 deletions ext/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,15 @@ <h1>Yomitan Settings</h1>
<label class="toggle"><input type="checkbox" data-setting="scanning.deepDomScan"><span class="toggle-body"><span class="toggle-track"></span><span class="toggle-knob"></span></span></label>
</div>
</div></div>
<div class="settings-item"><div class="settings-item-inner">
<div class="settings-item-left">
<div class="settings-item-label">Scan alt text</div>
<div class="settings-item-description">Scan text that is used for image and button descriptions.</div>
</div>
<div class="settings-item-right">
<label class="toggle"><input type="checkbox" data-setting="scanning.scanAltText"><span class="toggle-body"><span class="toggle-track"></span><span class="toggle-knob"></span></span></label>
</div>
</div></div>
<div class="settings-item advanced-only">
<div class="settings-item-inner">
<div class="settings-item-left">
Expand Down
2 changes: 2 additions & 0 deletions test/options-util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ function createProfileOptionsTestData1() {
enableOnSearchPage: true,
enableSearchTags: false,
layoutAwareScan: false,
scanAltText: true,
},
translation: {
convertHalfWidthCharacters: 'false',
Expand Down Expand Up @@ -325,6 +326,7 @@ function createProfileOptionsUpdatedTestData1() {
hidePopupOnCursorExit: false,
hidePopupOnCursorExitDelay: 0,
normalizeCssZoom: true,
scanAltText: true,
preventMiddleMouse: {
onWebPages: false,
onPopupPages: false,
Expand Down
1 change: 1 addition & 0 deletions types/ext/settings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ export type ScanningOptions = {
hidePopupOnCursorExit: boolean;
hidePopupOnCursorExitDelay: number;
normalizeCssZoom: boolean;
scanAltText: boolean;
};

export type ScanningInput = {
Expand Down
1 change: 1 addition & 0 deletions types/ext/text-scanner.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export type Options = {
preventMiddleMouse?: boolean;
matchTypePrefix?: boolean;
sentenceParsingOptions?: SentenceParsingOptions;
scanAltText?: boolean;
};

export type InputOptionsOuter = {
Expand Down

0 comments on commit 0f3447a

Please sign in to comment.