From 9ed80f6d496c00dd52cd78f52885d7f072ef2526 Mon Sep 17 00:00:00 2001 From: Khai Truong Date: Tue, 24 Sep 2024 15:29:21 +0700 Subject: [PATCH] Prevent exclude .tag and .gloss-link from website --- ext/js/app/frontend.js | 3 +++ ext/js/display/display.js | 1 + ext/js/language/text-scanner.js | 15 ++++++++++++--- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/ext/js/app/frontend.js b/ext/js/app/frontend.js index 20c76d4f09..cb2b216be0 100644 --- a/ext/js/app/frontend.js +++ b/ext/js/app/frontend.js @@ -518,13 +518,16 @@ export class Frontend { }); this._updateTextScannerEnabled(); + const touchEventExcludeSelectors = ['a', 'a *'] if (this._pageType !== 'web') { const excludeSelectors = ['.scan-disable', '.scan-disable *']; if (!scanningOptions.enableOnPopupExpressions) { excludeSelectors.push('.source-text', '.source-text *'); } + touchEventExcludeSelectors.push('.gloss-link', '.gloss-link *', '.tag', '.tag *'); this._textScanner.excludeSelector = excludeSelectors.join(','); } + this._textScanner.touchEventExcludeSelector = touchEventExcludeSelectors.join(','); this._updateContentScale(); diff --git a/ext/js/display/display.js b/ext/js/display/display.js index be0c7fddc7..e03d16d09c 100644 --- a/ext/js/display/display.js +++ b/ext/js/display/display.js @@ -1993,6 +1993,7 @@ export class Display extends EventDispatcher { }); this._contentTextScanner.includeSelector = '.click-scannable,.click-scannable *'; this._contentTextScanner.excludeSelector = '.scan-disable,.scan-disable *'; + this._contentTextScanner.touchEventExcludeSelector = 'a,.a *' this._contentTextScanner.prepare(); this._contentTextScanner.on('clear', this._onContentTextScannerClear.bind(this)); this._contentTextScanner.on('searchSuccess', this._onContentTextScannerSearchSuccess.bind(this)); diff --git a/ext/js/language/text-scanner.js b/ext/js/language/text-scanner.js index c04c7f7f8b..c2f610f24f 100644 --- a/ext/js/language/text-scanner.js +++ b/ext/js/language/text-scanner.js @@ -73,6 +73,8 @@ export class TextScanner extends EventDispatcher { /** @type {?string} */ this._excludeSelector = null; /** @type {?string} */ + this._touchExcludeSelector = null; + /** @type {?string} */ this._language = null; /** @type {?import('text-scanner').InputInfo} */ @@ -197,6 +199,15 @@ export class TextScanner extends EventDispatcher { this._excludeSelector = value; } + /** @type {?string} */ + get touchEventExcludeSelector() { + return this._touchExcludeSelector; + } + + set touchEventExcludeSelector(value) { + this._touchExcludeSelector = value; + } + /** @type {?string} */ get language() { return this._language; } set language(value) { this._language = value; } @@ -1657,9 +1668,7 @@ export class TextScanner extends EventDispatcher { */ _getExcludeSelectorForPointerType(pointerType) { if (pointerType === 'touch') { - // Avoid trigger search with tapping on interactive elements. - const popupClickableSelector = '.gloss-link,.gloss-link *,.tag, .tag *, .inflection, a, a *'; - return this._excludeSelector ? `${this._excludeSelector},${popupClickableSelector}` : popupClickableSelector; + return this._excludeSelector ? `${this._excludeSelector},${this.touchEventExcludeSelector}` : this.touchEventExcludeSelector; } return this._excludeSelector; }