feat: Support multi-touch selection

This commit is contained in:
Gabe
2025-10-26 00:06:52 +08:00
parent 1b646df908
commit 61a515c1d2
4 changed files with 41 additions and 43 deletions

View File

@@ -28,7 +28,7 @@ import { logger } from "./log";
export default class TranslatorManager {
#clearShortcuts = [];
#menuCommandIds = [];
#clearTouchListener = null;
#clearTouchListeners = [];
#isActive = false;
#isUserscript;
#isIframe;
@@ -110,10 +110,8 @@ export default class TranslatorManager {
this.#clearShortcuts = [];
// 触屏
if (this.#clearTouchListener) {
this.#clearTouchListener();
this.#clearTouchListener = null;
}
this.#clearTouchListeners.forEach((clear) => clear());
this.#clearTouchListeners = [];
// 油猴菜单
if (globalThis.GM && this.#menuCommandIds.length > 0) {
@@ -145,8 +143,8 @@ export default class TranslatorManager {
#setupTouchOperations() {
if (this.#isIframe) return;
const { touchTranslate = 2 } = this._translator.setting;
if (touchTranslate === 0) {
const { touchModes = [2] } = this._translator.setting;
if (touchModes.length === 0) {
return;
}
@@ -154,35 +152,31 @@ export default class TranslatorManager {
this.#processActions({ action: MSG_TRANS_TOGGLE });
};
switch (touchTranslate) {
case 2:
case 3:
case 4:
this.#clearTouchListener = touchTapListener(handleTap, {
taps: 1,
fingers: touchTranslate,
});
break;
case 5:
this.#clearTouchListener = touchTapListener(handleTap, {
taps: 2,
fingers: 1,
});
break;
case 6:
this.#clearTouchListener = touchTapListener(handleTap, {
taps: 3,
fingers: 1,
});
break;
case 7:
this.#clearTouchListener = touchTapListener(handleTap, {
taps: 2,
fingers: 2,
});
break;
default:
}
const handleListener = (mode) => {
let options = null;
switch (mode) {
case 2:
case 3:
case 4:
options = { taps: 1, fingers: mode };
break;
case 5:
options = { taps: 2, fingers: 1 };
break;
case 6:
options = { taps: 3, fingers: 1 };
break;
case 7:
options = { taps: 2, fingers: 2 };
break;
default:
}
if (options) {
this.#clearTouchListeners.push(touchTapListener(handleTap, options));
}
};
touchModes.forEach((mode) => handleListener(mode));
}
#handleWindowMessage(event) {