Skip to content

Commit

Permalink
add option to scan hyperlink
Browse files Browse the repository at this point in the history
  • Loading branch information
khaitruong922 committed Sep 17, 2024
1 parent 547a628 commit 82d26f1
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 2 deletions.
5 changes: 5 additions & 0 deletions ext/data/schemas/options-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@
"length",
"deepDomScan",
"scanAltText",
"scanHyperlinkText",
"popupNestingMaxDepth",
"enablePopupSearch",
"enableOnPopupExpressions",
Expand Down Expand Up @@ -720,6 +721,10 @@
"type": "boolean",
"default": true
},
"scanHyperlinkText": {
"type": "boolean",
"default": true
},
"popupNestingMaxDepth": {
"type": "integer",
"minimum": 0,
Expand Down
6 changes: 5 additions & 1 deletion ext/js/app/frontend.js
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,11 @@ export class Frontend {
});
this._updateTextScannerEnabled();

if (this._pageType !== 'web') {
if (this._pageType === 'web') {
if (!scanningOptions.scanHyperlinkText) {
this._textScanner.excludeSelector = 'a,a *';
}
} else {
const excludeSelectors = ['.scan-disable', '.scan-disable *'];
if (!scanningOptions.enableOnPopupExpressions) {
excludeSelectors.push('.source-text', '.source-text *');
Expand Down
12 changes: 12 additions & 0 deletions ext/js/data/options-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ export class OptionsUtil {
this._updateVersion49,
this._updateVersion50,
this._updateVersion51,
this._updateVersion52,
];
/* eslint-enable @typescript-eslint/unbound-method */
if (typeof targetVersion === 'number' && targetVersion < result.length) {
Expand Down Expand Up @@ -1487,6 +1488,16 @@ export class OptionsUtil {
}
}

/**
* - Added scanning.scanAltText
* @type {import('options-util').UpdateFunction}
*/
async _updateVersion52(options) {
for (const profile of options.profiles) {
profile.options.scanning.scanHyperlinkText = true;
}
}

/**
* @param {string} url
* @returns {Promise<chrome.tabs.Tab>}
Expand All @@ -1503,6 +1514,7 @@ export class OptionsUtil {
});
});
}

Check failure on line 1516 in ext/js/data/options-util.js

View workflow job for this annotation

GitHub Actions / Static Analysis

Block must not be padded by blank lines

}

/* eslint-enable @typescript-eslint/no-unsafe-assignment */
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 @@ -465,6 +465,7 @@ export class Display extends EventDispatcher {
matchTypePrefix: false,
sentenceParsingOptions,
scanAltText: scanningOptions.scanAltText,
scanHyperlinkText: scanningOptions.scanHyperlinkText,
scanWithoutMousemove: scanningOptions.scanWithoutMousemove,
scanResolution: scanningOptions.scanResolution,
},
Expand Down Expand Up @@ -2034,6 +2035,7 @@ export class Display extends EventDispatcher {
preventMiddleMouse: false,
sentenceParsingOptions,
scanAltText: scanningOptions.scanAltText,
scanHyperlinkText: scanningOptions.scanHyperlinkText,
});

this._contentTextScanner.setEnabled(true);
Expand Down
8 changes: 8 additions & 0 deletions ext/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,14 @@ <h1>Yomitan Settings</h1>
<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"><div class="settings-item-inner">
<div class="settings-item-left">
<div class="settings-item-label">Scan hyperlink text</div>
</div>
<div class="settings-item-right">
<label class="toggle"><input type="checkbox" data-setting="scanning.scanHyperlinkText"><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
3 changes: 2 additions & 1 deletion test/options-util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ function createProfileOptionsUpdatedTestData1() {
hidePopupOnCursorExitDelay: 0,
normalizeCssZoom: true,
scanAltText: true,
scanHyperlinkText: true,
preventMiddleMouse: {
onWebPages: false,
onPopupPages: false,
Expand Down Expand Up @@ -645,7 +646,7 @@ function createOptionsUpdatedTestData1() {
},
],
profileCurrent: 0,
version: 51,
version: 52,
global: {
database: {
prefixWildcardsSupported: false,
Expand Down
5 changes: 5 additions & 0 deletions types/ext/settings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import type * as TextScanner from './text-scanner';
import type * as Input from './input';

export type OptionsContextFlag = 'clipboard';
Expand All @@ -27,6 +28,7 @@ export type OptionsContext1 = {
flags?: OptionsContextFlag[];
modifiers?: Input.Modifier[];
modifierKeys?: Input.ModifierKey[];
pointerType?: TextScanner.PointerType;
};

export type OptionsContext2 = {
Expand All @@ -37,6 +39,7 @@ export type OptionsContext2 = {
flags?: OptionsContextFlag[];
modifiers?: Input.Modifier[];
modifierKeys?: Input.ModifierKey[];
pointerType?: TextScanner.PointerType;
};

export type OptionsContext3 = {
Expand All @@ -47,6 +50,7 @@ export type OptionsContext3 = {
flags?: OptionsContextFlag[];
modifiers?: Input.Modifier[];
modifierKeys?: Input.ModifierKey[];
pointerType?: TextScanner.PointerType;
};

export type OptionsContext = OptionsContext1 | OptionsContext2 | OptionsContext3;
Expand Down Expand Up @@ -195,6 +199,7 @@ export type ScanningOptions = {
hidePopupOnCursorExitDelay: number;
normalizeCssZoom: boolean;
scanAltText: boolean;
scanHyperlinkText: boolean;
scanWithoutMousemove: boolean;
scanResolution: string;
};
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 @@ -42,6 +42,7 @@ export type Options = {
matchTypePrefix?: boolean;
sentenceParsingOptions?: SentenceParsingOptions;
scanAltText?: boolean;
scanHyperlinkText?: boolean;
scanWithoutMousemove?: boolean;
scanResolution?: string;
};
Expand Down

0 comments on commit 82d26f1

Please sign in to comment.