Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scanHyperlinkText option #1426

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
11 changes: 11 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 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
1 change: 1 addition & 0 deletions types/ext/settings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,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
Loading