From 3a69956c2465a25e8dc29f06244a97a11721cf3a Mon Sep 17 00:00:00 2001 From: ThinkStu <91378285+Bistutu@users.noreply.github.com> Date: Fri, 26 Apr 2024 23:45:06 +0800 Subject: [PATCH] =?UTF-8?q?feature:=20=E5=A2=9E=E5=8A=A0=E9=BC=A0=E6=A0=87?= =?UTF-8?q?=E5=8F=8C=E5=87=BB=E7=BF=BB=E8=AF=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entrypoints/compat/compat.ts | 7 ++++++- entrypoints/content.ts | 13 ++++++++++++- entrypoints/utils/constant.ts | 4 +++- entrypoints/utils/option.ts | 5 +++++ 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/entrypoints/compat/compat.ts b/entrypoints/compat/compat.ts index db2bbdc..32dd040 100644 --- a/entrypoints/compat/compat.ts +++ b/entrypoints/compat/compat.ts @@ -6,6 +6,7 @@ type SelectFunction = (url: any) => any; interface ReplaceCompatFn { [domain: string]: ReplaceFunction; } + interface SelectCompatFn { [domain: string]: SelectFunction; } @@ -41,5 +42,9 @@ export const selectCompatFn: SelectCompatFn = { ['www.webtrees.net']: (node: any) => { // class='kmsg' if (node.tagName.toLowerCase() === 'div' && node.classList.contains('kmsg')) return true - } + }, + ['webtrees.net']: (node: any) => { + // class='kmsg' + if (node.tagName.toLowerCase() === 'div' && node.classList.contains('kmsg')) return true + }, } \ No newline at end of file diff --git a/entrypoints/content.ts b/entrypoints/content.ts index 14bdaee..95f75be 100644 --- a/entrypoints/content.ts +++ b/entrypoints/content.ts @@ -2,6 +2,7 @@ import {Config} from "./utils/model"; import {cssInject} from "./main/css"; import {handler} from "./main/dom"; import {cache} from "./utils/cache"; +import {DoubleClick} from "@/entrypoints/utils/constant"; export default defineContentScript({ matches: [''], // 匹配所有页面 @@ -53,7 +54,17 @@ export default defineContentScript({ } }); - // todo 2024.4.26 双击翻译)开关控制 + // 6、双击鼠标翻译事件 + document.body.addEventListener('dblclick', event => { + if (config.hotkey == DoubleClick) { + // 通过双击事件获取鼠标位置 + let mouseX = event.clientX; + let mouseY = event.clientY; + // 调用 handler 函数进行翻译 + handler(config, mouseX, mouseY); + } + }); + // background.ts browser.runtime.onMessage.addListener((message, sender, sendResponse) => { diff --git a/entrypoints/utils/constant.ts b/entrypoints/utils/constant.ts index 4ace146..df481d3 100644 --- a/entrypoints/utils/constant.ts +++ b/entrypoints/utils/constant.ts @@ -18,4 +18,6 @@ export const urls = { [services.baidu]: "https://fanyi-api.baidu.com/api/trans/vip/translate", } -export const method = {POST: "POST", GET: "GET",}; \ No newline at end of file +export const method = {POST: "POST", GET: "GET",}; + +export const DoubleClick = "DoubleClick"; \ No newline at end of file diff --git a/entrypoints/utils/option.ts b/entrypoints/utils/option.ts index 8f59ad7..c14adcf 100644 --- a/entrypoints/utils/option.ts +++ b/entrypoints/utils/option.ts @@ -107,6 +107,11 @@ export const options = { value: "`", label: "波浪号键" }, + // 鼠标双击左键 + { + value: 'DoubleClick', + label: "鼠标双击" + }, ], services: [ {