mouseover dev

This commit is contained in:
Gabe Yuan
2023-09-06 23:35:09 +08:00
parent bdac67df88
commit 9a2b21eee5
4 changed files with 15308 additions and 10838 deletions

View File

@@ -181,15 +181,15 @@ export const I18N = {
zh: `鼠标悬停`,
en: `Mouseover`,
},
mk_control: {
mk_ctrlKey: {
zh: `Control + 鼠标悬停`,
en: `Control + Mouseover`,
},
mk_shift: {
mk_shiftKey: {
zh: `Shift + 鼠标悬停`,
en: `Shift + Mouseover`,
},
mk_alt: {
mk_altKey: {
zh: `Alt + 鼠标悬停`,
en: `Alt + Mouseover`,
},

View File

@@ -164,9 +164,9 @@ export const OPT_STYLE_USE_COLOR = [
export const OPT_MOUSEKEY_DISABLE = "mk_disable";
export const OPT_MOUSEKEY_NONE = "mk_none";
export const OPT_MOUSEKEY_CONTROL = "mk_control";
export const OPT_MOUSEKEY_SHIFT = "mk_shift";
export const OPT_MOUSEKEY_ALT = "mk_alt";
export const OPT_MOUSEKEY_CONTROL = "mk_ctrlKey";
export const OPT_MOUSEKEY_SHIFT = "mk_shiftKey";
export const OPT_MOUSEKEY_ALT = "mk_altKey";
export const OPT_MOUSEKEY_ALL = [
OPT_MOUSEKEY_DISABLE,
OPT_MOUSEKEY_NONE,

View File

@@ -8,6 +8,7 @@ import {
OPT_STYLE_FUZZY,
SHADOW_KEY,
OPT_MOUSEKEY_DISABLE,
OPT_MOUSEKEY_NONE,
} from "../config";
import Content from "../views/Content";
import { updateFetchPool, clearFetchPool } from "./fetch";
@@ -38,7 +39,6 @@ export class Translator {
"iframe",
];
_eventName = genEventName();
_keydownNow = "";
// 显示
_interseObserver = new IntersectionObserver(
@@ -241,32 +241,16 @@ export class Translator {
node.addEventListener("mouseover", this._handleMouseover);
}
});
// 监听键盘事件
window.addEventListener("keydown", this._handleKeydown);
window.addEventListener("keyup", this._handleKeyup);
};
_handleMouseover = (e) => {
if (
this._keydownNow &&
this._setting?.mouseKey?.endsWith(this._keydownNow)
) {
const key = this._setting.mouseKey.slice(3);
if (this._setting.mouseKey === OPT_MOUSEKEY_NONE || e[key]) {
e.target.removeEventListener("mouseover", this._handleMouseover);
this._render(e.target);
}
};
_handleKeydown = (e) => {
console.log("keydown", e.key);
this._keydownNow = e.key.toLowerCase();
};
_handleKeyup = (e) => {
console.log("keyup", e.key);
this._keydownNow = "";
};
_unRegister = () => {
// 解除节点变化监听
this._mutaObserver.disconnect();
@@ -290,11 +274,6 @@ export class Translator {
node.querySelector(APP_LCNAME)?.remove();
});
// 解除监听键盘
window.removeEventListener("keydown", this._handleKeydown);
window.removeEventListener("keyup", this._handleKeyup);
this._keydownNow = "";
// 清空节点集合
this._rootNodes.clear();
this._tranNodes.clear();

26107
yarn.lock

File diff suppressed because it is too large Load Diff