Compare commits
107 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
beca31f55d | ||
|
|
c7df103950 | ||
|
|
4bf7972ad5 | ||
|
|
534eaed1ed | ||
|
|
7e014e7385 | ||
|
|
34adb2660b | ||
|
|
b6bc165cf0 | ||
|
|
bdd5ed7fc7 | ||
|
|
95d19417c3 | ||
|
|
30ebebdd71 | ||
|
|
e9c557776d | ||
|
|
535a43b698 | ||
|
|
59752ed4aa | ||
|
|
b3e7b8f3f1 | ||
|
|
c4e9365512 | ||
|
|
7d3972d3a8 | ||
|
|
52ca4306fd | ||
|
|
da368ee612 | ||
|
|
22c50e7765 | ||
|
|
7bc39dd1bc | ||
|
|
c80ead6116 | ||
|
|
67e76e4009 | ||
|
|
b213218a30 | ||
|
|
c629a1252c | ||
|
|
64d2481e93 | ||
|
|
e7d6a6add8 | ||
|
|
edc25f7da4 | ||
|
|
5bff84ace1 | ||
|
|
f8bfcba317 | ||
|
|
013a05201b | ||
|
|
433e811821 | ||
|
|
df4cfc0fbc | ||
|
|
1bfb465fd6 | ||
|
|
d5d5ec3fef | ||
|
|
0a32f94d32 | ||
|
|
8067f34ce6 | ||
|
|
214c189a7c | ||
|
|
1f67afc8d8 | ||
|
|
7d4af27919 | ||
|
|
2d651abfdd | ||
|
|
6e06fe79cd | ||
|
|
6093577591 | ||
|
|
4b23ee733f | ||
|
|
46428b7c7f | ||
|
|
6805340a9a | ||
|
|
df36ca8d8b | ||
|
|
fe13de7c30 | ||
|
|
b00f636b72 | ||
|
|
8d074e63e1 | ||
|
|
37989b0089 | ||
|
|
477361eb40 | ||
|
|
94288b5dc3 | ||
|
|
84de1e0f12 | ||
|
|
06f93c1c10 | ||
|
|
450283b80a | ||
|
|
44aeed03a6 | ||
|
|
fa4569415d | ||
|
|
a341bf30ba | ||
|
|
34a7354c84 | ||
|
|
21b5dfbe98 | ||
|
|
c1920f5cdd | ||
|
|
3e24568df9 | ||
|
|
b785cfe854 | ||
|
|
15367bd117 | ||
|
|
d7eaac5aca | ||
|
|
d4526d605c | ||
|
|
52979356ca | ||
|
|
c6d3d6454f | ||
|
|
0d7112187d | ||
|
|
045ff3c3d9 | ||
|
|
dd68a73efd | ||
|
|
5947dc182e | ||
|
|
e185bbdb4d | ||
|
|
9368320c38 | ||
|
|
f65314bc2d | ||
|
|
1791e36038 | ||
|
|
8d93094af5 | ||
|
|
43f34fe6ed | ||
|
|
83911b2164 | ||
|
|
94c7494e90 | ||
|
|
65f2177299 | ||
|
|
f033b11e63 | ||
|
|
02f26af592 | ||
|
|
4125aba808 | ||
|
|
e89da9120c | ||
|
|
160fc218fc | ||
|
|
507d54dba0 | ||
|
|
f3029a0f76 | ||
|
|
53181588cf | ||
|
|
f88aa159fc | ||
|
|
fb2b517a67 | ||
|
|
6e952a9530 | ||
|
|
d9acef8d56 | ||
|
|
113a4d8eca | ||
|
|
6d5b93c01b | ||
|
|
5746911651 | ||
|
|
7173692db7 | ||
|
|
b13a63e568 | ||
|
|
791ec65579 | ||
|
|
dd99fddc07 | ||
|
|
5cd6977a6e | ||
|
|
5af66204c4 | ||
|
|
595efe808f | ||
|
|
7b4b3b020c | ||
|
|
3e96540b56 | ||
|
|
88b791bd73 | ||
|
|
7817019e70 |
2
.env
2
.env
@@ -2,7 +2,7 @@ GENERATE_SOURCEMAP=false
|
|||||||
|
|
||||||
REACT_APP_NAME=KISS Translator
|
REACT_APP_NAME=KISS Translator
|
||||||
REACT_APP_NAME_CN=简约翻译
|
REACT_APP_NAME_CN=简约翻译
|
||||||
REACT_APP_VERSION=1.7.5
|
REACT_APP_VERSION=1.7.15
|
||||||
|
|
||||||
REACT_APP_HOMEPAGE=https://github.com/fishjar/kiss-translator
|
REACT_APP_HOMEPAGE=https://github.com/fishjar/kiss-translator
|
||||||
|
|
||||||
|
|||||||
29
README.en.md
29
README.en.md
@@ -1,19 +1,9 @@
|
|||||||
# KISS Translator
|
# KISS Translator
|
||||||
|
|
||||||
A minimalist [bilingual translation Extension & Greasemonkey Script](https://github.com/fishjar/kiss-translator).
|
A simple, open source [bilingual translation extension & Greasemonkey script](https://github.com/fishjar/kiss-translator).
|
||||||
|
|
||||||
[kiss-translator.webm](https://github.com/fishjar/kiss-translator/assets/1157624/f7ba8a5c-e4a8-4d5a-823a-5c5c67a0a47f)
|
[kiss-translator.webm](https://github.com/fishjar/kiss-translator/assets/1157624/f7ba8a5c-e4a8-4d5a-823a-5c5c67a0a47f)
|
||||||
|
|
||||||
## Inspiration
|
|
||||||
|
|
||||||
The inspiration for this project comes from [Immersive Translate](https://github.com/immersive-translate/immersive-translate). After trying it out, I found that it can be used together with the [Webpage Word Translation Extension](https://github.com/fishjar/kiss-dictionary) developed by me earlier, which just forms a very good supplement.
|
|
||||||
|
|
||||||
But the function of this extension is a bit complicated for me, and only the compiled and obfuscated installation package is provided, and the source code is not provided, which cannot meet some of my personalized customization needs.
|
|
||||||
|
|
||||||
It just so happens that I am obsessed with translation tools. Based on the concept of "mainly for personal use, as long as you can use it", I made one. At present, the first version is completed, which basically meets the needs of personal use.
|
|
||||||
|
|
||||||
If you also like a little more simplicity, welcome to pick it up.
|
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
- [x] Keep it simple, smart
|
- [x] Keep it simple, smart
|
||||||
@@ -22,11 +12,13 @@ If you also like a little more simplicity, welcome to pick it up.
|
|||||||
- [x] Chrome/Edge/Firefox/Kiwi
|
- [x] Chrome/Edge/Firefox/Kiwi
|
||||||
- [ ] Safari
|
- [ ] Safari
|
||||||
- [x] Supports multiple translation services
|
- [x] Supports multiple translation services
|
||||||
- [x] Google/Microsoft/DeepL/OpenAI
|
- [x] Google/Microsoft/DeepL/OpenAI/Gemini/CloudflareAI/Baidu/Tencent
|
||||||
- [x] Custom translation interface
|
- [x] Custom translation interface
|
||||||
- [x] Covers common translation scenarios
|
- [x] Covers common translation scenarios
|
||||||
- [x] Web bilingual translation
|
- [x] Web bilingual translation
|
||||||
- [x] Input box translation
|
- [x] Input box translation
|
||||||
|
- [x] Seletction translation
|
||||||
|
- [x] Favorite Words
|
||||||
- [x] Mouseover translation
|
- [x] Mouseover translation
|
||||||
- [x] YouTube subtitle translation
|
- [x] YouTube subtitle translation
|
||||||
- [x] Cross-client data synchronization
|
- [x] Cross-client data synchronization
|
||||||
@@ -38,16 +30,17 @@ If you also like a little more simplicity, welcome to pick it up.
|
|||||||
- [x] Custom shortcut keys
|
- [x] Custom shortcut keys
|
||||||
- `Alt+Q` Toggle Translation
|
- `Alt+Q` Toggle Translation
|
||||||
- `Alt+C` Toggle Styles
|
- `Alt+C` Toggle Styles
|
||||||
- `Alt+K` Open Popup
|
- `Alt+K` Open Setting Popup
|
||||||
- `Alt+O` Open Options
|
- `Alt+S` Open Translate Popup / Translate Selected Text
|
||||||
|
- `Alt+O` Open Options Page
|
||||||
- `Alt+I` Input Box Translation
|
- `Alt+I` Input Box Translation
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
|
||||||
> Note: For the following reasons, it is recommended to use browser extensions first
|
> Note: For the following reasons, it is recommended to use browser extensions first
|
||||||
>
|
>
|
||||||
> - Browser extension can use local language recognition
|
> - Browser extensions have more complete functions (local language recognition, context menu, etc.)
|
||||||
> - Grease Monkey script will encounter more usage problems
|
> - Grease Monkey script will encounter more usage problems (cross domain issues, script conflicts, etc.)
|
||||||
|
|
||||||
- [x] Browser extension
|
- [x] Browser extension
|
||||||
- [x] Chrome [Installation address](https://chrome.google.com/webstore/detail/kiss-translator/bdiifdefkgmcblbcghdlonllpjhhjgof?hl=zh-CN)
|
- [x] Chrome [Installation address](https://chrome.google.com/webstore/detail/kiss-translator/bdiifdefkgmcblbcghdlonllpjhhjgof?hl=zh-CN)
|
||||||
@@ -55,9 +48,9 @@ If you also like a little more simplicity, welcome to pick it up.
|
|||||||
- [x] Firefox [Installation address](https://addons.mozilla.org/zh-CN/firefox/addon/kiss-translator/)
|
- [x] Firefox [Installation address](https://addons.mozilla.org/zh-CN/firefox/addon/kiss-translator/)
|
||||||
- [ ] Safari
|
- [ ] Safari
|
||||||
- [x] GreaseMonkey Script
|
- [x] GreaseMonkey Script
|
||||||
- [x] Chrome/Edge/Firefox ([Tampermonkey](https://www.tampermonkey.net/)/[Violentmonkey](https://violentmonkey.github.io/)) [Installation link 1](https://fishjar.github.io/kiss-translator/kiss-translator.user.js)、 [Installation link 2](https://kiss-translator.rayjar.com/kiss-translator.user.js)
|
- [x] Chrome/Edge/Firefox ([Tampermonkey](https://www.tampermonkey.net/)/[Violentmonkey](https://violentmonkey.github.io/)) [Installation link](https://fishjar.github.io/kiss-translator/kiss-translator.user.js)
|
||||||
- Greasy Fork [Installation address](https://greasyfork.org/zh-CN/scripts/472840-kiss-translator)
|
- Greasy Fork [Installation address](https://greasyfork.org/zh-CN/scripts/472840-kiss-translator)
|
||||||
- [x] iOS Safari ([Userscripts Safari](https://github.com/quoid/userscripts)) [Installation link 1](https://fishjar.github.io/kiss-translator/kiss-translator-ios-safari.user.js)、 [Installation link 2](https://kiss-translator.rayjar.com/kiss-translator.user-ios-safari.js)
|
- [x] iOS Safari ([Userscripts Safari](https://github.com/quoid/userscripts)) [Installation link](https://fishjar.github.io/kiss-translator/kiss-translator-ios-safari.user.js)
|
||||||
|
|
||||||
## Associated Projects
|
## Associated Projects
|
||||||
|
|
||||||
|
|||||||
33
README.md
33
README.md
@@ -1,19 +1,9 @@
|
|||||||
# 简约翻译
|
# 简约翻译
|
||||||
|
|
||||||
一个简约的 [网页双语翻译扩展 & 油猴脚本](https://github.com/fishjar/kiss-translator)。
|
一个简约、开源的 [双语对照翻译扩展 & 油猴脚本](https://github.com/fishjar/kiss-translator)。
|
||||||
|
|
||||||
[kiss-translator.webm](https://github.com/fishjar/kiss-translator/assets/1157624/f7ba8a5c-e4a8-4d5a-823a-5c5c67a0a47f)
|
[kiss-translator.webm](https://github.com/fishjar/kiss-translator/assets/1157624/f7ba8a5c-e4a8-4d5a-823a-5c5c67a0a47f)
|
||||||
|
|
||||||
## 缘由
|
|
||||||
|
|
||||||
本项目灵感来源于 [Immersive Translate](https://github.com/immersive-translate/immersive-translate),在试用了后,发现搭配本人早前开发的 [网页划词翻译扩展](https://github.com/fishjar/kiss-dictionary) 一起使用,刚好形成很好补充。
|
|
||||||
|
|
||||||
但该扩展的功能对我来说有些繁杂了,而且只提供编译混淆后的安装包,没有提供源代码,无法满足我的一些个性化定制需求。
|
|
||||||
|
|
||||||
恰巧本人对翻译类工具有些执念,本着`“自用为主,能用就行”`的理念,于是动手撸了一个,目前初版完成,基本达到个人使用需求。
|
|
||||||
|
|
||||||
如果你也喜欢简约一点的,欢迎自取。
|
|
||||||
|
|
||||||
## 特性
|
## 特性
|
||||||
|
|
||||||
- [x] 保持简约
|
- [x] 保持简约
|
||||||
@@ -22,11 +12,13 @@
|
|||||||
- [x] Chrome/Edge/Firefox/Kiwi
|
- [x] Chrome/Edge/Firefox/Kiwi
|
||||||
- [ ] Safari
|
- [ ] Safari
|
||||||
- [x] 支持多种翻译服务
|
- [x] 支持多种翻译服务
|
||||||
- [x] Google/Microsoft/DeepL/OpenAI
|
- [x] Google/Microsoft/DeepL/OpenAI/Gemini/CloudflareAI/Baidu/Tencent
|
||||||
- [x] 自定义翻译接口
|
- [x] 自定义翻译接口
|
||||||
- [x] 覆盖常见翻译场景
|
- [x] 覆盖常见翻译场景
|
||||||
- [x] 网页双语翻译
|
- [x] 网页双语对照翻译
|
||||||
- [x] 输入框翻译
|
- [x] 输入框翻译
|
||||||
|
- [x] 划词翻译
|
||||||
|
- [x] 收藏词汇
|
||||||
- [x] 鼠标悬停翻译
|
- [x] 鼠标悬停翻译
|
||||||
- [x] YouTube 字幕翻译
|
- [x] YouTube 字幕翻译
|
||||||
- [x] 跨客户端数据同步
|
- [x] 跨客户端数据同步
|
||||||
@@ -38,16 +30,17 @@
|
|||||||
- [x] 自定义快捷键
|
- [x] 自定义快捷键
|
||||||
- `Alt+Q` 开启翻译
|
- `Alt+Q` 开启翻译
|
||||||
- `Alt+C` 切换样式
|
- `Alt+C` 切换样式
|
||||||
- `Alt+K` 打开弹窗
|
- `Alt+K` 打开设置弹窗
|
||||||
- `Alt+O` 打开设置
|
- `Alt+S` 打开翻译弹窗/翻译选中文字
|
||||||
|
- `Alt+O` 打开设置页面
|
||||||
- `Alt+I` 输入框翻译
|
- `Alt+I` 输入框翻译
|
||||||
|
|
||||||
## 安装
|
## 安装
|
||||||
|
|
||||||
> 注:基于以下原因,建议优先使用浏览器扩展
|
> 注:基于以下原因,建议优先使用浏览器扩展
|
||||||
>
|
>
|
||||||
> - 浏览器扩展可以使用本地的语言识别
|
> - 浏览器扩展的功能更完整(本地语言识别、右键菜单等)
|
||||||
> - 油猴脚本会遇到更多使用上的问题
|
> - 油猴脚本会遇到更多使用上的问题(跨域问题、脚本冲突等)
|
||||||
|
|
||||||
- [x] 浏览器扩展
|
- [x] 浏览器扩展
|
||||||
- [x] Chrome [安装地址](https://chrome.google.com/webstore/detail/kiss-translator/bdiifdefkgmcblbcghdlonllpjhhjgof?hl=zh-CN)
|
- [x] Chrome [安装地址](https://chrome.google.com/webstore/detail/kiss-translator/bdiifdefkgmcblbcghdlonllpjhhjgof?hl=zh-CN)
|
||||||
@@ -55,9 +48,9 @@
|
|||||||
- [x] Firefox [安装地址](https://addons.mozilla.org/zh-CN/firefox/addon/kiss-translator/)
|
- [x] Firefox [安装地址](https://addons.mozilla.org/zh-CN/firefox/addon/kiss-translator/)
|
||||||
- [ ] Safari
|
- [ ] Safari
|
||||||
- [x] 油猴脚本
|
- [x] 油猴脚本
|
||||||
- [x] Chrome/Edge/Firefox ([Tampermonkey](https://www.tampermonkey.net/)/[Violentmonkey](https://violentmonkey.github.io/)) [安装链接 1](https://fishjar.github.io/kiss-translator/kiss-translator.user.js)、 [安装链接 2](https://kiss-translator.rayjar.com/kiss-translator.user.js)
|
- [x] Chrome/Edge/Firefox ([Tampermonkey](https://www.tampermonkey.net/)/[Violentmonkey](https://violentmonkey.github.io/)) [安装链接](https://fishjar.github.io/kiss-translator/kiss-translator.user.js)
|
||||||
- Greasy Fork [安装地址](https://greasyfork.org/zh-CN/scripts/472840-kiss-translator)
|
- Greasy Fork [安装地址](https://greasyfork.org/zh-CN/scripts/472840-kiss-translator)
|
||||||
- [x] iOS Safari ([Userscripts Safari](https://github.com/quoid/userscripts)) [安装链接 1](https://fishjar.github.io/kiss-translator/kiss-translator-ios-safari.user.js)、 [安装链接 2](https://kiss-translator.rayjar.com/kiss-translator.user-ios-safari.js)
|
- [x] iOS Safari ([Userscripts Safari](https://github.com/quoid/userscripts)) [安装链接](https://fishjar.github.io/kiss-translator/kiss-translator-ios-safari.user.js)
|
||||||
|
|
||||||
## 关联项目
|
## 关联项目
|
||||||
|
|
||||||
@@ -72,7 +65,7 @@
|
|||||||
- 针对一些特殊网站的修正脚本。
|
- 针对一些特殊网站的修正脚本。
|
||||||
- 以便翻译软件得到更好的展示效果。
|
- 以便翻译软件得到更好的展示效果。
|
||||||
- 翻译接口代理: [https://github.com/fishjar/kiss-proxy](https://github.com/fishjar/kiss-proxy)
|
- 翻译接口代理: [https://github.com/fishjar/kiss-proxy](https://github.com/fishjar/kiss-proxy)
|
||||||
- 如果访问某个翻译接口遇到网络问题,这个代理服务也许可以帮你到你。
|
- 如果访问某个翻译接口遇到网络问题,这个代理服务也许可以帮到你。
|
||||||
- 自己部署,自己管理。
|
- 自己部署,自己管理。
|
||||||
- 简约词典插件: [https://github.com/fishjar/kiss-dictionary](https://github.com/fishjar/kiss-dictionary)
|
- 简约词典插件: [https://github.com/fishjar/kiss-dictionary](https://github.com/fishjar/kiss-dictionary)
|
||||||
- 搭配本项目一起使用的划词翻译插件。
|
- 搭配本项目一起使用的划词翻译插件。
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ const userscriptWebpack = (config, env) => {
|
|||||||
// @name ${process.env.REACT_APP_NAME}
|
// @name ${process.env.REACT_APP_NAME}
|
||||||
// @namespace ${process.env.REACT_APP_HOMEPAGE}
|
// @namespace ${process.env.REACT_APP_HOMEPAGE}
|
||||||
// @version ${process.env.REACT_APP_VERSION}
|
// @version ${process.env.REACT_APP_VERSION}
|
||||||
// @description A minimalist bilingual translation Extension & Greasemonkey Script (一个简约的网页双语翻译扩展 & 油猴脚本)
|
// @description A simple bilingual translation extension & Greasemonkey script (一个简约的双语对照翻译扩展 & 油猴脚本)
|
||||||
// @author Gabe<yugang2002@gmail.com>
|
// @author Gabe<yugang2002@gmail.com>
|
||||||
// @homepageURL ${process.env.REACT_APP_HOMEPAGE}
|
// @homepageURL ${process.env.REACT_APP_HOMEPAGE}
|
||||||
// @license GPL-3.0
|
// @license GPL-3.0
|
||||||
@@ -85,6 +85,7 @@ const userscriptWebpack = (config, env) => {
|
|||||||
// @updateURL ${process.env.REACT_APP_USERSCRIPT_DOWNLOADURL}
|
// @updateURL ${process.env.REACT_APP_USERSCRIPT_DOWNLOADURL}
|
||||||
// @grant GM.xmlHttpRequest
|
// @grant GM.xmlHttpRequest
|
||||||
// @grant GM.registerMenuCommand
|
// @grant GM.registerMenuCommand
|
||||||
|
// @grant GM.unregisterMenuCommand
|
||||||
// @grant GM.setValue
|
// @grant GM.setValue
|
||||||
// @grant GM.getValue
|
// @grant GM.getValue
|
||||||
// @grant GM.deleteValue
|
// @grant GM.deleteValue
|
||||||
@@ -95,7 +96,9 @@ const userscriptWebpack = (config, env) => {
|
|||||||
// @connect edge.microsoft.com
|
// @connect edge.microsoft.com
|
||||||
// @connect api-free.deepl.com
|
// @connect api-free.deepl.com
|
||||||
// @connect api.deepl.com
|
// @connect api.deepl.com
|
||||||
|
// @connect www2.deepl.com
|
||||||
// @connect api.openai.com
|
// @connect api.openai.com
|
||||||
|
// @connect generativelanguage.googleapis.com
|
||||||
// @connect openai.azure.com
|
// @connect openai.azure.com
|
||||||
// @connect workers.dev
|
// @connect workers.dev
|
||||||
// @connect github.io
|
// @connect github.io
|
||||||
@@ -103,7 +106,12 @@ const userscriptWebpack = (config, env) => {
|
|||||||
// @connect kiss-translator.rayjar.com
|
// @connect kiss-translator.rayjar.com
|
||||||
// @connect ghproxy.com
|
// @connect ghproxy.com
|
||||||
// @connect dav.jianguoyun.com
|
// @connect dav.jianguoyun.com
|
||||||
|
// @connect fanyi.baidu.com
|
||||||
|
// @connect transmart.qq.com
|
||||||
// @connect localhost:3000
|
// @connect localhost:3000
|
||||||
|
// @connect 127.0.0.1:3000
|
||||||
|
// @connect localhost:1188
|
||||||
|
// @connect 127.0.0.1:1188
|
||||||
// @run-at document-end
|
// @run-at document-end
|
||||||
// ==/UserScript==
|
// ==/UserScript==
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "kiss-translator",
|
"name": "kiss-translator",
|
||||||
"description": "A minimalist bilingual translation Extension & Greasemonkey Script",
|
"description": "A minimalist bilingual translation Extension & Greasemonkey Script",
|
||||||
"version": "1.7.5",
|
"version": "1.7.15",
|
||||||
"author": "Gabe<yugang2002@gmail.com>",
|
"author": "Gabe<yugang2002@gmail.com>",
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -30,7 +30,6 @@
|
|||||||
"build:userscript": "rm -rf build/userscript && mkdir build/userscript && cp build/web/*.user.js build/userscript/",
|
"build:userscript": "rm -rf build/userscript && mkdir build/userscript && cp build/web/*.user.js build/userscript/",
|
||||||
"build:rules": "babel-node src/rules.js",
|
"build:rules": "babel-node src/rules.js",
|
||||||
"build": "pnpm build:chrome && pnpm build:edge && pnpm build:firefox && pnpm build:web && pnpm build:userscript-ios && pnpm build:userscript && pnpm build:rules",
|
"build": "pnpm build:chrome && pnpm build:edge && pnpm build:firefox && pnpm build:web && pnpm build:userscript-ios && pnpm build:userscript && pnpm build:rules",
|
||||||
"deploy:web": "wrangler pages deploy ./build/web --project-name kiss-translator",
|
|
||||||
"test": "react-app-rewired test",
|
"test": "react-app-rewired test",
|
||||||
"eject": "react-scripts eject"
|
"eject": "react-scripts eject"
|
||||||
},
|
},
|
||||||
@@ -62,8 +61,6 @@
|
|||||||
"@babel/node": "^7.22.10",
|
"@babel/node": "^7.22.10",
|
||||||
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
|
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
|
||||||
"@babel/preset-env": "^7.22.10",
|
"@babel/preset-env": "^7.22.10",
|
||||||
"react-app-rewired": "^2.2.1",
|
"react-app-rewired": "^2.2.1"
|
||||||
"wrangler": "^3.4.0"
|
}
|
||||||
},
|
|
||||||
"packageManager": "yarn@3.6.3"
|
|
||||||
}
|
}
|
||||||
|
|||||||
529
pnpm-lock.yaml
generated
529
pnpm-lock.yaml
generated
@@ -37,7 +37,7 @@ dependencies:
|
|||||||
version: 6.16.0(react-dom@18.2.0)(react@18.2.0)
|
version: 6.16.0(react-dom@18.2.0)(react@18.2.0)
|
||||||
react-scripts:
|
react-scripts:
|
||||||
specifier: 5.0.1
|
specifier: 5.0.1
|
||||||
version: 5.0.1(@babel/plugin-syntax-flow@7.22.5)(@babel/plugin-transform-react-jsx@7.22.15)(esbuild@0.17.19)(eslint@8.49.0)(react@18.2.0)(typescript@5.2.2)
|
version: 5.0.1(@babel/plugin-syntax-flow@7.22.5)(@babel/plugin-transform-react-jsx@7.22.15)(eslint@8.49.0)(react@18.2.0)(typescript@5.2.2)
|
||||||
webdav:
|
webdav:
|
||||||
specifier: ^5.3.0
|
specifier: ^5.3.0
|
||||||
version: 5.3.0
|
version: 5.3.0
|
||||||
@@ -61,9 +61,6 @@ devDependencies:
|
|||||||
react-app-rewired:
|
react-app-rewired:
|
||||||
specifier: ^2.2.1
|
specifier: ^2.2.1
|
||||||
version: 2.2.1(react-scripts@5.0.1)
|
version: 2.2.1(react-scripts@5.0.1)
|
||||||
wrangler:
|
|
||||||
specifier: ^3.4.0
|
|
||||||
version: 3.9.0
|
|
||||||
|
|
||||||
packages:
|
packages:
|
||||||
|
|
||||||
@@ -1434,57 +1431,6 @@ packages:
|
|||||||
node-fetch: 3.3.2
|
node-fetch: 3.3.2
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
/@cloudflare/kv-asset-handler@0.2.0:
|
|
||||||
resolution: {integrity: sha512-MVbXLbTcAotOPUj0pAMhVtJ+3/kFkwJqc5qNOleOZTv6QkZZABDMS21dSrSlVswEHwrpWC03e4fWytjqKvuE2A==}
|
|
||||||
dependencies:
|
|
||||||
mime: 3.0.0
|
|
||||||
dev: true
|
|
||||||
|
|
||||||
/@cloudflare/workerd-darwin-64@1.20230904.0:
|
|
||||||
resolution: {integrity: sha512-/GDlmxAFbDtrQwP4zOXFbqOfaPvkDxdsCoEa+KEBcAl5uR98+7WW5/b8naBHX+t26uS7p4bLlImM8J5F1ienRQ==}
|
|
||||||
engines: {node: '>=16'}
|
|
||||||
cpu: [x64]
|
|
||||||
os: [darwin]
|
|
||||||
requiresBuild: true
|
|
||||||
dev: true
|
|
||||||
optional: true
|
|
||||||
|
|
||||||
/@cloudflare/workerd-darwin-arm64@1.20230904.0:
|
|
||||||
resolution: {integrity: sha512-x8WXNc2xnDqr5y1iirnNdyx8GZY3rL5xiF7ebK3mKQeB+jFjkhO71yuPTkDCzUWtOvw1Wfd4jbwy4wxacMX4mQ==}
|
|
||||||
engines: {node: '>=16'}
|
|
||||||
cpu: [arm64]
|
|
||||||
os: [darwin]
|
|
||||||
requiresBuild: true
|
|
||||||
dev: true
|
|
||||||
optional: true
|
|
||||||
|
|
||||||
/@cloudflare/workerd-linux-64@1.20230904.0:
|
|
||||||
resolution: {integrity: sha512-V58xyMS3oDpKO8Dpdh0r0BXm99OzoGgvWe9ufttVraj/1NTMGELwb6i9ySb8k3F1J9m/sO26+TV7pQc/bGC1VQ==}
|
|
||||||
engines: {node: '>=16'}
|
|
||||||
cpu: [x64]
|
|
||||||
os: [linux]
|
|
||||||
requiresBuild: true
|
|
||||||
dev: true
|
|
||||||
optional: true
|
|
||||||
|
|
||||||
/@cloudflare/workerd-linux-arm64@1.20230904.0:
|
|
||||||
resolution: {integrity: sha512-VrDaW+pjb5IAKEnNWtEaFiG377kXKmk5Fu0Era4W+jKzPON2BW/qRb/4LNHXQ4yxg/2HLm7RiUTn7JZtt1qO6A==}
|
|
||||||
engines: {node: '>=16'}
|
|
||||||
cpu: [arm64]
|
|
||||||
os: [linux]
|
|
||||||
requiresBuild: true
|
|
||||||
dev: true
|
|
||||||
optional: true
|
|
||||||
|
|
||||||
/@cloudflare/workerd-windows-64@1.20230904.0:
|
|
||||||
resolution: {integrity: sha512-/R/dE8uy+8J2YeXfDhI8/Bg7YUirdbbjH5/l/Vv00ZRE0lC3nPLcYeyBXSwXIQ6/Xht3gN+lksLQgKd0ZWRd+Q==}
|
|
||||||
engines: {node: '>=16'}
|
|
||||||
cpu: [x64]
|
|
||||||
os: [win32]
|
|
||||||
requiresBuild: true
|
|
||||||
dev: true
|
|
||||||
optional: true
|
|
||||||
|
|
||||||
/@csstools/normalize.css@12.0.0:
|
/@csstools/normalize.css@12.0.0:
|
||||||
resolution: {integrity: sha512-M0qqxAcwCsIVfpFQSlGN5XjXWu8l5JDZN+fPt1LeW5SZexQTgnaEvgXAY+CeygRw0EeppWHi12JxESWiWrB0Sg==}
|
resolution: {integrity: sha512-M0qqxAcwCsIVfpFQSlGN5XjXWu8l5JDZN+fPt1LeW5SZexQTgnaEvgXAY+CeygRw0EeppWHi12JxESWiWrB0Sg==}
|
||||||
|
|
||||||
@@ -1742,200 +1688,6 @@ packages:
|
|||||||
resolution: {integrity: sha512-EsBwpc7hBUJWAsNPBmJy4hxWx12v6bshQsldrVmjxJoc3isbxhOrF2IcCpaXxfvq03NwkI7sbsOLXbYuqF/8Ww==}
|
resolution: {integrity: sha512-EsBwpc7hBUJWAsNPBmJy4hxWx12v6bshQsldrVmjxJoc3isbxhOrF2IcCpaXxfvq03NwkI7sbsOLXbYuqF/8Ww==}
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
/@esbuild-plugins/node-globals-polyfill@0.2.3(esbuild@0.17.19):
|
|
||||||
resolution: {integrity: sha512-r3MIryXDeXDOZh7ih1l/yE9ZLORCd5e8vWg02azWRGj5SPTuoh69A2AIyn0Z31V/kHBfZ4HgWJ+OK3GTTwLmnw==}
|
|
||||||
peerDependencies:
|
|
||||||
esbuild: '*'
|
|
||||||
dependencies:
|
|
||||||
esbuild: 0.17.19
|
|
||||||
dev: true
|
|
||||||
|
|
||||||
/@esbuild-plugins/node-modules-polyfill@0.2.2(esbuild@0.17.19):
|
|
||||||
resolution: {integrity: sha512-LXV7QsWJxRuMYvKbiznh+U1ilIop3g2TeKRzUxOG5X3YITc8JyyTa90BmLwqqv0YnX4v32CSlG+vsziZp9dMvA==}
|
|
||||||
peerDependencies:
|
|
||||||
esbuild: '*'
|
|
||||||
dependencies:
|
|
||||||
esbuild: 0.17.19
|
|
||||||
escape-string-regexp: 4.0.0
|
|
||||||
rollup-plugin-node-polyfills: 0.2.1
|
|
||||||
dev: true
|
|
||||||
|
|
||||||
/@esbuild/android-arm64@0.17.19:
|
|
||||||
resolution: {integrity: sha512-KBMWvEZooR7+kzY0BtbTQn0OAYY7CsiydT63pVEaPtVYF0hXbUaOyZog37DKxK7NF3XacBJOpYT4adIJh+avxA==}
|
|
||||||
engines: {node: '>=12'}
|
|
||||||
cpu: [arm64]
|
|
||||||
os: [android]
|
|
||||||
requiresBuild: true
|
|
||||||
optional: true
|
|
||||||
|
|
||||||
/@esbuild/android-arm@0.17.19:
|
|
||||||
resolution: {integrity: sha512-rIKddzqhmav7MSmoFCmDIb6e2W57geRsM94gV2l38fzhXMwq7hZoClug9USI2pFRGL06f4IOPHHpFNOkWieR8A==}
|
|
||||||
engines: {node: '>=12'}
|
|
||||||
cpu: [arm]
|
|
||||||
os: [android]
|
|
||||||
requiresBuild: true
|
|
||||||
optional: true
|
|
||||||
|
|
||||||
/@esbuild/android-x64@0.17.19:
|
|
||||||
resolution: {integrity: sha512-uUTTc4xGNDT7YSArp/zbtmbhO0uEEK9/ETW29Wk1thYUJBz3IVnvgEiEwEa9IeLyvnpKrWK64Utw2bgUmDveww==}
|
|
||||||
engines: {node: '>=12'}
|
|
||||||
cpu: [x64]
|
|
||||||
os: [android]
|
|
||||||
requiresBuild: true
|
|
||||||
optional: true
|
|
||||||
|
|
||||||
/@esbuild/darwin-arm64@0.17.19:
|
|
||||||
resolution: {integrity: sha512-80wEoCfF/hFKM6WE1FyBHc9SfUblloAWx6FJkFWTWiCoht9Mc0ARGEM47e67W9rI09YoUxJL68WHfDRYEAvOhg==}
|
|
||||||
engines: {node: '>=12'}
|
|
||||||
cpu: [arm64]
|
|
||||||
os: [darwin]
|
|
||||||
requiresBuild: true
|
|
||||||
optional: true
|
|
||||||
|
|
||||||
/@esbuild/darwin-x64@0.17.19:
|
|
||||||
resolution: {integrity: sha512-IJM4JJsLhRYr9xdtLytPLSH9k/oxR3boaUIYiHkAawtwNOXKE8KoU8tMvryogdcT8AU+Bflmh81Xn6Q0vTZbQw==}
|
|
||||||
engines: {node: '>=12'}
|
|
||||||
cpu: [x64]
|
|
||||||
os: [darwin]
|
|
||||||
requiresBuild: true
|
|
||||||
optional: true
|
|
||||||
|
|
||||||
/@esbuild/freebsd-arm64@0.17.19:
|
|
||||||
resolution: {integrity: sha512-pBwbc7DufluUeGdjSU5Si+P3SoMF5DQ/F/UmTSb8HXO80ZEAJmrykPyzo1IfNbAoaqw48YRpv8shwd1NoI0jcQ==}
|
|
||||||
engines: {node: '>=12'}
|
|
||||||
cpu: [arm64]
|
|
||||||
os: [freebsd]
|
|
||||||
requiresBuild: true
|
|
||||||
optional: true
|
|
||||||
|
|
||||||
/@esbuild/freebsd-x64@0.17.19:
|
|
||||||
resolution: {integrity: sha512-4lu+n8Wk0XlajEhbEffdy2xy53dpR06SlzvhGByyg36qJw6Kpfk7cp45DR/62aPH9mtJRmIyrXAS5UWBrJT6TQ==}
|
|
||||||
engines: {node: '>=12'}
|
|
||||||
cpu: [x64]
|
|
||||||
os: [freebsd]
|
|
||||||
requiresBuild: true
|
|
||||||
optional: true
|
|
||||||
|
|
||||||
/@esbuild/linux-arm64@0.17.19:
|
|
||||||
resolution: {integrity: sha512-ct1Tg3WGwd3P+oZYqic+YZF4snNl2bsnMKRkb3ozHmnM0dGWuxcPTTntAF6bOP0Sp4x0PjSF+4uHQ1xvxfRKqg==}
|
|
||||||
engines: {node: '>=12'}
|
|
||||||
cpu: [arm64]
|
|
||||||
os: [linux]
|
|
||||||
requiresBuild: true
|
|
||||||
optional: true
|
|
||||||
|
|
||||||
/@esbuild/linux-arm@0.17.19:
|
|
||||||
resolution: {integrity: sha512-cdmT3KxjlOQ/gZ2cjfrQOtmhG4HJs6hhvm3mWSRDPtZ/lP5oe8FWceS10JaSJC13GBd4eH/haHnqf7hhGNLerA==}
|
|
||||||
engines: {node: '>=12'}
|
|
||||||
cpu: [arm]
|
|
||||||
os: [linux]
|
|
||||||
requiresBuild: true
|
|
||||||
optional: true
|
|
||||||
|
|
||||||
/@esbuild/linux-ia32@0.17.19:
|
|
||||||
resolution: {integrity: sha512-w4IRhSy1VbsNxHRQpeGCHEmibqdTUx61Vc38APcsRbuVgK0OPEnQ0YD39Brymn96mOx48Y2laBQGqgZ0j9w6SQ==}
|
|
||||||
engines: {node: '>=12'}
|
|
||||||
cpu: [ia32]
|
|
||||||
os: [linux]
|
|
||||||
requiresBuild: true
|
|
||||||
optional: true
|
|
||||||
|
|
||||||
/@esbuild/linux-loong64@0.17.19:
|
|
||||||
resolution: {integrity: sha512-2iAngUbBPMq439a+z//gE+9WBldoMp1s5GWsUSgqHLzLJ9WoZLZhpwWuym0u0u/4XmZ3gpHmzV84PonE+9IIdQ==}
|
|
||||||
engines: {node: '>=12'}
|
|
||||||
cpu: [loong64]
|
|
||||||
os: [linux]
|
|
||||||
requiresBuild: true
|
|
||||||
optional: true
|
|
||||||
|
|
||||||
/@esbuild/linux-mips64el@0.17.19:
|
|
||||||
resolution: {integrity: sha512-LKJltc4LVdMKHsrFe4MGNPp0hqDFA1Wpt3jE1gEyM3nKUvOiO//9PheZZHfYRfYl6AwdTH4aTcXSqBerX0ml4A==}
|
|
||||||
engines: {node: '>=12'}
|
|
||||||
cpu: [mips64el]
|
|
||||||
os: [linux]
|
|
||||||
requiresBuild: true
|
|
||||||
optional: true
|
|
||||||
|
|
||||||
/@esbuild/linux-ppc64@0.17.19:
|
|
||||||
resolution: {integrity: sha512-/c/DGybs95WXNS8y3Ti/ytqETiW7EU44MEKuCAcpPto3YjQbyK3IQVKfF6nbghD7EcLUGl0NbiL5Rt5DMhn5tg==}
|
|
||||||
engines: {node: '>=12'}
|
|
||||||
cpu: [ppc64]
|
|
||||||
os: [linux]
|
|
||||||
requiresBuild: true
|
|
||||||
optional: true
|
|
||||||
|
|
||||||
/@esbuild/linux-riscv64@0.17.19:
|
|
||||||
resolution: {integrity: sha512-FC3nUAWhvFoutlhAkgHf8f5HwFWUL6bYdvLc/TTuxKlvLi3+pPzdZiFKSWz/PF30TB1K19SuCxDTI5KcqASJqA==}
|
|
||||||
engines: {node: '>=12'}
|
|
||||||
cpu: [riscv64]
|
|
||||||
os: [linux]
|
|
||||||
requiresBuild: true
|
|
||||||
optional: true
|
|
||||||
|
|
||||||
/@esbuild/linux-s390x@0.17.19:
|
|
||||||
resolution: {integrity: sha512-IbFsFbxMWLuKEbH+7sTkKzL6NJmG2vRyy6K7JJo55w+8xDk7RElYn6xvXtDW8HCfoKBFK69f3pgBJSUSQPr+4Q==}
|
|
||||||
engines: {node: '>=12'}
|
|
||||||
cpu: [s390x]
|
|
||||||
os: [linux]
|
|
||||||
requiresBuild: true
|
|
||||||
optional: true
|
|
||||||
|
|
||||||
/@esbuild/linux-x64@0.17.19:
|
|
||||||
resolution: {integrity: sha512-68ngA9lg2H6zkZcyp22tsVt38mlhWde8l3eJLWkyLrp4HwMUr3c1s/M2t7+kHIhvMjglIBrFpncX1SzMckomGw==}
|
|
||||||
engines: {node: '>=12'}
|
|
||||||
cpu: [x64]
|
|
||||||
os: [linux]
|
|
||||||
requiresBuild: true
|
|
||||||
optional: true
|
|
||||||
|
|
||||||
/@esbuild/netbsd-x64@0.17.19:
|
|
||||||
resolution: {integrity: sha512-CwFq42rXCR8TYIjIfpXCbRX0rp1jo6cPIUPSaWwzbVI4aOfX96OXY8M6KNmtPcg7QjYeDmN+DD0Wp3LaBOLf4Q==}
|
|
||||||
engines: {node: '>=12'}
|
|
||||||
cpu: [x64]
|
|
||||||
os: [netbsd]
|
|
||||||
requiresBuild: true
|
|
||||||
optional: true
|
|
||||||
|
|
||||||
/@esbuild/openbsd-x64@0.17.19:
|
|
||||||
resolution: {integrity: sha512-cnq5brJYrSZ2CF6c35eCmviIN3k3RczmHz8eYaVlNasVqsNY+JKohZU5MKmaOI+KkllCdzOKKdPs762VCPC20g==}
|
|
||||||
engines: {node: '>=12'}
|
|
||||||
cpu: [x64]
|
|
||||||
os: [openbsd]
|
|
||||||
requiresBuild: true
|
|
||||||
optional: true
|
|
||||||
|
|
||||||
/@esbuild/sunos-x64@0.17.19:
|
|
||||||
resolution: {integrity: sha512-vCRT7yP3zX+bKWFeP/zdS6SqdWB8OIpaRq/mbXQxTGHnIxspRtigpkUcDMlSCOejlHowLqII7K2JKevwyRP2rg==}
|
|
||||||
engines: {node: '>=12'}
|
|
||||||
cpu: [x64]
|
|
||||||
os: [sunos]
|
|
||||||
requiresBuild: true
|
|
||||||
optional: true
|
|
||||||
|
|
||||||
/@esbuild/win32-arm64@0.17.19:
|
|
||||||
resolution: {integrity: sha512-yYx+8jwowUstVdorcMdNlzklLYhPxjniHWFKgRqH7IFlUEa0Umu3KuYplf1HUZZ422e3NU9F4LGb+4O0Kdcaag==}
|
|
||||||
engines: {node: '>=12'}
|
|
||||||
cpu: [arm64]
|
|
||||||
os: [win32]
|
|
||||||
requiresBuild: true
|
|
||||||
optional: true
|
|
||||||
|
|
||||||
/@esbuild/win32-ia32@0.17.19:
|
|
||||||
resolution: {integrity: sha512-eggDKanJszUtCdlVs0RB+h35wNlb5v4TWEkq4vZcmVt5u/HiDZrTXe2bWFQUez3RgNHwx/x4sk5++4NSSicKkw==}
|
|
||||||
engines: {node: '>=12'}
|
|
||||||
cpu: [ia32]
|
|
||||||
os: [win32]
|
|
||||||
requiresBuild: true
|
|
||||||
optional: true
|
|
||||||
|
|
||||||
/@esbuild/win32-x64@0.17.19:
|
|
||||||
resolution: {integrity: sha512-lAhycmKnVOuRYNtRtatQR1LPQf2oYCkRGkSFnseDAKPl8lu5SOsK/e1sXe5a0Pc5kHIHe6P2I/ilntNv2xf3cA==}
|
|
||||||
engines: {node: '>=12'}
|
|
||||||
cpu: [x64]
|
|
||||||
os: [win32]
|
|
||||||
requiresBuild: true
|
|
||||||
optional: true
|
|
||||||
|
|
||||||
/@eslint-community/eslint-utils@4.4.0(eslint@8.49.0):
|
/@eslint-community/eslint-utils@4.4.0(eslint@8.49.0):
|
||||||
resolution: {integrity: sha512-1/sA4dwrzBAyeUoQ6oxahHKmrZvsnLCg4RfxW3ZFGGmQkSNQPFNLV9CUEFQP1x9EYXHTo5p6xdhZM1Ne9p/AfA==}
|
resolution: {integrity: sha512-1/sA4dwrzBAyeUoQ6oxahHKmrZvsnLCg4RfxW3ZFGGmQkSNQPFNLV9CUEFQP1x9EYXHTo5p6xdhZM1Ne9p/AfA==}
|
||||||
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
|
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
|
||||||
@@ -2516,7 +2268,7 @@ packages:
|
|||||||
react-refresh: 0.11.0
|
react-refresh: 0.11.0
|
||||||
schema-utils: 3.3.0
|
schema-utils: 3.3.0
|
||||||
source-map: 0.7.4
|
source-map: 0.7.4
|
||||||
webpack: 5.88.2(esbuild@0.17.19)
|
webpack: 5.88.2
|
||||||
webpack-dev-server: 4.15.1(webpack@5.88.2)
|
webpack-dev-server: 4.15.1(webpack@5.88.2)
|
||||||
|
|
||||||
/@popperjs/core@2.11.8:
|
/@popperjs/core@2.11.8:
|
||||||
@@ -3216,11 +2968,6 @@ packages:
|
|||||||
resolution: {integrity: sha512-OPdCF6GsMIP+Az+aWfAAOEt2/+iVDKE7oy6lJ098aoe59oAmK76qV6Gw60SbZ8jHuG2wH058GF4pLFbYamYrVA==}
|
resolution: {integrity: sha512-OPdCF6GsMIP+Az+aWfAAOEt2/+iVDKE7oy6lJ098aoe59oAmK76qV6Gw60SbZ8jHuG2wH058GF4pLFbYamYrVA==}
|
||||||
engines: {node: '>=0.4.0'}
|
engines: {node: '>=0.4.0'}
|
||||||
|
|
||||||
/acorn-walk@8.2.0:
|
|
||||||
resolution: {integrity: sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==}
|
|
||||||
engines: {node: '>=0.4.0'}
|
|
||||||
dev: true
|
|
||||||
|
|
||||||
/acorn@7.4.1:
|
/acorn@7.4.1:
|
||||||
resolution: {integrity: sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==}
|
resolution: {integrity: sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==}
|
||||||
engines: {node: '>=0.4.0'}
|
engines: {node: '>=0.4.0'}
|
||||||
@@ -3437,12 +3184,6 @@ packages:
|
|||||||
is-array-buffer: 3.0.2
|
is-array-buffer: 3.0.2
|
||||||
is-shared-array-buffer: 1.0.2
|
is-shared-array-buffer: 1.0.2
|
||||||
|
|
||||||
/as-table@1.0.55:
|
|
||||||
resolution: {integrity: sha512-xvsWESUJn0JN421Xb9MQw6AsMHRCUknCe0Wjlxvjud80mU4E6hQf1A6NzQKcYNmYw62MfzEtXc+badstZP3JpQ==}
|
|
||||||
dependencies:
|
|
||||||
printable-characters: 1.0.42
|
|
||||||
dev: true
|
|
||||||
|
|
||||||
/asap@2.0.6:
|
/asap@2.0.6:
|
||||||
resolution: {integrity: sha512-BSHWgDSAiKs50o2Re8ppvp3seVHXSRM44cdSsT9FfNEUUZLOGWVCsiWaRPWM1Znn+mqZ1OfVZ3z3DWEzSp7hRA==}
|
resolution: {integrity: sha512-BSHWgDSAiKs50o2Re8ppvp3seVHXSRM44cdSsT9FfNEUUZLOGWVCsiWaRPWM1Znn+mqZ1OfVZ3z3DWEzSp7hRA==}
|
||||||
|
|
||||||
@@ -3522,7 +3263,7 @@ packages:
|
|||||||
loader-utils: 2.0.4
|
loader-utils: 2.0.4
|
||||||
make-dir: 3.1.0
|
make-dir: 3.1.0
|
||||||
schema-utils: 2.7.1
|
schema-utils: 2.7.1
|
||||||
webpack: 5.88.2(esbuild@0.17.19)
|
webpack: 5.88.2
|
||||||
|
|
||||||
/babel-plugin-istanbul@6.1.1:
|
/babel-plugin-istanbul@6.1.1:
|
||||||
resolution: {integrity: sha512-Y1IQok9821cC9onCx5otgFfRm7Lm+I+wwxOx738M/WLPZ9Q42m4IG5W0FNX8WLL2gYMZo3JkuXIH2DOpWM+qwA==}
|
resolution: {integrity: sha512-Y1IQok9821cC9onCx5otgFfRm7Lm+I+wwxOx738M/WLPZ9Q42m4IG5W0FNX8WLL2gYMZo3JkuXIH2DOpWM+qwA==}
|
||||||
@@ -3679,10 +3420,6 @@ packages:
|
|||||||
resolution: {integrity: sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==}
|
resolution: {integrity: sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==}
|
||||||
engines: {node: '>=8'}
|
engines: {node: '>=8'}
|
||||||
|
|
||||||
/blake3-wasm@2.1.5:
|
|
||||||
resolution: {integrity: sha512-F1+K8EbfOZE49dtoPtmxUQrpXaBIl3ICvasLh+nJta0xkz+9kF/7uet9fLnwKqhDrmj6g+6K3Tw9yQPUg2ka5g==}
|
|
||||||
dev: true
|
|
||||||
|
|
||||||
/bluebird@3.7.2:
|
/bluebird@3.7.2:
|
||||||
resolution: {integrity: sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==}
|
resolution: {integrity: sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==}
|
||||||
|
|
||||||
@@ -3758,13 +3495,6 @@ packages:
|
|||||||
resolution: {integrity: sha512-zhaCDicdLuWN5UbN5IMnFqNMhNfo919sH85y2/ea+5Yg9TsTkeZxpL+JLbp6cgYFS4sRLp3YV4S6yDuqVWHYOw==}
|
resolution: {integrity: sha512-zhaCDicdLuWN5UbN5IMnFqNMhNfo919sH85y2/ea+5Yg9TsTkeZxpL+JLbp6cgYFS4sRLp3YV4S6yDuqVWHYOw==}
|
||||||
engines: {node: '>=6'}
|
engines: {node: '>=6'}
|
||||||
|
|
||||||
/busboy@1.6.0:
|
|
||||||
resolution: {integrity: sha512-8SFQbg/0hQ9xy3UNTB0YEnsNBbWfhf7RtnzpL7TkBiTBRfrQ9Fxcnz7VJsleJpyp6rVLvXiuORqjlHi5q+PYuA==}
|
|
||||||
engines: {node: '>=10.16.0'}
|
|
||||||
dependencies:
|
|
||||||
streamsearch: 1.1.0
|
|
||||||
dev: true
|
|
||||||
|
|
||||||
/byte-length@1.0.2:
|
/byte-length@1.0.2:
|
||||||
resolution: {integrity: sha512-ovBpjmsgd/teRmgcPh23d4gJvxDoXtAzEL9xTfMU8Yc2kqCDb7L9jAG0XHl1nzuGl+h3ebCIF1i62UFyA9V/2Q==}
|
resolution: {integrity: sha512-ovBpjmsgd/teRmgcPh23d4gJvxDoXtAzEL9xTfMU8Yc2kqCDb7L9jAG0XHl1nzuGl+h3ebCIF1i62UFyA9V/2Q==}
|
||||||
dev: false
|
dev: false
|
||||||
@@ -3816,15 +3546,6 @@ packages:
|
|||||||
/caniuse-lite@1.0.30001538:
|
/caniuse-lite@1.0.30001538:
|
||||||
resolution: {integrity: sha512-HWJnhnID+0YMtGlzcp3T9drmBJUVDchPJ08tpUGFLs9CYlwWPH2uLgpHn8fND5pCgXVtnGS3H4QR9XLMHVNkHw==}
|
resolution: {integrity: sha512-HWJnhnID+0YMtGlzcp3T9drmBJUVDchPJ08tpUGFLs9CYlwWPH2uLgpHn8fND5pCgXVtnGS3H4QR9XLMHVNkHw==}
|
||||||
|
|
||||||
/capnp-ts@0.7.0:
|
|
||||||
resolution: {integrity: sha512-XKxXAC3HVPv7r674zP0VC3RTXz+/JKhfyw94ljvF80yynK6VkTnqE3jMuN8b3dUVmmc43TjyxjW4KTsmB3c86g==}
|
|
||||||
dependencies:
|
|
||||||
debug: 4.3.4
|
|
||||||
tslib: 2.6.2
|
|
||||||
transitivePeerDependencies:
|
|
||||||
- supports-color
|
|
||||||
dev: true
|
|
||||||
|
|
||||||
/case-sensitive-paths-webpack-plugin@2.4.0:
|
/case-sensitive-paths-webpack-plugin@2.4.0:
|
||||||
resolution: {integrity: sha512-roIFONhcxog0JSSWbvVAh3OocukmSgpqOH6YpMkCvav/ySIV3JKg4Dc8vYtQjYi/UxpNE36r/9v+VqTQqgkYmw==}
|
resolution: {integrity: sha512-roIFONhcxog0JSSWbvVAh3OocukmSgpqOH6YpMkCvav/ySIV3JKg4Dc8vYtQjYi/UxpNE36r/9v+VqTQqgkYmw==}
|
||||||
engines: {node: '>=4'}
|
engines: {node: '>=4'}
|
||||||
@@ -4132,9 +3853,9 @@ packages:
|
|||||||
postcss-modules-values: 4.0.0(postcss@8.4.30)
|
postcss-modules-values: 4.0.0(postcss@8.4.30)
|
||||||
postcss-value-parser: 4.2.0
|
postcss-value-parser: 4.2.0
|
||||||
semver: 7.5.4
|
semver: 7.5.4
|
||||||
webpack: 5.88.2(esbuild@0.17.19)
|
webpack: 5.88.2
|
||||||
|
|
||||||
/css-minimizer-webpack-plugin@3.4.1(esbuild@0.17.19)(webpack@5.88.2):
|
/css-minimizer-webpack-plugin@3.4.1(webpack@5.88.2):
|
||||||
resolution: {integrity: sha512-1u6D71zeIfgngN2XNRJefc/hY7Ybsxd74Jm4qngIXyUEk7fss3VUzuHxLAq/R8NAba4QU9OUSaMZlbpRc7bM4Q==}
|
resolution: {integrity: sha512-1u6D71zeIfgngN2XNRJefc/hY7Ybsxd74Jm4qngIXyUEk7fss3VUzuHxLAq/R8NAba4QU9OUSaMZlbpRc7bM4Q==}
|
||||||
engines: {node: '>= 12.13.0'}
|
engines: {node: '>= 12.13.0'}
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
@@ -4154,13 +3875,12 @@ packages:
|
|||||||
optional: true
|
optional: true
|
||||||
dependencies:
|
dependencies:
|
||||||
cssnano: 5.1.15(postcss@8.4.30)
|
cssnano: 5.1.15(postcss@8.4.30)
|
||||||
esbuild: 0.17.19
|
|
||||||
jest-worker: 27.5.1
|
jest-worker: 27.5.1
|
||||||
postcss: 8.4.30
|
postcss: 8.4.30
|
||||||
schema-utils: 4.2.0
|
schema-utils: 4.2.0
|
||||||
serialize-javascript: 6.0.1
|
serialize-javascript: 6.0.1
|
||||||
source-map: 0.6.1
|
source-map: 0.6.1
|
||||||
webpack: 5.88.2(esbuild@0.17.19)
|
webpack: 5.88.2
|
||||||
|
|
||||||
/css-prefers-color-scheme@6.0.3(postcss@8.4.30):
|
/css-prefers-color-scheme@6.0.3(postcss@8.4.30):
|
||||||
resolution: {integrity: sha512-4BqMbZksRkJQx2zAjrokiGMd07RqOa2IxIrrN10lyBe9xhn9DEvjUK79J6jkeiv9D9hQFXKb6g1jwU62jziJZA==}
|
resolution: {integrity: sha512-4BqMbZksRkJQx2zAjrokiGMd07RqOa2IxIrrN10lyBe9xhn9DEvjUK79J6jkeiv9D9hQFXKb6g1jwU62jziJZA==}
|
||||||
@@ -4302,10 +4022,6 @@ packages:
|
|||||||
/damerau-levenshtein@1.0.8:
|
/damerau-levenshtein@1.0.8:
|
||||||
resolution: {integrity: sha512-sdQSFB7+llfUcQHUQO3+B8ERRj0Oa4w9POWMI/puGtuf7gFywGmkaLCElnudfTiKZV+NvHqL0ifzdrI8Ro7ESA==}
|
resolution: {integrity: sha512-sdQSFB7+llfUcQHUQO3+B8ERRj0Oa4w9POWMI/puGtuf7gFywGmkaLCElnudfTiKZV+NvHqL0ifzdrI8Ro7ESA==}
|
||||||
|
|
||||||
/data-uri-to-buffer@2.0.2:
|
|
||||||
resolution: {integrity: sha512-ND9qDTLc6diwj+Xe5cdAgVTbLVdXbtxTJRXRhli8Mowuaan+0EJOtdqJ0QCHNSSPyoXGx9HX2/VMnKeC34AChA==}
|
|
||||||
dev: true
|
|
||||||
|
|
||||||
/data-uri-to-buffer@4.0.1:
|
/data-uri-to-buffer@4.0.1:
|
||||||
resolution: {integrity: sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==}
|
resolution: {integrity: sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==}
|
||||||
engines: {node: '>= 12'}
|
engines: {node: '>= 12'}
|
||||||
@@ -4697,35 +4413,6 @@ packages:
|
|||||||
is-date-object: 1.0.5
|
is-date-object: 1.0.5
|
||||||
is-symbol: 1.0.4
|
is-symbol: 1.0.4
|
||||||
|
|
||||||
/esbuild@0.17.19:
|
|
||||||
resolution: {integrity: sha512-XQ0jAPFkK/u3LcVRcvVHQcTIqD6E2H1fvZMA5dQPSOWb3suUbWbfbRf94pjc0bNzRYLfIrDRQXr7X+LHIm5oHw==}
|
|
||||||
engines: {node: '>=12'}
|
|
||||||
hasBin: true
|
|
||||||
requiresBuild: true
|
|
||||||
optionalDependencies:
|
|
||||||
'@esbuild/android-arm': 0.17.19
|
|
||||||
'@esbuild/android-arm64': 0.17.19
|
|
||||||
'@esbuild/android-x64': 0.17.19
|
|
||||||
'@esbuild/darwin-arm64': 0.17.19
|
|
||||||
'@esbuild/darwin-x64': 0.17.19
|
|
||||||
'@esbuild/freebsd-arm64': 0.17.19
|
|
||||||
'@esbuild/freebsd-x64': 0.17.19
|
|
||||||
'@esbuild/linux-arm': 0.17.19
|
|
||||||
'@esbuild/linux-arm64': 0.17.19
|
|
||||||
'@esbuild/linux-ia32': 0.17.19
|
|
||||||
'@esbuild/linux-loong64': 0.17.19
|
|
||||||
'@esbuild/linux-mips64el': 0.17.19
|
|
||||||
'@esbuild/linux-ppc64': 0.17.19
|
|
||||||
'@esbuild/linux-riscv64': 0.17.19
|
|
||||||
'@esbuild/linux-s390x': 0.17.19
|
|
||||||
'@esbuild/linux-x64': 0.17.19
|
|
||||||
'@esbuild/netbsd-x64': 0.17.19
|
|
||||||
'@esbuild/openbsd-x64': 0.17.19
|
|
||||||
'@esbuild/sunos-x64': 0.17.19
|
|
||||||
'@esbuild/win32-arm64': 0.17.19
|
|
||||||
'@esbuild/win32-ia32': 0.17.19
|
|
||||||
'@esbuild/win32-x64': 0.17.19
|
|
||||||
|
|
||||||
/escalade@3.1.1:
|
/escalade@3.1.1:
|
||||||
resolution: {integrity: sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==}
|
resolution: {integrity: sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==}
|
||||||
engines: {node: '>=6'}
|
engines: {node: '>=6'}
|
||||||
@@ -5011,7 +4698,7 @@ packages:
|
|||||||
micromatch: 4.0.5
|
micromatch: 4.0.5
|
||||||
normalize-path: 3.0.0
|
normalize-path: 3.0.0
|
||||||
schema-utils: 4.2.0
|
schema-utils: 4.2.0
|
||||||
webpack: 5.88.2(esbuild@0.17.19)
|
webpack: 5.88.2
|
||||||
|
|
||||||
/eslint@8.49.0:
|
/eslint@8.49.0:
|
||||||
resolution: {integrity: sha512-jw03ENfm6VJI0jA9U+8H5zfl5b+FvuU3YYvZRdZHOlU2ggJkxrlkJH4HcDrZpj6YwD8kuYqvQM8LyesoazrSOQ==}
|
resolution: {integrity: sha512-jw03ENfm6VJI0jA9U+8H5zfl5b+FvuU3YYvZRdZHOlU2ggJkxrlkJH4HcDrZpj6YwD8kuYqvQM8LyesoazrSOQ==}
|
||||||
@@ -5096,10 +4783,6 @@ packages:
|
|||||||
resolution: {integrity: sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==}
|
resolution: {integrity: sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==}
|
||||||
engines: {node: '>=4.0'}
|
engines: {node: '>=4.0'}
|
||||||
|
|
||||||
/estree-walker@0.6.1:
|
|
||||||
resolution: {integrity: sha512-SqmZANLWS0mnatqbSfRP5g8OXZC12Fgg1IwNtLsyHDzJizORW4khDfjPqJZsemPWBB2uqykUah5YpQ6epsqC/w==}
|
|
||||||
dev: true
|
|
||||||
|
|
||||||
/estree-walker@1.0.1:
|
/estree-walker@1.0.1:
|
||||||
resolution: {integrity: sha512-1fMXF3YP4pZZVozF8j/ZLfvnR8NSIljt56UhbZ5PeeDmmGHpgpdwQt7ITlGvYaQukCvuBRMLEiKiYC+oeIg4cg==}
|
resolution: {integrity: sha512-1fMXF3YP4pZZVozF8j/ZLfvnR8NSIljt56UhbZ5PeeDmmGHpgpdwQt7ITlGvYaQukCvuBRMLEiKiYC+oeIg4cg==}
|
||||||
|
|
||||||
@@ -5132,11 +4815,6 @@ packages:
|
|||||||
signal-exit: 3.0.7
|
signal-exit: 3.0.7
|
||||||
strip-final-newline: 2.0.0
|
strip-final-newline: 2.0.0
|
||||||
|
|
||||||
/exit-hook@2.2.1:
|
|
||||||
resolution: {integrity: sha512-eNTPlAD67BmP31LDINZ3U7HSF8l57TxOY2PmBJ1shpCvpnxBF93mWCE8YHBnXs8qiUZJc9WDcWIeC3a2HIAMfw==}
|
|
||||||
engines: {node: '>=6'}
|
|
||||||
dev: true
|
|
||||||
|
|
||||||
/exit@0.1.2:
|
/exit@0.1.2:
|
||||||
resolution: {integrity: sha512-Zk/eNKV2zbjpKzrsQ+n1G6poVbErQxJ0LBOJXaKZ1EViLzH+hrLu9cdXI4zw9dBQJslwBEpbQ2P1oS7nDxs6jQ==}
|
resolution: {integrity: sha512-Zk/eNKV2zbjpKzrsQ+n1G6poVbErQxJ0LBOJXaKZ1EViLzH+hrLu9cdXI4zw9dBQJslwBEpbQ2P1oS7nDxs6jQ==}
|
||||||
engines: {node: '>= 0.8.0'}
|
engines: {node: '>= 0.8.0'}
|
||||||
@@ -5258,7 +4936,7 @@ packages:
|
|||||||
dependencies:
|
dependencies:
|
||||||
loader-utils: 2.0.4
|
loader-utils: 2.0.4
|
||||||
schema-utils: 3.3.0
|
schema-utils: 3.3.0
|
||||||
webpack: 5.88.2(esbuild@0.17.19)
|
webpack: 5.88.2
|
||||||
|
|
||||||
/filelist@1.0.4:
|
/filelist@1.0.4:
|
||||||
resolution: {integrity: sha512-w1cEuf3S+DrLCQL7ET6kz+gmlJdbq9J7yXCSjK/OZCPA+qEN1WyF4ZAf0YYJa4/shHJra2t/d/r8SV4Ji+x+8Q==}
|
resolution: {integrity: sha512-w1cEuf3S+DrLCQL7ET6kz+gmlJdbq9J7yXCSjK/OZCPA+qEN1WyF4ZAf0YYJa4/shHJra2t/d/r8SV4Ji+x+8Q==}
|
||||||
@@ -5389,7 +5067,7 @@ packages:
|
|||||||
semver: 7.5.4
|
semver: 7.5.4
|
||||||
tapable: 1.1.3
|
tapable: 1.1.3
|
||||||
typescript: 5.2.2
|
typescript: 5.2.2
|
||||||
webpack: 5.88.2(esbuild@0.17.19)
|
webpack: 5.88.2
|
||||||
|
|
||||||
/form-data@3.0.1:
|
/form-data@3.0.1:
|
||||||
resolution: {integrity: sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==}
|
resolution: {integrity: sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==}
|
||||||
@@ -5487,13 +5165,6 @@ packages:
|
|||||||
resolution: {integrity: sha512-pjzuKtY64GYfWizNAJ0fr9VqttZkNiK2iS430LtIHzjBEr6bX8Am2zm4sW4Ro5wjWW5cAlRL1qAMTcXbjNAO2Q==}
|
resolution: {integrity: sha512-pjzuKtY64GYfWizNAJ0fr9VqttZkNiK2iS430LtIHzjBEr6bX8Am2zm4sW4Ro5wjWW5cAlRL1qAMTcXbjNAO2Q==}
|
||||||
engines: {node: '>=8.0.0'}
|
engines: {node: '>=8.0.0'}
|
||||||
|
|
||||||
/get-source@2.0.12:
|
|
||||||
resolution: {integrity: sha512-X5+4+iD+HoSeEED+uwrQ07BOQr0kEDFMVqqpBuI+RaZBpBpHCuXxo70bjar6f0b0u/DQJsJ7ssurpP0V60Az+w==}
|
|
||||||
dependencies:
|
|
||||||
data-uri-to-buffer: 2.0.2
|
|
||||||
source-map: 0.6.1
|
|
||||||
dev: true
|
|
||||||
|
|
||||||
/get-stream@6.0.1:
|
/get-stream@6.0.1:
|
||||||
resolution: {integrity: sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg==}
|
resolution: {integrity: sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg==}
|
||||||
engines: {node: '>=10'}
|
engines: {node: '>=10'}
|
||||||
@@ -5713,7 +5384,7 @@ packages:
|
|||||||
lodash: 4.17.21
|
lodash: 4.17.21
|
||||||
pretty-error: 4.0.0
|
pretty-error: 4.0.0
|
||||||
tapable: 2.2.1
|
tapable: 2.2.1
|
||||||
webpack: 5.88.2(esbuild@0.17.19)
|
webpack: 5.88.2
|
||||||
|
|
||||||
/htmlparser2@6.1.0:
|
/htmlparser2@6.1.0:
|
||||||
resolution: {integrity: sha512-gyyPk6rgonLFEDGoeRgQNaEUvdJ4ktTmmUh/h2t7s+M8oPpIPxgNACWa+6ESR57kXstwqPiCut0V8NRpcwgU7A==}
|
resolution: {integrity: sha512-gyyPk6rgonLFEDGoeRgQNaEUvdJ4ktTmmUh/h2t7s+M8oPpIPxgNACWa+6ESR57kXstwqPiCut0V8NRpcwgU7A==}
|
||||||
@@ -7257,12 +6928,6 @@ packages:
|
|||||||
engines: {node: '>=4'}
|
engines: {node: '>=4'}
|
||||||
hasBin: true
|
hasBin: true
|
||||||
|
|
||||||
/mime@3.0.0:
|
|
||||||
resolution: {integrity: sha512-jSCU7/VB1loIWBZe14aEYHU/+1UMEHoaO7qxCOVJOw9GgH72VAWppxNcjU+x9a2k3GSIBXNKxXQFqRvvZ7vr3A==}
|
|
||||||
engines: {node: '>=10.0.0'}
|
|
||||||
hasBin: true
|
|
||||||
dev: true
|
|
||||||
|
|
||||||
/mimic-fn@2.1.0:
|
/mimic-fn@2.1.0:
|
||||||
resolution: {integrity: sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==}
|
resolution: {integrity: sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==}
|
||||||
engines: {node: '>=6'}
|
engines: {node: '>=6'}
|
||||||
@@ -7274,29 +6939,7 @@ packages:
|
|||||||
webpack: ^5.0.0
|
webpack: ^5.0.0
|
||||||
dependencies:
|
dependencies:
|
||||||
schema-utils: 4.2.0
|
schema-utils: 4.2.0
|
||||||
webpack: 5.88.2(esbuild@0.17.19)
|
webpack: 5.88.2
|
||||||
|
|
||||||
/miniflare@3.20230918.0:
|
|
||||||
resolution: {integrity: sha512-Dd29HB7ZlT1CXB2tPH8nW6fBOOXi/m7qFZHjKm2jGS+1OaGfrv0PkT5UspWW5jQi8rWI87xtordAUiIJkwWqRw==}
|
|
||||||
engines: {node: '>=16.13'}
|
|
||||||
dependencies:
|
|
||||||
acorn: 8.10.0
|
|
||||||
acorn-walk: 8.2.0
|
|
||||||
capnp-ts: 0.7.0
|
|
||||||
exit-hook: 2.2.1
|
|
||||||
glob-to-regexp: 0.4.1
|
|
||||||
source-map-support: 0.5.21
|
|
||||||
stoppable: 1.1.0
|
|
||||||
undici: 5.25.1
|
|
||||||
workerd: 1.20230904.0
|
|
||||||
ws: 8.14.2
|
|
||||||
youch: 3.3.1
|
|
||||||
zod: 3.22.2
|
|
||||||
transitivePeerDependencies:
|
|
||||||
- bufferutil
|
|
||||||
- supports-color
|
|
||||||
- utf-8-validate
|
|
||||||
dev: true
|
|
||||||
|
|
||||||
/minimalistic-assert@1.0.1:
|
/minimalistic-assert@1.0.1:
|
||||||
resolution: {integrity: sha512-UtJcAD4yEaGtjPezWuO9wC4nwUnVH/8/Im3yEHQP4b67cXlD/Qr9hdITCU1xDbSEXg2XKNaP8jsReV7vQd00/A==}
|
resolution: {integrity: sha512-UtJcAD4yEaGtjPezWuO9wC4nwUnVH/8/Im3yEHQP4b67cXlD/Qr9hdITCU1xDbSEXg2XKNaP8jsReV7vQd00/A==}
|
||||||
@@ -7349,11 +6992,6 @@ packages:
|
|||||||
dns-packet: 5.6.1
|
dns-packet: 5.6.1
|
||||||
thunky: 1.1.0
|
thunky: 1.1.0
|
||||||
|
|
||||||
/mustache@4.2.0:
|
|
||||||
resolution: {integrity: sha512-71ippSywq5Yb7/tVYyGbkBggbU8H3u5Rz56fH60jGFgr8uHwxs+aSKeqmluIVzM0m0kB7xQjKS6qPfd0b2ZoqQ==}
|
|
||||||
hasBin: true
|
|
||||||
dev: true
|
|
||||||
|
|
||||||
/mz@2.7.0:
|
/mz@2.7.0:
|
||||||
resolution: {integrity: sha512-z81GNO7nnYMEhrGh9LeymoE4+Yr0Wn5McHIZMK5cfQCl+NDX08sCZgUc9/6MHni9IWuFLm1Z3HTCXu2z9fN62Q==}
|
resolution: {integrity: sha512-z81GNO7nnYMEhrGh9LeymoE4+Yr0Wn5McHIZMK5cfQCl+NDX08sCZgUc9/6MHni9IWuFLm1Z3HTCXu2z9fN62Q==}
|
||||||
dependencies:
|
dependencies:
|
||||||
@@ -7687,10 +7325,6 @@ packages:
|
|||||||
/path-to-regexp@0.1.7:
|
/path-to-regexp@0.1.7:
|
||||||
resolution: {integrity: sha512-5DFkuoqlv1uYQKxy8omFBeJPQcdoE07Kv2sferDCrAq1ohOU+MSDswDIbnx3YAM60qIOnYa53wBhXW0EbMonrQ==}
|
resolution: {integrity: sha512-5DFkuoqlv1uYQKxy8omFBeJPQcdoE07Kv2sferDCrAq1ohOU+MSDswDIbnx3YAM60qIOnYa53wBhXW0EbMonrQ==}
|
||||||
|
|
||||||
/path-to-regexp@6.2.1:
|
|
||||||
resolution: {integrity: sha512-JLyh7xT1kizaEvcaXOQwOc2/Yhw6KZOvPf1S8401UyLk86CU79LN3vl7ztXGm/pZ+YjoyAJ4rxmHwbkBXJX+yw==}
|
|
||||||
dev: true
|
|
||||||
|
|
||||||
/path-type@4.0.0:
|
/path-type@4.0.0:
|
||||||
resolution: {integrity: sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==}
|
resolution: {integrity: sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==}
|
||||||
engines: {node: '>=8'}
|
engines: {node: '>=8'}
|
||||||
@@ -8026,7 +7660,7 @@ packages:
|
|||||||
klona: 2.0.6
|
klona: 2.0.6
|
||||||
postcss: 8.4.30
|
postcss: 8.4.30
|
||||||
semver: 7.5.4
|
semver: 7.5.4
|
||||||
webpack: 5.88.2(esbuild@0.17.19)
|
webpack: 5.88.2
|
||||||
|
|
||||||
/postcss-logical@5.0.4(postcss@8.4.30):
|
/postcss-logical@5.0.4(postcss@8.4.30):
|
||||||
resolution: {integrity: sha512-RHXxplCeLh9VjinvMrZONq7im4wjWGlRJAqmAVLXyZaXwfDWP73/oq4NdIp+OZwhQUMj0zjqDfM5Fj7qby+B4g==}
|
resolution: {integrity: sha512-RHXxplCeLh9VjinvMrZONq7im4wjWGlRJAqmAVLXyZaXwfDWP73/oq4NdIp+OZwhQUMj0zjqDfM5Fj7qby+B4g==}
|
||||||
@@ -8480,10 +8114,6 @@ packages:
|
|||||||
ansi-styles: 5.2.0
|
ansi-styles: 5.2.0
|
||||||
react-is: 18.2.0
|
react-is: 18.2.0
|
||||||
|
|
||||||
/printable-characters@1.0.42:
|
|
||||||
resolution: {integrity: sha512-dKp+C4iXWK4vVYZmYSd0KBH5F/h1HoZRsbJ82AVKRO3PEo8L4lBS/vLwhVtpwwuYcoIsVY+1JYKR268yn480uQ==}
|
|
||||||
dev: true
|
|
||||||
|
|
||||||
/process-nextick-args@2.0.1:
|
/process-nextick-args@2.0.1:
|
||||||
resolution: {integrity: sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==}
|
resolution: {integrity: sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==}
|
||||||
|
|
||||||
@@ -8589,7 +8219,7 @@ packages:
|
|||||||
peerDependencies:
|
peerDependencies:
|
||||||
react-scripts: '>=2.1.3'
|
react-scripts: '>=2.1.3'
|
||||||
dependencies:
|
dependencies:
|
||||||
react-scripts: 5.0.1(@babel/plugin-syntax-flow@7.22.5)(@babel/plugin-transform-react-jsx@7.22.15)(esbuild@0.17.19)(eslint@8.49.0)(react@18.2.0)(typescript@5.2.2)
|
react-scripts: 5.0.1(@babel/plugin-syntax-flow@7.22.5)(@babel/plugin-transform-react-jsx@7.22.15)(eslint@8.49.0)(react@18.2.0)(typescript@5.2.2)
|
||||||
semver: 5.7.2
|
semver: 5.7.2
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
@@ -8628,7 +8258,7 @@ packages:
|
|||||||
strip-ansi: 6.0.1
|
strip-ansi: 6.0.1
|
||||||
text-table: 0.2.0
|
text-table: 0.2.0
|
||||||
typescript: 5.2.2
|
typescript: 5.2.2
|
||||||
webpack: 5.88.2(esbuild@0.17.19)
|
webpack: 5.88.2
|
||||||
transitivePeerDependencies:
|
transitivePeerDependencies:
|
||||||
- eslint
|
- eslint
|
||||||
- supports-color
|
- supports-color
|
||||||
@@ -8710,7 +8340,7 @@ packages:
|
|||||||
react: 18.2.0
|
react: 18.2.0
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
/react-scripts@5.0.1(@babel/plugin-syntax-flow@7.22.5)(@babel/plugin-transform-react-jsx@7.22.15)(esbuild@0.17.19)(eslint@8.49.0)(react@18.2.0)(typescript@5.2.2):
|
/react-scripts@5.0.1(@babel/plugin-syntax-flow@7.22.5)(@babel/plugin-transform-react-jsx@7.22.15)(eslint@8.49.0)(react@18.2.0)(typescript@5.2.2):
|
||||||
resolution: {integrity: sha512-8VAmEm/ZAwQzJ+GOMLbBsTdDKOpuZh7RPs0UymvBR2vRk4iZWCskjbFnxqjrzoIvlNNRZ3QJFx6/qDSi6zSnaQ==}
|
resolution: {integrity: sha512-8VAmEm/ZAwQzJ+GOMLbBsTdDKOpuZh7RPs0UymvBR2vRk4iZWCskjbFnxqjrzoIvlNNRZ3QJFx6/qDSi6zSnaQ==}
|
||||||
engines: {node: '>=14.0.0'}
|
engines: {node: '>=14.0.0'}
|
||||||
hasBin: true
|
hasBin: true
|
||||||
@@ -8734,7 +8364,7 @@ packages:
|
|||||||
camelcase: 6.3.0
|
camelcase: 6.3.0
|
||||||
case-sensitive-paths-webpack-plugin: 2.4.0
|
case-sensitive-paths-webpack-plugin: 2.4.0
|
||||||
css-loader: 6.8.1(webpack@5.88.2)
|
css-loader: 6.8.1(webpack@5.88.2)
|
||||||
css-minimizer-webpack-plugin: 3.4.1(esbuild@0.17.19)(webpack@5.88.2)
|
css-minimizer-webpack-plugin: 3.4.1(webpack@5.88.2)
|
||||||
dotenv: 10.0.0
|
dotenv: 10.0.0
|
||||||
dotenv-expand: 5.1.0
|
dotenv-expand: 5.1.0
|
||||||
eslint: 8.49.0
|
eslint: 8.49.0
|
||||||
@@ -8765,9 +8395,9 @@ packages:
|
|||||||
source-map-loader: 3.0.2(webpack@5.88.2)
|
source-map-loader: 3.0.2(webpack@5.88.2)
|
||||||
style-loader: 3.3.3(webpack@5.88.2)
|
style-loader: 3.3.3(webpack@5.88.2)
|
||||||
tailwindcss: 3.3.3
|
tailwindcss: 3.3.3
|
||||||
terser-webpack-plugin: 5.3.9(esbuild@0.17.19)(webpack@5.88.2)
|
terser-webpack-plugin: 5.3.9(webpack@5.88.2)
|
||||||
typescript: 5.2.2
|
typescript: 5.2.2
|
||||||
webpack: 5.88.2(esbuild@0.17.19)
|
webpack: 5.88.2
|
||||||
webpack-dev-server: 4.15.1(webpack@5.88.2)
|
webpack-dev-server: 4.15.1(webpack@5.88.2)
|
||||||
webpack-manifest-plugin: 4.1.1(webpack@5.88.2)
|
webpack-manifest-plugin: 4.1.1(webpack@5.88.2)
|
||||||
workbox-webpack-plugin: 6.6.0(webpack@5.88.2)
|
workbox-webpack-plugin: 6.6.0(webpack@5.88.2)
|
||||||
@@ -9030,21 +8660,6 @@ packages:
|
|||||||
dependencies:
|
dependencies:
|
||||||
glob: 7.2.3
|
glob: 7.2.3
|
||||||
|
|
||||||
/rollup-plugin-inject@3.0.2:
|
|
||||||
resolution: {integrity: sha512-ptg9PQwzs3orn4jkgXJ74bfs5vYz1NCZlSQMBUA0wKcGp5i5pA1AO3fOUEte8enhGUC+iapTCzEWw2jEFFUO/w==}
|
|
||||||
deprecated: This package has been deprecated and is no longer maintained. Please use @rollup/plugin-inject.
|
|
||||||
dependencies:
|
|
||||||
estree-walker: 0.6.1
|
|
||||||
magic-string: 0.25.9
|
|
||||||
rollup-pluginutils: 2.8.2
|
|
||||||
dev: true
|
|
||||||
|
|
||||||
/rollup-plugin-node-polyfills@0.2.1:
|
|
||||||
resolution: {integrity: sha512-4kCrKPTJ6sK4/gLL/U5QzVT8cxJcofO0OU74tnB19F40cmuAKSzH5/siithxlofFEjwvw1YAhPmbvGNA6jEroA==}
|
|
||||||
dependencies:
|
|
||||||
rollup-plugin-inject: 3.0.2
|
|
||||||
dev: true
|
|
||||||
|
|
||||||
/rollup-plugin-terser@7.0.2(rollup@2.79.1):
|
/rollup-plugin-terser@7.0.2(rollup@2.79.1):
|
||||||
resolution: {integrity: sha512-w3iIaU4OxcF52UUXiZNsNeuXIMDvFrr+ZXK6bFZ0Q60qyVfq4uLptoS4bbq3paG3x216eQllFZX7zt6TIImguQ==}
|
resolution: {integrity: sha512-w3iIaU4OxcF52UUXiZNsNeuXIMDvFrr+ZXK6bFZ0Q60qyVfq4uLptoS4bbq3paG3x216eQllFZX7zt6TIImguQ==}
|
||||||
deprecated: This package has been deprecated and is no longer maintained. Please use @rollup/plugin-terser
|
deprecated: This package has been deprecated and is no longer maintained. Please use @rollup/plugin-terser
|
||||||
@@ -9057,12 +8672,6 @@ packages:
|
|||||||
serialize-javascript: 4.0.0
|
serialize-javascript: 4.0.0
|
||||||
terser: 5.20.0
|
terser: 5.20.0
|
||||||
|
|
||||||
/rollup-pluginutils@2.8.2:
|
|
||||||
resolution: {integrity: sha512-EEp9NhnUkwY8aif6bxgovPHMoMoNr2FulJziTndpt5H9RdwC47GSGuII9XxpSdzVGM0GWrNPHV6ie1LTNJPaLQ==}
|
|
||||||
dependencies:
|
|
||||||
estree-walker: 0.6.1
|
|
||||||
dev: true
|
|
||||||
|
|
||||||
/rollup@2.79.1:
|
/rollup@2.79.1:
|
||||||
resolution: {integrity: sha512-uKxbd0IhMZOhjAiD5oAFp7BqvkA4Dv47qpOCtaNvng4HBwdbWtdOh8f5nZNuk2rp51PMGk3bzfWu5oayNEuYnw==}
|
resolution: {integrity: sha512-uKxbd0IhMZOhjAiD5oAFp7BqvkA4Dv47qpOCtaNvng4HBwdbWtdOh8f5nZNuk2rp51PMGk3bzfWu5oayNEuYnw==}
|
||||||
engines: {node: '>=10.0.0'}
|
engines: {node: '>=10.0.0'}
|
||||||
@@ -9131,7 +8740,7 @@ packages:
|
|||||||
dependencies:
|
dependencies:
|
||||||
klona: 2.0.6
|
klona: 2.0.6
|
||||||
neo-async: 2.6.2
|
neo-async: 2.6.2
|
||||||
webpack: 5.88.2(esbuild@0.17.19)
|
webpack: 5.88.2
|
||||||
|
|
||||||
/sax@1.2.4:
|
/sax@1.2.4:
|
||||||
resolution: {integrity: sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==}
|
resolution: {integrity: sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==}
|
||||||
@@ -9339,7 +8948,7 @@ packages:
|
|||||||
abab: 2.0.6
|
abab: 2.0.6
|
||||||
iconv-lite: 0.6.3
|
iconv-lite: 0.6.3
|
||||||
source-map-js: 1.0.2
|
source-map-js: 1.0.2
|
||||||
webpack: 5.88.2(esbuild@0.17.19)
|
webpack: 5.88.2
|
||||||
|
|
||||||
/source-map-support@0.5.21:
|
/source-map-support@0.5.21:
|
||||||
resolution: {integrity: sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==}
|
resolution: {integrity: sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==}
|
||||||
@@ -9419,13 +9028,6 @@ packages:
|
|||||||
/stackframe@1.3.4:
|
/stackframe@1.3.4:
|
||||||
resolution: {integrity: sha512-oeVtt7eWQS+Na6F//S4kJ2K2VbRlS9D43mAlMyVpVWovy9o+jfgH8O9agzANzaiLjclA0oYzUXEM4PurhSUChw==}
|
resolution: {integrity: sha512-oeVtt7eWQS+Na6F//S4kJ2K2VbRlS9D43mAlMyVpVWovy9o+jfgH8O9agzANzaiLjclA0oYzUXEM4PurhSUChw==}
|
||||||
|
|
||||||
/stacktracey@2.1.8:
|
|
||||||
resolution: {integrity: sha512-Kpij9riA+UNg7TnphqjH7/CzctQ/owJGNbFkfEeve4Z4uxT5+JapVLFXcsurIfN34gnTWZNJ/f7NMG0E8JDzTw==}
|
|
||||||
dependencies:
|
|
||||||
as-table: 1.0.55
|
|
||||||
get-source: 2.0.12
|
|
||||||
dev: true
|
|
||||||
|
|
||||||
/static-eval@2.0.2:
|
/static-eval@2.0.2:
|
||||||
resolution: {integrity: sha512-N/D219Hcr2bPjLxPiV+TQE++Tsmrady7TqAJugLy7Xk1EumfDWS/f5dtBbkRCGE7wKKXuYockQoj8Rm2/pVKyg==}
|
resolution: {integrity: sha512-N/D219Hcr2bPjLxPiV+TQE++Tsmrady7TqAJugLy7Xk1EumfDWS/f5dtBbkRCGE7wKKXuYockQoj8Rm2/pVKyg==}
|
||||||
dependencies:
|
dependencies:
|
||||||
@@ -9439,16 +9041,6 @@ packages:
|
|||||||
resolution: {integrity: sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==}
|
resolution: {integrity: sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==}
|
||||||
engines: {node: '>= 0.8'}
|
engines: {node: '>= 0.8'}
|
||||||
|
|
||||||
/stoppable@1.1.0:
|
|
||||||
resolution: {integrity: sha512-KXDYZ9dszj6bzvnEMRYvxgeTHU74QBFL54XKtP3nyMuJ81CFYtABZ3bAzL2EdFUaEwJOBOgENyFj3R7oTzDyyw==}
|
|
||||||
engines: {node: '>=4', npm: '>=6'}
|
|
||||||
dev: true
|
|
||||||
|
|
||||||
/streamsearch@1.1.0:
|
|
||||||
resolution: {integrity: sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==}
|
|
||||||
engines: {node: '>=10.0.0'}
|
|
||||||
dev: true
|
|
||||||
|
|
||||||
/string-length@4.0.2:
|
/string-length@4.0.2:
|
||||||
resolution: {integrity: sha512-+l6rNN5fYHNhZZy41RXsYptCjA2Igmq4EG7kZAYFQI1E1VTXarr6ZPXBg6eq7Y6eK4FEhY6AJlyuFIb/v/S0VQ==}
|
resolution: {integrity: sha512-+l6rNN5fYHNhZZy41RXsYptCjA2Igmq4EG7kZAYFQI1E1VTXarr6ZPXBg6eq7Y6eK4FEhY6AJlyuFIb/v/S0VQ==}
|
||||||
engines: {node: '>=10'}
|
engines: {node: '>=10'}
|
||||||
@@ -9569,7 +9161,7 @@ packages:
|
|||||||
peerDependencies:
|
peerDependencies:
|
||||||
webpack: ^5.0.0
|
webpack: ^5.0.0
|
||||||
dependencies:
|
dependencies:
|
||||||
webpack: 5.88.2(esbuild@0.17.19)
|
webpack: 5.88.2
|
||||||
|
|
||||||
/style-to-object@0.4.2:
|
/style-to-object@0.4.2:
|
||||||
resolution: {integrity: sha512-1JGpfPB3lo42ZX8cuPrheZbfQ6kqPPnPHlKMyeRYtfKD+0jG+QsXgXN57O/dvJlzlB2elI6dGmrPnl5VPQFPaA==}
|
resolution: {integrity: sha512-1JGpfPB3lo42ZX8cuPrheZbfQ6kqPPnPHlKMyeRYtfKD+0jG+QsXgXN57O/dvJlzlB2elI6dGmrPnl5VPQFPaA==}
|
||||||
@@ -9730,7 +9322,7 @@ packages:
|
|||||||
ansi-escapes: 4.3.2
|
ansi-escapes: 4.3.2
|
||||||
supports-hyperlinks: 2.3.0
|
supports-hyperlinks: 2.3.0
|
||||||
|
|
||||||
/terser-webpack-plugin@5.3.9(esbuild@0.17.19)(webpack@5.88.2):
|
/terser-webpack-plugin@5.3.9(webpack@5.88.2):
|
||||||
resolution: {integrity: sha512-ZuXsqE07EcggTWQjXUj+Aot/OMcD0bMKGgF63f7UxYcu5/AJF53aIpK1YoP5xR9l6s/Hy2b+t1AM0bLNPRuhwA==}
|
resolution: {integrity: sha512-ZuXsqE07EcggTWQjXUj+Aot/OMcD0bMKGgF63f7UxYcu5/AJF53aIpK1YoP5xR9l6s/Hy2b+t1AM0bLNPRuhwA==}
|
||||||
engines: {node: '>= 10.13.0'}
|
engines: {node: '>= 10.13.0'}
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
@@ -9747,12 +9339,11 @@ packages:
|
|||||||
optional: true
|
optional: true
|
||||||
dependencies:
|
dependencies:
|
||||||
'@jridgewell/trace-mapping': 0.3.19
|
'@jridgewell/trace-mapping': 0.3.19
|
||||||
esbuild: 0.17.19
|
|
||||||
jest-worker: 27.5.1
|
jest-worker: 27.5.1
|
||||||
schema-utils: 3.3.0
|
schema-utils: 3.3.0
|
||||||
serialize-javascript: 6.0.1
|
serialize-javascript: 6.0.1
|
||||||
terser: 5.20.0
|
terser: 5.20.0
|
||||||
webpack: 5.88.2(esbuild@0.17.19)
|
webpack: 5.88.2
|
||||||
|
|
||||||
/terser@5.20.0:
|
/terser@5.20.0:
|
||||||
resolution: {integrity: sha512-e56ETryaQDyebBwJIWYB2TT6f2EZ0fL0sW/JRXNMN26zZdKi2u/E/5my5lG6jNxym6qsrVXfFRmOdV42zlAgLQ==}
|
resolution: {integrity: sha512-e56ETryaQDyebBwJIWYB2TT6f2EZ0fL0sW/JRXNMN26zZdKi2u/E/5my5lG6jNxym6qsrVXfFRmOdV42zlAgLQ==}
|
||||||
@@ -9956,13 +9547,6 @@ packages:
|
|||||||
/underscore@1.12.1:
|
/underscore@1.12.1:
|
||||||
resolution: {integrity: sha512-hEQt0+ZLDVUMhebKxL4x1BTtDY7bavVofhZ9KZ4aI26X9SRaE+Y3m83XUL1UP2jn8ynjndwCCpEHdUG+9pP1Tw==}
|
resolution: {integrity: sha512-hEQt0+ZLDVUMhebKxL4x1BTtDY7bavVofhZ9KZ4aI26X9SRaE+Y3m83XUL1UP2jn8ynjndwCCpEHdUG+9pP1Tw==}
|
||||||
|
|
||||||
/undici@5.25.1:
|
|
||||||
resolution: {integrity: sha512-nTw6b2G2OqP6btYPyghCgV4hSwjJlL/78FMJatVLCa3otj6PCOQSt6dVtYt82OtNqFz8XsnJ+vsXLADPXjPhqw==}
|
|
||||||
engines: {node: '>=14.0'}
|
|
||||||
dependencies:
|
|
||||||
busboy: 1.6.0
|
|
||||||
dev: true
|
|
||||||
|
|
||||||
/unicode-canonical-property-names-ecmascript@2.0.0:
|
/unicode-canonical-property-names-ecmascript@2.0.0:
|
||||||
resolution: {integrity: sha512-yY5PpDlfVIU5+y/BSCxAJRBIS1Zc2dDG3Ujq+sR0U+JjUevW2JhocOF+soROYDSaAezOzOKuyyixhD6mBknSmQ==}
|
resolution: {integrity: sha512-yY5PpDlfVIU5+y/BSCxAJRBIS1Zc2dDG3Ujq+sR0U+JjUevW2JhocOF+soROYDSaAezOzOKuyyixhD6mBknSmQ==}
|
||||||
engines: {node: '>=4'}
|
engines: {node: '>=4'}
|
||||||
@@ -10231,7 +9815,7 @@ packages:
|
|||||||
mime-types: 2.1.35
|
mime-types: 2.1.35
|
||||||
range-parser: 1.2.1
|
range-parser: 1.2.1
|
||||||
schema-utils: 4.2.0
|
schema-utils: 4.2.0
|
||||||
webpack: 5.88.2(esbuild@0.17.19)
|
webpack: 5.88.2
|
||||||
|
|
||||||
/webpack-dev-server@4.15.1(webpack@5.88.2):
|
/webpack-dev-server@4.15.1(webpack@5.88.2):
|
||||||
resolution: {integrity: sha512-5hbAst3h3C3L8w6W4P96L5vaV0PxSmJhxZvWKYIdgxOQm8pNZ5dEOmmSLBVpP85ReeyRt6AS1QJNyo/oFFPeVA==}
|
resolution: {integrity: sha512-5hbAst3h3C3L8w6W4P96L5vaV0PxSmJhxZvWKYIdgxOQm8pNZ5dEOmmSLBVpP85ReeyRt6AS1QJNyo/oFFPeVA==}
|
||||||
@@ -10274,7 +9858,7 @@ packages:
|
|||||||
serve-index: 1.9.1
|
serve-index: 1.9.1
|
||||||
sockjs: 0.3.24
|
sockjs: 0.3.24
|
||||||
spdy: 4.0.2
|
spdy: 4.0.2
|
||||||
webpack: 5.88.2(esbuild@0.17.19)
|
webpack: 5.88.2
|
||||||
webpack-dev-middleware: 5.3.3(webpack@5.88.2)
|
webpack-dev-middleware: 5.3.3(webpack@5.88.2)
|
||||||
ws: 8.14.2
|
ws: 8.14.2
|
||||||
transitivePeerDependencies:
|
transitivePeerDependencies:
|
||||||
@@ -10290,7 +9874,7 @@ packages:
|
|||||||
webpack: ^4.44.2 || ^5.47.0
|
webpack: ^4.44.2 || ^5.47.0
|
||||||
dependencies:
|
dependencies:
|
||||||
tapable: 2.2.1
|
tapable: 2.2.1
|
||||||
webpack: 5.88.2(esbuild@0.17.19)
|
webpack: 5.88.2
|
||||||
webpack-sources: 2.3.1
|
webpack-sources: 2.3.1
|
||||||
|
|
||||||
/webpack-sources@1.4.3:
|
/webpack-sources@1.4.3:
|
||||||
@@ -10310,7 +9894,7 @@ packages:
|
|||||||
resolution: {integrity: sha512-/DyMEOrDgLKKIG0fmvtz+4dUX/3Ghozwgm6iPp8KRhvn+eQf9+Q7GWxVNMk3+uCPWfdXYC4ExGBckIXdFEfH1w==}
|
resolution: {integrity: sha512-/DyMEOrDgLKKIG0fmvtz+4dUX/3Ghozwgm6iPp8KRhvn+eQf9+Q7GWxVNMk3+uCPWfdXYC4ExGBckIXdFEfH1w==}
|
||||||
engines: {node: '>=10.13.0'}
|
engines: {node: '>=10.13.0'}
|
||||||
|
|
||||||
/webpack@5.88.2(esbuild@0.17.19):
|
/webpack@5.88.2:
|
||||||
resolution: {integrity: sha512-JmcgNZ1iKj+aiR0OvTYtWQqJwq37Pf683dY9bVORwVbUrDhLhdn/PlO2sHsFHPkj7sHNQF3JwaAkp49V+Sq1tQ==}
|
resolution: {integrity: sha512-JmcgNZ1iKj+aiR0OvTYtWQqJwq37Pf683dY9bVORwVbUrDhLhdn/PlO2sHsFHPkj7sHNQF3JwaAkp49V+Sq1tQ==}
|
||||||
engines: {node: '>=10.13.0'}
|
engines: {node: '>=10.13.0'}
|
||||||
hasBin: true
|
hasBin: true
|
||||||
@@ -10341,7 +9925,7 @@ packages:
|
|||||||
neo-async: 2.6.2
|
neo-async: 2.6.2
|
||||||
schema-utils: 3.3.0
|
schema-utils: 3.3.0
|
||||||
tapable: 2.2.1
|
tapable: 2.2.1
|
||||||
terser-webpack-plugin: 5.3.9(esbuild@0.17.19)(webpack@5.88.2)
|
terser-webpack-plugin: 5.3.9(webpack@5.88.2)
|
||||||
watchpack: 2.4.0
|
watchpack: 2.4.0
|
||||||
webpack-sources: 3.2.3
|
webpack-sources: 3.2.3
|
||||||
transitivePeerDependencies:
|
transitivePeerDependencies:
|
||||||
@@ -10582,7 +10166,7 @@ packages:
|
|||||||
fast-json-stable-stringify: 2.1.0
|
fast-json-stable-stringify: 2.1.0
|
||||||
pretty-bytes: 5.6.0
|
pretty-bytes: 5.6.0
|
||||||
upath: 1.2.0
|
upath: 1.2.0
|
||||||
webpack: 5.88.2(esbuild@0.17.19)
|
webpack: 5.88.2
|
||||||
webpack-sources: 1.4.3
|
webpack-sources: 1.4.3
|
||||||
workbox-build: 6.6.0
|
workbox-build: 6.6.0
|
||||||
transitivePeerDependencies:
|
transitivePeerDependencies:
|
||||||
@@ -10595,45 +10179,6 @@ packages:
|
|||||||
'@types/trusted-types': 2.0.4
|
'@types/trusted-types': 2.0.4
|
||||||
workbox-core: 6.6.0
|
workbox-core: 6.6.0
|
||||||
|
|
||||||
/workerd@1.20230904.0:
|
|
||||||
resolution: {integrity: sha512-t9znszH0rQGK4mJGvF9L3nN0qKEaObAGx0JkywFtAwH8OkSn+YfQbHNZE+YsJ4qa1hOz1DCNEk08UDFRBaYq4g==}
|
|
||||||
engines: {node: '>=16'}
|
|
||||||
hasBin: true
|
|
||||||
requiresBuild: true
|
|
||||||
optionalDependencies:
|
|
||||||
'@cloudflare/workerd-darwin-64': 1.20230904.0
|
|
||||||
'@cloudflare/workerd-darwin-arm64': 1.20230904.0
|
|
||||||
'@cloudflare/workerd-linux-64': 1.20230904.0
|
|
||||||
'@cloudflare/workerd-linux-arm64': 1.20230904.0
|
|
||||||
'@cloudflare/workerd-windows-64': 1.20230904.0
|
|
||||||
dev: true
|
|
||||||
|
|
||||||
/wrangler@3.9.0:
|
|
||||||
resolution: {integrity: sha512-Ho1A76KxbqfcRgCsuN6xGar3BVPyn4oVWM9zx0HvEVhT9wQ7n/LvB6GlPdXKABqEBYhVe/oTH72S5TgWl0DgaA==}
|
|
||||||
engines: {node: '>=16.13.0'}
|
|
||||||
hasBin: true
|
|
||||||
dependencies:
|
|
||||||
'@cloudflare/kv-asset-handler': 0.2.0
|
|
||||||
'@esbuild-plugins/node-globals-polyfill': 0.2.3(esbuild@0.17.19)
|
|
||||||
'@esbuild-plugins/node-modules-polyfill': 0.2.2(esbuild@0.17.19)
|
|
||||||
blake3-wasm: 2.1.5
|
|
||||||
chokidar: 3.5.3
|
|
||||||
esbuild: 0.17.19
|
|
||||||
miniflare: 3.20230918.0
|
|
||||||
nanoid: 3.3.6
|
|
||||||
path-to-regexp: 6.2.1
|
|
||||||
selfsigned: 2.1.1
|
|
||||||
source-map: 0.6.1
|
|
||||||
source-map-support: 0.5.21
|
|
||||||
xxhash-wasm: 1.0.2
|
|
||||||
optionalDependencies:
|
|
||||||
fsevents: 2.3.3
|
|
||||||
transitivePeerDependencies:
|
|
||||||
- bufferutil
|
|
||||||
- supports-color
|
|
||||||
- utf-8-validate
|
|
||||||
dev: true
|
|
||||||
|
|
||||||
/wrap-ansi@7.0.0:
|
/wrap-ansi@7.0.0:
|
||||||
resolution: {integrity: sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==}
|
resolution: {integrity: sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==}
|
||||||
engines: {node: '>=10'}
|
engines: {node: '>=10'}
|
||||||
@@ -10683,10 +10228,6 @@ packages:
|
|||||||
/xmlchars@2.2.0:
|
/xmlchars@2.2.0:
|
||||||
resolution: {integrity: sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw==}
|
resolution: {integrity: sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw==}
|
||||||
|
|
||||||
/xxhash-wasm@1.0.2:
|
|
||||||
resolution: {integrity: sha512-ibF0Or+FivM9lNrg+HGJfVX8WJqgo+kCLDc4vx6xMeTce7Aj+DLttKbxxRR/gNLSAelRc1omAPlJ77N/Jem07A==}
|
|
||||||
dev: true
|
|
||||||
|
|
||||||
/y18n@5.0.8:
|
/y18n@5.0.8:
|
||||||
resolution: {integrity: sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==}
|
resolution: {integrity: sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==}
|
||||||
engines: {node: '>=10'}
|
engines: {node: '>=10'}
|
||||||
@@ -10724,15 +10265,3 @@ packages:
|
|||||||
/yocto-queue@0.1.0:
|
/yocto-queue@0.1.0:
|
||||||
resolution: {integrity: sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==}
|
resolution: {integrity: sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==}
|
||||||
engines: {node: '>=10'}
|
engines: {node: '>=10'}
|
||||||
|
|
||||||
/youch@3.3.1:
|
|
||||||
resolution: {integrity: sha512-Rg9ioi+AkKyje2Hk4qILSVvayaFW98KTsOJ4aIkjDf97LZX5WJVIHZmFLnM4ThcVofHo/fbbwtYajfBPHFOVtg==}
|
|
||||||
dependencies:
|
|
||||||
cookie: 0.5.0
|
|
||||||
mustache: 4.2.0
|
|
||||||
stacktracey: 2.1.8
|
|
||||||
dev: true
|
|
||||||
|
|
||||||
/zod@3.22.2:
|
|
||||||
resolution: {integrity: sha512-wvWkphh5WQsJbVk1tbx1l1Ly4yg+XecD+Mq280uBGt9wa5BKSWf4Mhp6GmrkPixhMxmabYY7RbzlwVP32pbGCg==}
|
|
||||||
dev: true
|
|
||||||
|
|||||||
@@ -3,15 +3,18 @@
|
|||||||
"message": "KISS Translator"
|
"message": "KISS Translator"
|
||||||
},
|
},
|
||||||
"app_description": {
|
"app_description": {
|
||||||
"message": "A minimalist bilingual translation Extension & Greasemonkey Script"
|
"message": "A simple bilingual translation extension & Greasemonkey script"
|
||||||
},
|
},
|
||||||
"toggle_translate": {
|
"toggle_translate": {
|
||||||
"message": "Toggle Translate"
|
"message": "Toggle Translate (Alt+Q)"
|
||||||
},
|
},
|
||||||
"toggle_style": {
|
"toggle_style": {
|
||||||
"message": "Toggle Style"
|
"message": "Toggle Style (Alt+C)"
|
||||||
},
|
},
|
||||||
"open_options": {
|
"open_options": {
|
||||||
"message": "Open Options"
|
"message": "Open Options (Alt+O)"
|
||||||
|
},
|
||||||
|
"open_tranbox": {
|
||||||
|
"message": "Translate Popup/Selected (Alt+S)"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,15 +3,18 @@
|
|||||||
"message": "简约翻译"
|
"message": "简约翻译"
|
||||||
},
|
},
|
||||||
"app_description": {
|
"app_description": {
|
||||||
"message": "一个简约的网页双语翻译扩展 & 油猴脚本"
|
"message": "一个简约的双语对照翻译扩展 & 油猴脚本"
|
||||||
},
|
},
|
||||||
"toggle_translate": {
|
"toggle_translate": {
|
||||||
"message": "开启翻译"
|
"message": "开启翻译 (Alt+Q)"
|
||||||
},
|
},
|
||||||
"toggle_style": {
|
"toggle_style": {
|
||||||
"message": "切换样式"
|
"message": "切换样式 (Alt+C)"
|
||||||
},
|
},
|
||||||
"open_options": {
|
"open_options": {
|
||||||
"message": "打开设置"
|
"message": "打开设置 (Alt+O)"
|
||||||
|
},
|
||||||
|
"open_tranbox": {
|
||||||
|
"message": "翻译弹窗/选中文字 (Alt+S)"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
"manifest_version": 2,
|
"manifest_version": 2,
|
||||||
"name": "__MSG_app_name__",
|
"name": "__MSG_app_name__",
|
||||||
"description": "__MSG_app_description__",
|
"description": "__MSG_app_description__",
|
||||||
"version": "1.7.5",
|
"version": "1.7.15",
|
||||||
"default_locale": "en",
|
"default_locale": "en",
|
||||||
"author": "Gabe<yugang2002@gmail.com>",
|
"author": "Gabe<yugang2002@gmail.com>",
|
||||||
"homepage_url": "https://github.com/fishjar/kiss-translator",
|
"homepage_url": "https://github.com/fishjar/kiss-translator",
|
||||||
@@ -41,7 +41,7 @@
|
|||||||
"description": "__MSG_open_options__"
|
"description": "__MSG_open_options__"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"permissions": ["<all_urls>", "storage"],
|
"permissions": ["<all_urls>", "storage", "contextMenus"],
|
||||||
"icons": {
|
"icons": {
|
||||||
"16": "images/logo16.png",
|
"16": "images/logo16.png",
|
||||||
"32": "images/logo32.png",
|
"32": "images/logo32.png",
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
"manifest_version": 3,
|
"manifest_version": 3,
|
||||||
"name": "__MSG_app_name__",
|
"name": "__MSG_app_name__",
|
||||||
"description": "__MSG_app_description__",
|
"description": "__MSG_app_description__",
|
||||||
"version": "1.7.5",
|
"version": "1.7.15",
|
||||||
"default_locale": "en",
|
"default_locale": "en",
|
||||||
"author": "Gabe<yugang2002@gmail.com>",
|
"author": "Gabe<yugang2002@gmail.com>",
|
||||||
"homepage_url": "https://github.com/fishjar/kiss-translator",
|
"homepage_url": "https://github.com/fishjar/kiss-translator",
|
||||||
@@ -42,7 +42,7 @@
|
|||||||
"description": "__MSG_open_options__"
|
"description": "__MSG_open_options__"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"permissions": ["storage"],
|
"permissions": ["storage", "contextMenus"],
|
||||||
"host_permissions": ["<all_urls>"],
|
"host_permissions": ["<all_urls>"],
|
||||||
"icons": {
|
"icons": {
|
||||||
"16": "images/logo16.png",
|
"16": "images/logo16.png",
|
||||||
|
|||||||
230
src/apis/baidu.js
Normal file
230
src/apis/baidu.js
Normal file
@@ -0,0 +1,230 @@
|
|||||||
|
import queryString from "query-string";
|
||||||
|
import { getBdauth, setBdauth } from "../libs/storage";
|
||||||
|
import { URL_BAIDU_WEB, URL_BAIDU_TRAN } from "../config";
|
||||||
|
import { fetchApi } from "../libs/fetch";
|
||||||
|
|
||||||
|
/* eslint-disable */
|
||||||
|
function n(t, e) {
|
||||||
|
for (var n = 0; n < e.length - 2; n += 3) {
|
||||||
|
var r = e.charAt(n + 2);
|
||||||
|
(r = "a" <= r ? r.charCodeAt(0) - 87 : Number(r)),
|
||||||
|
(r = "+" === e.charAt(n + 1) ? t >>> r : t << r),
|
||||||
|
(t = "+" === e.charAt(n) ? (t + r) & 4294967295 : t ^ r);
|
||||||
|
}
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
function e(t, e) {
|
||||||
|
(null == e || e > t.length) && (e = t.length);
|
||||||
|
for (var n = 0, r = new Array(e); n < e; n++) r[n] = t[n];
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* eslint-disable */
|
||||||
|
function getSign(t, gtk, r = null) {
|
||||||
|
var o,
|
||||||
|
i = t.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g);
|
||||||
|
if (null === i) {
|
||||||
|
var a = t.length;
|
||||||
|
a > 30 &&
|
||||||
|
(t = ""
|
||||||
|
.concat(t.substr(0, 10))
|
||||||
|
.concat(t.substr(Math.floor(a / 2) - 5, 10))
|
||||||
|
.concat(t.substr(-10, 10)));
|
||||||
|
} else {
|
||||||
|
for (
|
||||||
|
var s = t.split(/[\uD800-\uDBFF][\uDC00-\uDFFF]/),
|
||||||
|
c = 0,
|
||||||
|
u = s.length,
|
||||||
|
l = [];
|
||||||
|
c < u;
|
||||||
|
c++
|
||||||
|
)
|
||||||
|
"" !== s[c] &&
|
||||||
|
l.push.apply(
|
||||||
|
l,
|
||||||
|
(function (t) {
|
||||||
|
if (Array.isArray(t)) return e(t);
|
||||||
|
})((o = s[c].split(""))) ||
|
||||||
|
(function (t) {
|
||||||
|
if (
|
||||||
|
("undefined" != typeof Symbol && null != t[Symbol.iterator]) ||
|
||||||
|
null != t["@@iterator"]
|
||||||
|
)
|
||||||
|
return Array.from(t);
|
||||||
|
})(o) ||
|
||||||
|
(function (t, n) {
|
||||||
|
if (t) {
|
||||||
|
if ("string" == typeof t) return e(t, n);
|
||||||
|
var r = Object.prototype.toString.call(t).slice(8, -1);
|
||||||
|
return (
|
||||||
|
"Object" === r && t.constructor && (r = t.constructor.name),
|
||||||
|
"Map" === r || "Set" === r
|
||||||
|
? Array.from(t)
|
||||||
|
: "Arguments" === r ||
|
||||||
|
/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)
|
||||||
|
? e(t, n)
|
||||||
|
: void 0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
})(o) ||
|
||||||
|
(function () {
|
||||||
|
throw new TypeError(
|
||||||
|
"Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."
|
||||||
|
);
|
||||||
|
})()
|
||||||
|
),
|
||||||
|
c !== u - 1 && l.push(i[c]);
|
||||||
|
var p = l.length;
|
||||||
|
p > 30 &&
|
||||||
|
(t =
|
||||||
|
l.slice(0, 10).join("") +
|
||||||
|
l.slice(Math.floor(p / 2) - 5, Math.floor(p / 2) + 5).join("") +
|
||||||
|
l.slice(-10).join(""));
|
||||||
|
}
|
||||||
|
for (
|
||||||
|
var d = ""
|
||||||
|
.concat(String.fromCharCode(103))
|
||||||
|
.concat(String.fromCharCode(116))
|
||||||
|
.concat(String.fromCharCode(107)),
|
||||||
|
h = (null !== r ? r : (r = gtk || "") || "").split("."),
|
||||||
|
f = Number(h[0]) || 0,
|
||||||
|
m = Number(h[1]) || 0,
|
||||||
|
g = [],
|
||||||
|
y = 0,
|
||||||
|
v = 0;
|
||||||
|
v < t.length;
|
||||||
|
v++
|
||||||
|
) {
|
||||||
|
var _ = t.charCodeAt(v);
|
||||||
|
_ < 128
|
||||||
|
? (g[y++] = _)
|
||||||
|
: (_ < 2048
|
||||||
|
? (g[y++] = (_ >> 6) | 192)
|
||||||
|
: (55296 == (64512 & _) &&
|
||||||
|
v + 1 < t.length &&
|
||||||
|
56320 == (64512 & t.charCodeAt(v + 1))
|
||||||
|
? ((_ = 65536 + ((1023 & _) << 10) + (1023 & t.charCodeAt(++v))),
|
||||||
|
(g[y++] = (_ >> 18) | 240),
|
||||||
|
(g[y++] = ((_ >> 12) & 63) | 128))
|
||||||
|
: (g[y++] = (_ >> 12) | 224),
|
||||||
|
(g[y++] = ((_ >> 6) & 63) | 128)),
|
||||||
|
(g[y++] = (63 & _) | 128));
|
||||||
|
}
|
||||||
|
for (
|
||||||
|
var b = f,
|
||||||
|
w =
|
||||||
|
""
|
||||||
|
.concat(String.fromCharCode(43))
|
||||||
|
.concat(String.fromCharCode(45))
|
||||||
|
.concat(String.fromCharCode(97)) +
|
||||||
|
""
|
||||||
|
.concat(String.fromCharCode(94))
|
||||||
|
.concat(String.fromCharCode(43))
|
||||||
|
.concat(String.fromCharCode(54)),
|
||||||
|
k =
|
||||||
|
""
|
||||||
|
.concat(String.fromCharCode(43))
|
||||||
|
.concat(String.fromCharCode(45))
|
||||||
|
.concat(String.fromCharCode(51)) +
|
||||||
|
""
|
||||||
|
.concat(String.fromCharCode(94))
|
||||||
|
.concat(String.fromCharCode(43))
|
||||||
|
.concat(String.fromCharCode(98)) +
|
||||||
|
""
|
||||||
|
.concat(String.fromCharCode(43))
|
||||||
|
.concat(String.fromCharCode(45))
|
||||||
|
.concat(String.fromCharCode(102)),
|
||||||
|
x = 0;
|
||||||
|
x < g.length;
|
||||||
|
x++
|
||||||
|
)
|
||||||
|
b = n((b += g[x]), w);
|
||||||
|
return (
|
||||||
|
(b = n(b, k)),
|
||||||
|
(b ^= m) < 0 && (b = 2147483648 + (2147483647 & b)),
|
||||||
|
"".concat((b %= 1e6).toString(), ".").concat(b ^ f)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const getToken = async () => {
|
||||||
|
const res = await fetchApi({
|
||||||
|
input: URL_BAIDU_WEB,
|
||||||
|
init: {
|
||||||
|
headers: {
|
||||||
|
"Content-type": "text/html; charset=utf-8",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!res.ok) {
|
||||||
|
throw new Error(res.statusText);
|
||||||
|
}
|
||||||
|
|
||||||
|
const text = await res.text();
|
||||||
|
const token = text.match(/token: '(.*)',/)[1];
|
||||||
|
const gtk = text.match(/gtk = "(.*)";/)[1];
|
||||||
|
const exp = Date.now() + 8 * 60 * 60 * 1000;
|
||||||
|
|
||||||
|
if (!token || !gtk) {
|
||||||
|
throw new Error("[baidu] get token error");
|
||||||
|
}
|
||||||
|
|
||||||
|
return { token, gtk, exp };
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 闭包缓存token,减少对storage查询
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
const _bdAuth = () => {
|
||||||
|
let store;
|
||||||
|
|
||||||
|
return async () => {
|
||||||
|
const now = Date.now();
|
||||||
|
|
||||||
|
// 查询内存缓存
|
||||||
|
if (store && store.exp > now) {
|
||||||
|
return store;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查询storage缓存
|
||||||
|
store = await getBdauth();
|
||||||
|
if (store && store.exp > now) {
|
||||||
|
return store;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 缓存没有或失效,查询接口
|
||||||
|
store = await getToken();
|
||||||
|
await setBdauth(store);
|
||||||
|
return store;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const bdAuth = _bdAuth();
|
||||||
|
|
||||||
|
export const genBaidu = async ({ text, from, to }) => {
|
||||||
|
const { token, gtk } = await bdAuth();
|
||||||
|
const sign = getSign(text, gtk);
|
||||||
|
const data = {
|
||||||
|
from,
|
||||||
|
to,
|
||||||
|
query: text,
|
||||||
|
simple_means_flag: 3,
|
||||||
|
sign,
|
||||||
|
token,
|
||||||
|
domain: "common",
|
||||||
|
ts: Date.now(),
|
||||||
|
};
|
||||||
|
|
||||||
|
const input = `${URL_BAIDU_TRAN}?from=${from}&to=${to}`;
|
||||||
|
const init = {
|
||||||
|
headers: {
|
||||||
|
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
|
||||||
|
},
|
||||||
|
method: "POST",
|
||||||
|
body: queryString.stringify(data),
|
||||||
|
};
|
||||||
|
|
||||||
|
return [input, init];
|
||||||
|
};
|
||||||
58
src/apis/deepl.js
Normal file
58
src/apis/deepl.js
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
import { URL_DEEPLFREE_TRAN } from "../config";
|
||||||
|
|
||||||
|
let id = 1e4 * Math.round(1e4 * Math.random());
|
||||||
|
|
||||||
|
export const genDeeplFree = ({ text, from, to }) => {
|
||||||
|
const iCount = (text.match(/[i]/g) || []).length + 1;
|
||||||
|
let timestamp = Date.now();
|
||||||
|
timestamp = timestamp + (iCount - (timestamp % iCount));
|
||||||
|
id++;
|
||||||
|
|
||||||
|
let body = JSON.stringify({
|
||||||
|
jsonrpc: "2.0",
|
||||||
|
method: "LMT_handle_texts",
|
||||||
|
params: {
|
||||||
|
splitting: "newlines",
|
||||||
|
lang: {
|
||||||
|
target_lang: to,
|
||||||
|
source_lang_user_selected: from,
|
||||||
|
},
|
||||||
|
commonJobParams: {
|
||||||
|
wasSpoken: false,
|
||||||
|
transcribe_as: "",
|
||||||
|
},
|
||||||
|
id,
|
||||||
|
timestamp,
|
||||||
|
texts: [
|
||||||
|
{
|
||||||
|
text,
|
||||||
|
requestAlternatives: 3,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
body = body.replace(
|
||||||
|
'method":"',
|
||||||
|
(id + 3) % 13 === 0 || (id + 5) % 29 === 0 ? 'method" : "' : 'method": "'
|
||||||
|
);
|
||||||
|
|
||||||
|
const init = {
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Accept: "*/*",
|
||||||
|
"x-app-os-name": "iOS",
|
||||||
|
"x-app-os-version": "16.3.0",
|
||||||
|
"Accept-Language": "en-US,en;q=0.9",
|
||||||
|
"Accept-Encoding": "gzip, deflate, br",
|
||||||
|
"x-app-device": "iPhone13,2",
|
||||||
|
"User-Agent": "DeepL-iOS/2.9.1 iOS 16.3.0 (iPhone13,2)",
|
||||||
|
"x-app-build": "510265",
|
||||||
|
"x-app-version": "2.9.1",
|
||||||
|
},
|
||||||
|
method: "POST",
|
||||||
|
body,
|
||||||
|
};
|
||||||
|
|
||||||
|
return [URL_DEEPLFREE_TRAN, init];
|
||||||
|
};
|
||||||
@@ -4,14 +4,22 @@ import {
|
|||||||
OPT_TRANS_GOOGLE,
|
OPT_TRANS_GOOGLE,
|
||||||
OPT_TRANS_MICROSOFT,
|
OPT_TRANS_MICROSOFT,
|
||||||
OPT_TRANS_DEEPL,
|
OPT_TRANS_DEEPL,
|
||||||
|
OPT_TRANS_DEEPLFREE,
|
||||||
|
OPT_TRANS_DEEPLX,
|
||||||
|
OPT_TRANS_BAIDU,
|
||||||
|
OPT_TRANS_TENCENT,
|
||||||
OPT_TRANS_OPENAI,
|
OPT_TRANS_OPENAI,
|
||||||
|
OPT_TRANS_GEMINI,
|
||||||
|
OPT_TRANS_CLOUDFLAREAI,
|
||||||
OPT_TRANS_CUSTOMIZE,
|
OPT_TRANS_CUSTOMIZE,
|
||||||
OPT_LANGS_SPECIAL,
|
URL_CACHE_TRAN,
|
||||||
PROMPT_PLACE_FROM,
|
|
||||||
PROMPT_PLACE_TO,
|
|
||||||
KV_SALT_SYNC,
|
KV_SALT_SYNC,
|
||||||
|
URL_BAIDU_LANGDETECT,
|
||||||
|
OPT_LANGS_BAIDU,
|
||||||
|
URL_TENCENT_TRANSMART,
|
||||||
|
OPT_LANGS_TENCENT,
|
||||||
|
OPT_LANGS_SPECIAL,
|
||||||
} from "../config";
|
} from "../config";
|
||||||
import { tryDetectLang } from "../libs";
|
|
||||||
import { sha256 } from "../libs/utils";
|
import { sha256 } from "../libs/utils";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -39,202 +47,52 @@ export const apiSyncData = async (url, key, data) =>
|
|||||||
export const apiFetch = (url) => fetchPolyfill(url);
|
export const apiFetch = (url) => fetchPolyfill(url);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 谷歌翻译
|
* 百度语言识别
|
||||||
* @param {*} text
|
* @param {*} text
|
||||||
* @param {*} to
|
|
||||||
* @param {*} from
|
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
const apiGoogleTranslate = async (
|
export const apiBaiduLangdetect = async (text) => {
|
||||||
translator,
|
const res = await fetchPolyfill(URL_BAIDU_LANGDETECT, {
|
||||||
text,
|
|
||||||
to,
|
|
||||||
from,
|
|
||||||
{ url, key, useCache = true }
|
|
||||||
) => {
|
|
||||||
const params = {
|
|
||||||
client: "gtx",
|
|
||||||
dt: "t",
|
|
||||||
dj: 1,
|
|
||||||
ie: "UTF-8",
|
|
||||||
sl: from,
|
|
||||||
tl: to,
|
|
||||||
q: text,
|
|
||||||
};
|
|
||||||
const input = `${url}?${queryString.stringify(params)}`;
|
|
||||||
const res = await fetchPolyfill(input, {
|
|
||||||
headers: {
|
|
||||||
"Content-type": "application/json",
|
|
||||||
},
|
|
||||||
useCache,
|
|
||||||
usePool: true,
|
|
||||||
translator,
|
|
||||||
token: key,
|
|
||||||
});
|
|
||||||
const trText = res.sentences.map((item) => item.trans).join(" ");
|
|
||||||
const isSame = to === res.src;
|
|
||||||
|
|
||||||
return [trText, isSame];
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 微软翻译
|
|
||||||
* @param {*} text
|
|
||||||
* @param {*} to
|
|
||||||
* @param {*} from
|
|
||||||
* @returns
|
|
||||||
*/
|
|
||||||
const apiMicrosoftTranslate = async (
|
|
||||||
translator,
|
|
||||||
text,
|
|
||||||
to,
|
|
||||||
from,
|
|
||||||
{ url, useCache = true }
|
|
||||||
) => {
|
|
||||||
const params = {
|
|
||||||
from,
|
|
||||||
to,
|
|
||||||
"api-version": "3.0",
|
|
||||||
};
|
|
||||||
const input = `${url}?${queryString.stringify(params)}`;
|
|
||||||
const res = await fetchPolyfill(input, {
|
|
||||||
headers: {
|
headers: {
|
||||||
"Content-type": "application/json",
|
"Content-type": "application/json",
|
||||||
},
|
},
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: JSON.stringify([{ Text: text }]),
|
body: JSON.stringify({
|
||||||
useCache,
|
query: text,
|
||||||
usePool: true,
|
}),
|
||||||
translator,
|
useCache: true,
|
||||||
});
|
});
|
||||||
const trText = res[0].translations[0].text;
|
|
||||||
const isSame = to === res[0].detectedLanguage?.language;
|
|
||||||
|
|
||||||
return [trText, isSame];
|
if (res.error === 0) {
|
||||||
};
|
return OPT_LANGS_BAIDU.get(res.lan) ?? res.lan;
|
||||||
|
|
||||||
/**
|
|
||||||
* DeepL翻译
|
|
||||||
* @param {*} text
|
|
||||||
* @param {*} to
|
|
||||||
* @param {*} from
|
|
||||||
* @returns
|
|
||||||
*/
|
|
||||||
const apiDeepLTranslate = async (
|
|
||||||
translator,
|
|
||||||
text,
|
|
||||||
to,
|
|
||||||
from,
|
|
||||||
{ url, key, useCache = true }
|
|
||||||
) => {
|
|
||||||
const data = {
|
|
||||||
text: [text],
|
|
||||||
target_lang: to,
|
|
||||||
split_sentences: "0",
|
|
||||||
};
|
|
||||||
if (from) {
|
|
||||||
data.source_lang = from;
|
|
||||||
}
|
}
|
||||||
const res = await fetchPolyfill(url, {
|
|
||||||
headers: {
|
|
||||||
"Content-type": "application/json",
|
|
||||||
},
|
|
||||||
method: "POST",
|
|
||||||
body: JSON.stringify(data),
|
|
||||||
useCache,
|
|
||||||
usePool: true,
|
|
||||||
translator,
|
|
||||||
token: key,
|
|
||||||
});
|
|
||||||
const trText = res.translations.map((item) => item.text).join(" ");
|
|
||||||
const isSame = to === res.translations[0].detected_source_language;
|
|
||||||
|
|
||||||
return [trText, isSame];
|
return "";
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OpenAI 翻译
|
* 腾讯语言识别
|
||||||
* @param {*} text
|
* @param {*} text
|
||||||
* @param {*} to
|
|
||||||
* @param {*} from
|
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
const apiOpenaiTranslate = async (
|
export const apiTencentLangdetect = async (text) => {
|
||||||
translator,
|
const body = JSON.stringify({
|
||||||
text,
|
header: {
|
||||||
to,
|
fn: "text_analysis",
|
||||||
from,
|
},
|
||||||
{ url, key, model, prompt, useCache = true }
|
text,
|
||||||
) => {
|
});
|
||||||
prompt = prompt
|
|
||||||
.replaceAll(PROMPT_PLACE_FROM, from)
|
const res = await fetchPolyfill(URL_TENCENT_TRANSMART, {
|
||||||
.replaceAll(PROMPT_PLACE_TO, to);
|
|
||||||
const res = await fetchPolyfill(url, {
|
|
||||||
headers: {
|
headers: {
|
||||||
"Content-type": "application/json",
|
"Content-type": "application/json",
|
||||||
},
|
},
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: JSON.stringify({
|
body,
|
||||||
model: model,
|
useCache: true,
|
||||||
messages: [
|
|
||||||
{
|
|
||||||
role: "system",
|
|
||||||
content: prompt,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
role: "user",
|
|
||||||
content: text,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
temperature: 0,
|
|
||||||
max_tokens: 256,
|
|
||||||
}),
|
|
||||||
useCache,
|
|
||||||
usePool: true,
|
|
||||||
translator,
|
|
||||||
token: key,
|
|
||||||
});
|
});
|
||||||
const trText = res?.choices?.[0].message.content;
|
|
||||||
const sLang = await tryDetectLang(text);
|
|
||||||
const tLang = await tryDetectLang(trText);
|
|
||||||
const isSame = text === trText || (sLang && tLang && sLang === tLang);
|
|
||||||
|
|
||||||
return [trText, isSame];
|
return OPT_LANGS_TENCENT.get(res.language) ?? res.language;
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 自定义接口 翻译
|
|
||||||
* @param {*} text
|
|
||||||
* @param {*} to
|
|
||||||
* @param {*} from
|
|
||||||
* @returns
|
|
||||||
*/
|
|
||||||
const apiCustomTranslate = async (
|
|
||||||
translator,
|
|
||||||
text,
|
|
||||||
to,
|
|
||||||
from,
|
|
||||||
{ url, key, useCache = true }
|
|
||||||
) => {
|
|
||||||
const res = await fetchPolyfill(url, {
|
|
||||||
headers: {
|
|
||||||
"Content-type": "application/json",
|
|
||||||
},
|
|
||||||
method: "POST",
|
|
||||||
body: JSON.stringify({
|
|
||||||
text,
|
|
||||||
from,
|
|
||||||
to,
|
|
||||||
}),
|
|
||||||
useCache,
|
|
||||||
usePool: true,
|
|
||||||
translator,
|
|
||||||
token: key,
|
|
||||||
});
|
|
||||||
const trText = res.text;
|
|
||||||
const isSame = to === res.from;
|
|
||||||
|
|
||||||
return [trText, isSame];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -242,29 +100,102 @@ const apiCustomTranslate = async (
|
|||||||
* @param {*} param0
|
* @param {*} param0
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export const apiTranslate = ({
|
export const apiTranslate = async ({
|
||||||
translator,
|
translator,
|
||||||
text,
|
text,
|
||||||
fromLang,
|
fromLang,
|
||||||
toLang,
|
toLang,
|
||||||
apiSetting,
|
apiSetting = {},
|
||||||
|
useCache = true,
|
||||||
|
usePool = true,
|
||||||
}) => {
|
}) => {
|
||||||
const from = OPT_LANGS_SPECIAL[translator]?.get(fromLang) ?? fromLang;
|
let trText = "";
|
||||||
const to = OPT_LANGS_SPECIAL[translator]?.get(toLang) ?? toLang;
|
let isSame = false;
|
||||||
const callApi = (api) => api(translator, text, to, from, apiSetting);
|
|
||||||
|
if (!text) {
|
||||||
|
return [trText, true];
|
||||||
|
}
|
||||||
|
|
||||||
|
const from =
|
||||||
|
OPT_LANGS_SPECIAL[translator].get(fromLang) ??
|
||||||
|
OPT_LANGS_SPECIAL[translator].get("auto");
|
||||||
|
const to = OPT_LANGS_SPECIAL[translator].get(toLang);
|
||||||
|
if (!to) {
|
||||||
|
console.log(`[trans] target lang: ${toLang} not support`);
|
||||||
|
return [trText, isSame];
|
||||||
|
}
|
||||||
|
|
||||||
|
const cacheOpts = {
|
||||||
|
translator,
|
||||||
|
text,
|
||||||
|
fromLang,
|
||||||
|
toLang,
|
||||||
|
};
|
||||||
|
|
||||||
|
const transOpts = {
|
||||||
|
translator,
|
||||||
|
text,
|
||||||
|
from,
|
||||||
|
to,
|
||||||
|
};
|
||||||
|
|
||||||
|
const res = await fetchPolyfill(
|
||||||
|
`${URL_CACHE_TRAN}?${queryString.stringify(cacheOpts)}`,
|
||||||
|
{
|
||||||
|
useCache,
|
||||||
|
usePool,
|
||||||
|
transOpts,
|
||||||
|
apiSetting,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
switch (translator) {
|
switch (translator) {
|
||||||
case OPT_TRANS_GOOGLE:
|
case OPT_TRANS_GOOGLE:
|
||||||
return callApi(apiGoogleTranslate);
|
trText = res.sentences.map((item) => item.trans).join(" ");
|
||||||
|
isSame = to === res.src;
|
||||||
|
break;
|
||||||
case OPT_TRANS_MICROSOFT:
|
case OPT_TRANS_MICROSOFT:
|
||||||
return callApi(apiMicrosoftTranslate);
|
trText = res[0].translations.map((item) => item.text).join(" ");
|
||||||
|
isSame = text === trText;
|
||||||
|
break;
|
||||||
case OPT_TRANS_DEEPL:
|
case OPT_TRANS_DEEPL:
|
||||||
return callApi(apiDeepLTranslate);
|
trText = res.translations.map((item) => item.text).join(" ");
|
||||||
|
isSame = to === res.translations[0].detected_source_language;
|
||||||
|
break;
|
||||||
|
case OPT_TRANS_DEEPLFREE:
|
||||||
|
trText = res.result?.texts.map((item) => item.text).join(" ");
|
||||||
|
isSame = to === res.result?.lang;
|
||||||
|
break;
|
||||||
|
case OPT_TRANS_DEEPLX:
|
||||||
|
trText = res.data;
|
||||||
|
isSame = to === res.source_lang;
|
||||||
|
break;
|
||||||
|
case OPT_TRANS_BAIDU:
|
||||||
|
trText = res.trans_result?.data.map((item) => item.dst).join(" ");
|
||||||
|
isSame = res.trans_result?.to === res.trans_result?.from;
|
||||||
|
break;
|
||||||
|
case OPT_TRANS_TENCENT:
|
||||||
|
trText = res.auto_translation;
|
||||||
|
isSame = text === trText;
|
||||||
|
break;
|
||||||
case OPT_TRANS_OPENAI:
|
case OPT_TRANS_OPENAI:
|
||||||
return callApi(apiOpenaiTranslate);
|
trText = res?.choices?.[0].message.content;
|
||||||
|
isSame = text === trText;
|
||||||
|
break;
|
||||||
|
case OPT_TRANS_GEMINI:
|
||||||
|
trText = res?.candidates?.[0].content.parts[0].text;
|
||||||
|
isSame = text === trText;
|
||||||
|
break;
|
||||||
|
case OPT_TRANS_CLOUDFLAREAI:
|
||||||
|
trText = res?.result?.translated_text;
|
||||||
|
isSame = text === trText;
|
||||||
|
break;
|
||||||
case OPT_TRANS_CUSTOMIZE:
|
case OPT_TRANS_CUSTOMIZE:
|
||||||
return callApi(apiCustomTranslate);
|
trText = res.text;
|
||||||
|
isSame = to === res.from;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return ["", false];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return [trText, isSame, res];
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,9 +7,12 @@ import {
|
|||||||
MSG_OPEN_OPTIONS,
|
MSG_OPEN_OPTIONS,
|
||||||
MSG_SAVE_RULE,
|
MSG_SAVE_RULE,
|
||||||
MSG_TRANS_TOGGLE_STYLE,
|
MSG_TRANS_TOGGLE_STYLE,
|
||||||
|
MSG_OPEN_TRANBOX,
|
||||||
|
MSG_CONTEXT_MENUS,
|
||||||
CMD_TOGGLE_TRANSLATE,
|
CMD_TOGGLE_TRANSLATE,
|
||||||
CMD_TOGGLE_STYLE,
|
CMD_TOGGLE_STYLE,
|
||||||
CMD_OPEN_OPTIONS,
|
CMD_OPEN_OPTIONS,
|
||||||
|
CMD_OPEN_TRANBOX,
|
||||||
} from "./config";
|
} from "./config";
|
||||||
import { getSettingWithDefault, tryInitDefaultData } from "./libs/storage";
|
import { getSettingWithDefault, tryInitDefaultData } from "./libs/storage";
|
||||||
import { trySyncSettingAndRules } from "./libs/sync";
|
import { trySyncSettingAndRules } from "./libs/sync";
|
||||||
@@ -21,30 +24,79 @@ import { saveRule } from "./libs/rules";
|
|||||||
|
|
||||||
globalThis.ContextType = "BACKGROUND";
|
globalThis.ContextType = "BACKGROUND";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加右键菜单
|
||||||
|
*/
|
||||||
|
function addContextMenus() {
|
||||||
|
browser.contextMenus.create({
|
||||||
|
id: CMD_TOGGLE_TRANSLATE,
|
||||||
|
title: browser.i18n.getMessage("toggle_translate"),
|
||||||
|
contexts: ["all"],
|
||||||
|
});
|
||||||
|
browser.contextMenus.create({
|
||||||
|
id: CMD_TOGGLE_STYLE,
|
||||||
|
title: browser.i18n.getMessage("toggle_style"),
|
||||||
|
contexts: ["all"],
|
||||||
|
});
|
||||||
|
browser.contextMenus.create({
|
||||||
|
id: CMD_OPEN_TRANBOX,
|
||||||
|
title: browser.i18n.getMessage("open_tranbox"),
|
||||||
|
contexts: ["all"],
|
||||||
|
});
|
||||||
|
browser.contextMenus.create({
|
||||||
|
id: "options_separator",
|
||||||
|
type: "separator",
|
||||||
|
contexts: ["all"],
|
||||||
|
});
|
||||||
|
browser.contextMenus.create({
|
||||||
|
id: CMD_OPEN_OPTIONS,
|
||||||
|
title: browser.i18n.getMessage("open_options"),
|
||||||
|
contexts: ["all"],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清除右键菜单
|
||||||
|
*/
|
||||||
|
function removeContextMenus() {
|
||||||
|
browser.contextMenus.removeAll();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 插件安装
|
* 插件安装
|
||||||
*/
|
*/
|
||||||
browser.runtime.onInstalled.addListener(() => {
|
browser.runtime.onInstalled.addListener(() => {
|
||||||
tryInitDefaultData();
|
tryInitDefaultData();
|
||||||
|
|
||||||
|
// 右键菜单
|
||||||
|
addContextMenus();
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 浏览器启动
|
* 浏览器启动
|
||||||
*/
|
*/
|
||||||
browser.runtime.onStartup.addListener(async () => {
|
browser.runtime.onStartup.addListener(async () => {
|
||||||
console.log("browser onStartup");
|
|
||||||
|
|
||||||
// 同步数据
|
// 同步数据
|
||||||
await trySyncSettingAndRules();
|
await trySyncSettingAndRules();
|
||||||
|
|
||||||
|
const {
|
||||||
|
clearCache,
|
||||||
|
contextMenus = true,
|
||||||
|
subrulesList,
|
||||||
|
} = await getSettingWithDefault();
|
||||||
|
|
||||||
// 清除缓存
|
// 清除缓存
|
||||||
const setting = await getSettingWithDefault();
|
if (clearCache) {
|
||||||
if (setting.clearCache) {
|
|
||||||
tryClearCaches();
|
tryClearCaches();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 右键菜单
|
||||||
|
if (!contextMenus) {
|
||||||
|
removeContextMenus();
|
||||||
|
}
|
||||||
|
|
||||||
// 同步订阅规则
|
// 同步订阅规则
|
||||||
trySyncAllSubRules(setting);
|
trySyncAllSubRules({ subrulesList });
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -60,7 +112,7 @@ browser.runtime.onMessage.addListener(
|
|||||||
sendResponse({ data });
|
sendResponse({ data });
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
sendResponse({ error: error.message });
|
sendResponse({ error: error.message, cause: error.cause });
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case MSG_FETCH_LIMIT:
|
case MSG_FETCH_LIMIT:
|
||||||
@@ -78,6 +130,14 @@ browser.runtime.onMessage.addListener(
|
|||||||
case MSG_SAVE_RULE:
|
case MSG_SAVE_RULE:
|
||||||
saveRule(args);
|
saveRule(args);
|
||||||
break;
|
break;
|
||||||
|
case MSG_CONTEXT_MENUS:
|
||||||
|
const { contextMenus } = args;
|
||||||
|
if (contextMenus) {
|
||||||
|
addContextMenus();
|
||||||
|
} else {
|
||||||
|
removeContextMenus();
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
sendResponse({ error: `message action is unavailable: ${action}` });
|
sendResponse({ error: `message action is unavailable: ${action}` });
|
||||||
}
|
}
|
||||||
@@ -103,3 +163,24 @@ browser.commands.onCommand.addListener((command) => {
|
|||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 监听右键菜单
|
||||||
|
*/
|
||||||
|
browser.contextMenus.onClicked.addListener(({ menuItemId }) => {
|
||||||
|
switch (menuItemId) {
|
||||||
|
case CMD_TOGGLE_TRANSLATE:
|
||||||
|
sendTabMsg(MSG_TRANS_TOGGLE);
|
||||||
|
break;
|
||||||
|
case CMD_TOGGLE_STYLE:
|
||||||
|
sendTabMsg(MSG_TRANS_TOGGLE_STYLE);
|
||||||
|
break;
|
||||||
|
case CMD_OPEN_TRANBOX:
|
||||||
|
sendTabMsg(MSG_OPEN_TRANBOX);
|
||||||
|
break;
|
||||||
|
case CMD_OPEN_OPTIONS:
|
||||||
|
browser.runtime.openOptionsPage();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|||||||
287
src/common.js
Normal file
287
src/common.js
Normal file
@@ -0,0 +1,287 @@
|
|||||||
|
import React from "react";
|
||||||
|
import ReactDOM from "react-dom/client";
|
||||||
|
import Action from "./views/Action";
|
||||||
|
import createCache from "@emotion/cache";
|
||||||
|
import { CacheProvider } from "@emotion/react";
|
||||||
|
import {
|
||||||
|
MSG_TRANS_TOGGLE,
|
||||||
|
MSG_TRANS_TOGGLE_STYLE,
|
||||||
|
MSG_TRANS_GETRULE,
|
||||||
|
MSG_TRANS_PUTRULE,
|
||||||
|
MSG_OPEN_TRANBOX,
|
||||||
|
APP_LCNAME,
|
||||||
|
DEFAULT_TRANBOX_SETTING,
|
||||||
|
} from "./config";
|
||||||
|
import { getFabWithDefault, getSettingWithDefault } from "./libs/storage";
|
||||||
|
import { Translator } from "./libs/translator";
|
||||||
|
import { isIframe, sendIframeMsg, sendParentMsg } from "./libs/iframe";
|
||||||
|
import Slection from "./views/Selection";
|
||||||
|
import { touchTapListener } from "./libs/touch";
|
||||||
|
import { debounce, genEventName } from "./libs/utils";
|
||||||
|
import { handlePing, injectScript } from "./libs/gm";
|
||||||
|
import { browser } from "./libs/browser";
|
||||||
|
import { runWebfix } from "./libs/webfix";
|
||||||
|
import { matchRule } from "./libs/rules";
|
||||||
|
import { trySyncAllSubRules } from "./libs/subRules";
|
||||||
|
import { isInBlacklist } from "./libs/blacklist";
|
||||||
|
import inputTranslate from "./libs/inputTranslate";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 油猴脚本设置页面
|
||||||
|
*/
|
||||||
|
function runSettingPage() {
|
||||||
|
if (GM?.info?.script?.grant?.includes("unsafeWindow")) {
|
||||||
|
unsafeWindow.GM = GM;
|
||||||
|
unsafeWindow.APP_INFO = {
|
||||||
|
name: process.env.REACT_APP_NAME,
|
||||||
|
version: process.env.REACT_APP_VERSION,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
const ping = genEventName();
|
||||||
|
window.addEventListener(ping, handlePing);
|
||||||
|
// window.eval(`(${injectScript})("${ping}")`); // eslint-disable-line
|
||||||
|
const script = document.createElement("script");
|
||||||
|
script.textContent = `(${injectScript})("${ping}")`;
|
||||||
|
document.head.append(script);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 插件监听后端事件
|
||||||
|
* @param {*} translator
|
||||||
|
*/
|
||||||
|
function runtimeListener(translator) {
|
||||||
|
browser?.runtime.onMessage.addListener(async ({ action, args }) => {
|
||||||
|
switch (action) {
|
||||||
|
case MSG_TRANS_TOGGLE:
|
||||||
|
translator.toggle();
|
||||||
|
sendIframeMsg(MSG_TRANS_TOGGLE);
|
||||||
|
break;
|
||||||
|
case MSG_TRANS_TOGGLE_STYLE:
|
||||||
|
translator.toggleStyle();
|
||||||
|
sendIframeMsg(MSG_TRANS_TOGGLE_STYLE);
|
||||||
|
break;
|
||||||
|
case MSG_TRANS_GETRULE:
|
||||||
|
break;
|
||||||
|
case MSG_TRANS_PUTRULE:
|
||||||
|
translator.updateRule(args);
|
||||||
|
sendIframeMsg(MSG_TRANS_PUTRULE, args);
|
||||||
|
break;
|
||||||
|
case MSG_OPEN_TRANBOX:
|
||||||
|
window.dispatchEvent(new CustomEvent(MSG_OPEN_TRANBOX));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return { error: `message action is unavailable: ${action}` };
|
||||||
|
}
|
||||||
|
return { data: translator.rule };
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* iframe 页面执行
|
||||||
|
* @param {*} setting
|
||||||
|
*/
|
||||||
|
function runIframe(setting) {
|
||||||
|
let translator;
|
||||||
|
window.addEventListener("message", (e) => {
|
||||||
|
const { action, args } = e.data || {};
|
||||||
|
switch (action) {
|
||||||
|
case MSG_TRANS_TOGGLE:
|
||||||
|
translator?.toggle();
|
||||||
|
break;
|
||||||
|
case MSG_TRANS_TOGGLE_STYLE:
|
||||||
|
translator?.toggleStyle();
|
||||||
|
break;
|
||||||
|
case MSG_TRANS_PUTRULE:
|
||||||
|
if (!translator) {
|
||||||
|
translator = new Translator(args, setting);
|
||||||
|
} else {
|
||||||
|
translator.updateRule(args || {});
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
});
|
||||||
|
sendParentMsg(MSG_TRANS_GETRULE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 悬浮按钮
|
||||||
|
* @param {*} translator
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
async function showFab(translator) {
|
||||||
|
const fab = await getFabWithDefault();
|
||||||
|
if (fab.isHide) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const $action = document.createElement("div");
|
||||||
|
$action.setAttribute("id", APP_LCNAME);
|
||||||
|
document.body.parentElement.appendChild($action);
|
||||||
|
const shadowContainer = $action.attachShadow({ mode: "closed" });
|
||||||
|
const emotionRoot = document.createElement("style");
|
||||||
|
const shadowRootElement = document.createElement("div");
|
||||||
|
shadowContainer.appendChild(emotionRoot);
|
||||||
|
shadowContainer.appendChild(shadowRootElement);
|
||||||
|
const cache = createCache({
|
||||||
|
key: APP_LCNAME,
|
||||||
|
prepend: true,
|
||||||
|
container: emotionRoot,
|
||||||
|
});
|
||||||
|
ReactDOM.createRoot(shadowRootElement).render(
|
||||||
|
<React.StrictMode>
|
||||||
|
<CacheProvider value={cache}>
|
||||||
|
<Action translator={translator} fab={fab} />
|
||||||
|
</CacheProvider>
|
||||||
|
</React.StrictMode>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 划词翻译
|
||||||
|
* @param {*} param0
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
function showTransbox({
|
||||||
|
contextMenus = true,
|
||||||
|
tranboxSetting = DEFAULT_TRANBOX_SETTING,
|
||||||
|
transApis,
|
||||||
|
}) {
|
||||||
|
if (!tranboxSetting?.transOpen) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const $tranbox = document.createElement("div");
|
||||||
|
$tranbox.setAttribute("id", "kiss-transbox");
|
||||||
|
document.body.parentElement.appendChild($tranbox);
|
||||||
|
const shadowContainer = $tranbox.attachShadow({ mode: "closed" });
|
||||||
|
const emotionRoot = document.createElement("style");
|
||||||
|
const shadowRootElement = document.createElement("div");
|
||||||
|
shadowContainer.appendChild(emotionRoot);
|
||||||
|
shadowContainer.appendChild(shadowRootElement);
|
||||||
|
const cache = createCache({
|
||||||
|
key: "kiss-transbox",
|
||||||
|
prepend: true,
|
||||||
|
container: emotionRoot,
|
||||||
|
});
|
||||||
|
ReactDOM.createRoot(shadowRootElement).render(
|
||||||
|
<React.StrictMode>
|
||||||
|
<CacheProvider value={cache}>
|
||||||
|
<Slection
|
||||||
|
contextMenus={contextMenus}
|
||||||
|
tranboxSetting={tranboxSetting}
|
||||||
|
transApis={transApis}
|
||||||
|
/>
|
||||||
|
</CacheProvider>
|
||||||
|
</React.StrictMode>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 监听来自iframe页面消息
|
||||||
|
* @param {*} rule
|
||||||
|
*/
|
||||||
|
function windowListener(rule) {
|
||||||
|
window.addEventListener("message", (e) => {
|
||||||
|
const { action } = e.data || {};
|
||||||
|
switch (action) {
|
||||||
|
case MSG_TRANS_GETRULE:
|
||||||
|
sendIframeMsg(MSG_TRANS_PUTRULE, rule);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 显示错误信息到页面顶部
|
||||||
|
* @param {*} message
|
||||||
|
*/
|
||||||
|
function showErr(message) {
|
||||||
|
const $err = document.createElement("div");
|
||||||
|
$err.innerText = `KISS-Translator: ${message}`;
|
||||||
|
$err.style.cssText = "background:red; color:#fff;";
|
||||||
|
document.body.prepend($err);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 监听触屏操作
|
||||||
|
* @param {*} translator
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
function touchOperation(translator) {
|
||||||
|
const { touchTranslate = 2 } = translator.setting;
|
||||||
|
if (touchTranslate === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleTap = debounce(() => {
|
||||||
|
translator.toggle();
|
||||||
|
sendIframeMsg(MSG_TRANS_TOGGLE);
|
||||||
|
});
|
||||||
|
touchTapListener(handleTap, touchTranslate);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 入口函数
|
||||||
|
*/
|
||||||
|
export async function run(isUserscript = false) {
|
||||||
|
try {
|
||||||
|
const href = document.location.href;
|
||||||
|
|
||||||
|
// 设置页面
|
||||||
|
if (
|
||||||
|
isUserscript &&
|
||||||
|
(href.includes(process.env.REACT_APP_OPTIONSPAGE_DEV) ||
|
||||||
|
href.includes(process.env.REACT_APP_OPTIONSPAGE) ||
|
||||||
|
href.includes(process.env.REACT_APP_OPTIONSPAGE2))
|
||||||
|
) {
|
||||||
|
runSettingPage();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 读取设置信息
|
||||||
|
const setting = await getSettingWithDefault();
|
||||||
|
|
||||||
|
// 黑名单
|
||||||
|
if (isInBlacklist(href, setting)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 适配iframe
|
||||||
|
if (isIframe) {
|
||||||
|
runIframe(setting);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 不规范网页修复
|
||||||
|
await runWebfix(setting);
|
||||||
|
|
||||||
|
// 翻译网页
|
||||||
|
const rule = await matchRule(href, setting);
|
||||||
|
const translator = new Translator(rule, setting);
|
||||||
|
|
||||||
|
// 监听消息
|
||||||
|
windowListener(rule);
|
||||||
|
!isUserscript && runtimeListener(translator);
|
||||||
|
|
||||||
|
// 输入框翻译
|
||||||
|
inputTranslate(setting);
|
||||||
|
|
||||||
|
// 划词翻译
|
||||||
|
showTransbox(setting);
|
||||||
|
|
||||||
|
// 浮球按钮
|
||||||
|
await showFab(translator);
|
||||||
|
|
||||||
|
// 触屏操作
|
||||||
|
touchOperation(translator);
|
||||||
|
|
||||||
|
// 同步订阅规则
|
||||||
|
isUserscript && (await trySyncAllSubRules(setting));
|
||||||
|
} catch (err) {
|
||||||
|
console.error("[KISS-Translator]", err);
|
||||||
|
showErr(err.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -215,6 +215,14 @@ export const I18N = {
|
|||||||
zh: `目标语言`,
|
zh: `目标语言`,
|
||||||
en: `Target Language`,
|
en: `Target Language`,
|
||||||
},
|
},
|
||||||
|
to_lang2: {
|
||||||
|
zh: `第二目标语言`,
|
||||||
|
en: `Target Language 2`,
|
||||||
|
},
|
||||||
|
to_lang2_helper: {
|
||||||
|
zh: `设定后,与目标语言产生互译效果,但依赖远程语言识别。`,
|
||||||
|
en: `After setting, it will produce mutual translation effect with the target language, but it relies on remote language recognition.`,
|
||||||
|
},
|
||||||
text_style: {
|
text_style: {
|
||||||
zh: `文字样式`,
|
zh: `文字样式`,
|
||||||
en: `Text Style`,
|
en: `Text Style`,
|
||||||
@@ -335,6 +343,10 @@ export const I18N = {
|
|||||||
zh: `高亮`,
|
zh: `高亮`,
|
||||||
en: `Highlight`,
|
en: `Highlight`,
|
||||||
},
|
},
|
||||||
|
blockquote: {
|
||||||
|
zh: `引用`,
|
||||||
|
en: `Blockquote`,
|
||||||
|
},
|
||||||
diy_style: {
|
diy_style: {
|
||||||
zh: `自定义样式`,
|
zh: `自定义样式`,
|
||||||
en: `Custom Style`,
|
en: `Custom Style`,
|
||||||
@@ -352,8 +364,8 @@ export const I18N = {
|
|||||||
en: `URL pattern`,
|
en: `URL pattern`,
|
||||||
},
|
},
|
||||||
pattern_helper: {
|
pattern_helper: {
|
||||||
zh: `1、支持星号(*)通配符。2、多个URL支持英文逗号“,”分隔。`,
|
zh: `1、支持星号(*)通配符。2、多个URL用英文逗号“,”分隔。`,
|
||||||
en: `1. The asterisk (*) wildcard is supported. 2. Multiple URLs can be separated by English commas ",".`,
|
en: `1. The asterisk (*) wildcard is supported. 2. Multiple URLs separated by English commas ",".`,
|
||||||
},
|
},
|
||||||
selector_helper: {
|
selector_helper: {
|
||||||
zh: `1、遵循CSS选择器语法。2、留空表示采用全局设置。3、多个CSS选择器之间用“;”隔开。4、“shadow root”选择器和内部选择器用“>>>”隔开。`,
|
zh: `1、遵循CSS选择器语法。2、留空表示采用全局设置。3、多个CSS选择器之间用“;”隔开。4、“shadow root”选择器和内部选择器用“>>>”隔开。`,
|
||||||
@@ -375,6 +387,14 @@ export const I18N = {
|
|||||||
zh: `选择器`,
|
zh: `选择器`,
|
||||||
en: `Selector`,
|
en: `Selector`,
|
||||||
},
|
},
|
||||||
|
root_selector: {
|
||||||
|
zh: `根选择器`,
|
||||||
|
en: `Root Selector`,
|
||||||
|
},
|
||||||
|
fixer_function: {
|
||||||
|
zh: `修复函数`,
|
||||||
|
en: `Fixer Function`,
|
||||||
|
},
|
||||||
import: {
|
import: {
|
||||||
zh: `导入`,
|
zh: `导入`,
|
||||||
en: `Import`,
|
en: `Import`,
|
||||||
@@ -539,6 +559,10 @@ export const I18N = {
|
|||||||
zh: `隐藏悬浮按钮`,
|
zh: `隐藏悬浮按钮`,
|
||||||
en: `Hide Fab Button`,
|
en: `Hide Fab Button`,
|
||||||
},
|
},
|
||||||
|
hide_tran_button: {
|
||||||
|
zh: `隐藏翻译按钮`,
|
||||||
|
en: `Hide Translate Button`,
|
||||||
|
},
|
||||||
show: {
|
show: {
|
||||||
zh: `显示`,
|
zh: `显示`,
|
||||||
en: `Show`,
|
en: `Show`,
|
||||||
@@ -555,11 +579,11 @@ export const I18N = {
|
|||||||
zh: `全局规则`,
|
zh: `全局规则`,
|
||||||
en: `Global Rule`,
|
en: `Global Rule`,
|
||||||
},
|
},
|
||||||
input_setting: {
|
input_translate: {
|
||||||
zh: `输入框设置`,
|
zh: `输入框翻译`,
|
||||||
en: `Input Box Setting`,
|
en: `Input Box Translation`,
|
||||||
},
|
},
|
||||||
input_box_translation: {
|
use_input_box_translation: {
|
||||||
zh: `启用输入框翻译`,
|
zh: `启用输入框翻译`,
|
||||||
en: `Input Box Translation`,
|
en: `Input Box Translation`,
|
||||||
},
|
},
|
||||||
@@ -595,4 +619,92 @@ export const I18N = {
|
|||||||
zh: `标识后面可以加目标语言代码,如: “/en 你好”、“/zh hello”`,
|
zh: `标识后面可以加目标语言代码,如: “/en 你好”、“/zh hello”`,
|
||||||
en: `The target language code can be added after the sign, such as: "/en 你好", "/zh hello"`,
|
en: `The target language code can be added after the sign, such as: "/en 你好", "/zh hello"`,
|
||||||
},
|
},
|
||||||
|
detect_lang_remote: {
|
||||||
|
zh: `远程语言检测`,
|
||||||
|
en: `Remote language detection`,
|
||||||
|
},
|
||||||
|
detect_lang_remote_help: {
|
||||||
|
zh: `启用后检测准确度增加,但会降低翻译速度,请酌情开启`,
|
||||||
|
en: `After enabling, the detection accuracy will increase, but it will reduce the translation speed. Please enable it as appropriate.`,
|
||||||
|
},
|
||||||
|
disable: {
|
||||||
|
zh: `禁用`,
|
||||||
|
en: `Disable`,
|
||||||
|
},
|
||||||
|
enable: {
|
||||||
|
zh: `启用`,
|
||||||
|
en: `Enable`,
|
||||||
|
},
|
||||||
|
selection_translate: {
|
||||||
|
zh: `划词翻译`,
|
||||||
|
en: `Selection Translate`,
|
||||||
|
},
|
||||||
|
toggle_selection_translate: {
|
||||||
|
zh: `启用划词翻译`,
|
||||||
|
en: `Use Selection Translate`,
|
||||||
|
},
|
||||||
|
trigger_tranbox_shortcut: {
|
||||||
|
zh: `显示翻译框/翻译选中文字快捷键`,
|
||||||
|
en: `Open Translate Popup/Translate Selected Shortcut`,
|
||||||
|
},
|
||||||
|
tranbtn_offset_x: {
|
||||||
|
zh: `翻译按钮偏移X(0-100)`,
|
||||||
|
en: `Translate Button Offset X (0-100)`,
|
||||||
|
},
|
||||||
|
tranbtn_offset_y: {
|
||||||
|
zh: `翻译按钮偏移Y(0-100)`,
|
||||||
|
en: `Translate Button Offset Y (0-100)`,
|
||||||
|
},
|
||||||
|
translated_text: {
|
||||||
|
zh: `译文`,
|
||||||
|
en: `Translated Text`,
|
||||||
|
},
|
||||||
|
original_text: {
|
||||||
|
zh: `原文`,
|
||||||
|
en: `Original Text`,
|
||||||
|
},
|
||||||
|
favorite_words: {
|
||||||
|
zh: `收藏词汇`,
|
||||||
|
en: `Favorite Words`,
|
||||||
|
},
|
||||||
|
touch_setting: {
|
||||||
|
zh: `触屏设置`,
|
||||||
|
en: `Touch Setting`,
|
||||||
|
},
|
||||||
|
touch_translate_shortcut: {
|
||||||
|
zh: `触屏翻译快捷方式`,
|
||||||
|
en: `Touch Translate Shortcut`,
|
||||||
|
},
|
||||||
|
touch_tap_0: {
|
||||||
|
zh: `禁用`,
|
||||||
|
en: `Disable`,
|
||||||
|
},
|
||||||
|
touch_tap_2: {
|
||||||
|
zh: `双指轻触`,
|
||||||
|
en: `Two finger tap`,
|
||||||
|
},
|
||||||
|
touch_tap_3: {
|
||||||
|
zh: `三指轻触`,
|
||||||
|
en: `Three finger tap`,
|
||||||
|
},
|
||||||
|
touch_tap_4: {
|
||||||
|
zh: `四指轻触`,
|
||||||
|
en: `Four finger tap`,
|
||||||
|
},
|
||||||
|
translate_blacklist: {
|
||||||
|
zh: `禁用翻译名单`,
|
||||||
|
en: `Translate Blacklist`,
|
||||||
|
},
|
||||||
|
disable_langs: {
|
||||||
|
zh: `不翻译的语言`,
|
||||||
|
en: `Disable Languages`,
|
||||||
|
},
|
||||||
|
disable_langs_helper: {
|
||||||
|
zh: `此功能依赖准确的语言检测,建议启用远程语言检测。`,
|
||||||
|
en: `This feature relies on accurate language detection. It is recommended to enable remote language detection.`,
|
||||||
|
},
|
||||||
|
add_context_menus: {
|
||||||
|
zh: `添加右键菜单`,
|
||||||
|
en: `Add Context Menus`,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -20,8 +20,11 @@ export {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const STOKEY_MSAUTH = `${APP_NAME}_msauth`;
|
export const STOKEY_MSAUTH = `${APP_NAME}_msauth`;
|
||||||
|
export const STOKEY_BDAUTH = `${APP_NAME}_bdauth`;
|
||||||
export const STOKEY_SETTING = `${APP_NAME}_setting`;
|
export const STOKEY_SETTING = `${APP_NAME}_setting`;
|
||||||
export const STOKEY_RULES = `${APP_NAME}_rules`;
|
export const STOKEY_RULES = `${APP_NAME}_rules`;
|
||||||
|
export const STOKEY_WFRULES = `${APP_NAME}_webfix_rules`;
|
||||||
|
export const STOKEY_WORDS = `${APP_NAME}_words`;
|
||||||
export const STOKEY_SYNC = `${APP_NAME}_sync`;
|
export const STOKEY_SYNC = `${APP_NAME}_sync`;
|
||||||
export const STOKEY_FAB = `${APP_NAME}_fab`;
|
export const STOKEY_FAB = `${APP_NAME}_fab`;
|
||||||
export const STOKEY_RULESCACHE_PREFIX = `${APP_NAME}_rulescache_`;
|
export const STOKEY_RULESCACHE_PREFIX = `${APP_NAME}_rulescache_`;
|
||||||
@@ -30,6 +33,7 @@ export const STOKEY_WEBFIXCACHE_PREFIX = `${APP_NAME}_webfixcache_`;
|
|||||||
export const CMD_TOGGLE_TRANSLATE = "toggleTranslate";
|
export const CMD_TOGGLE_TRANSLATE = "toggleTranslate";
|
||||||
export const CMD_TOGGLE_STYLE = "toggleStyle";
|
export const CMD_TOGGLE_STYLE = "toggleStyle";
|
||||||
export const CMD_OPEN_OPTIONS = "openOptions";
|
export const CMD_OPEN_OPTIONS = "openOptions";
|
||||||
|
export const CMD_OPEN_TRANBOX = "openTranbox";
|
||||||
|
|
||||||
export const CLIENT_WEB = "web";
|
export const CLIENT_WEB = "web";
|
||||||
export const CLIENT_CHROME = "chrome";
|
export const CLIENT_CHROME = "chrome";
|
||||||
@@ -39,6 +43,8 @@ export const CLIENT_USERSCRIPT = "userscript";
|
|||||||
export const CLIENT_EXTS = [CLIENT_CHROME, CLIENT_EDGE, CLIENT_FIREFOX];
|
export const CLIENT_EXTS = [CLIENT_CHROME, CLIENT_EDGE, CLIENT_FIREFOX];
|
||||||
|
|
||||||
export const KV_RULES_KEY = "kiss-rules.json";
|
export const KV_RULES_KEY = "kiss-rules.json";
|
||||||
|
export const KV_WFRULES_KEY = "kiss-webfix.json";
|
||||||
|
export const KV_WORDS_KEY = "kiss-words.json";
|
||||||
export const KV_RULES_SHARE_KEY = "kiss-rules-share.json";
|
export const KV_RULES_SHARE_KEY = "kiss-rules-share.json";
|
||||||
export const KV_SETTING_KEY = "kiss-setting.json";
|
export const KV_SETTING_KEY = "kiss-setting.json";
|
||||||
export const KV_SALT_SYNC = "KISS-Translator-SYNC";
|
export const KV_SALT_SYNC = "KISS-Translator-SYNC";
|
||||||
@@ -53,9 +59,11 @@ export const MSG_OPEN_OPTIONS = "open_options";
|
|||||||
export const MSG_SAVE_RULE = "save_rule";
|
export const MSG_SAVE_RULE = "save_rule";
|
||||||
export const MSG_TRANS_TOGGLE = "trans_toggle";
|
export const MSG_TRANS_TOGGLE = "trans_toggle";
|
||||||
export const MSG_TRANS_TOGGLE_STYLE = "trans_toggle_style";
|
export const MSG_TRANS_TOGGLE_STYLE = "trans_toggle_style";
|
||||||
|
export const MSG_OPEN_TRANBOX = "open_tranbox";
|
||||||
export const MSG_TRANS_GETRULE = "trans_getrule";
|
export const MSG_TRANS_GETRULE = "trans_getrule";
|
||||||
export const MSG_TRANS_PUTRULE = "trans_putrule";
|
export const MSG_TRANS_PUTRULE = "trans_putrule";
|
||||||
export const MSG_TRANS_CURRULE = "trans_currule";
|
export const MSG_TRANS_CURRULE = "trans_currule";
|
||||||
|
export const MSG_CONTEXT_MENUS = "context_menus";
|
||||||
|
|
||||||
export const THEME_LIGHT = "light";
|
export const THEME_LIGHT = "light";
|
||||||
export const THEME_DARK = "dark";
|
export const THEME_DARK = "dark";
|
||||||
@@ -67,18 +75,39 @@ export const URL_KISS_RULES_NEW_ISSUE =
|
|||||||
"https://github.com/fishjar/kiss-rules/issues/new";
|
"https://github.com/fishjar/kiss-rules/issues/new";
|
||||||
export const URL_RAW_PREFIX =
|
export const URL_RAW_PREFIX =
|
||||||
"https://raw.githubusercontent.com/fishjar/kiss-translator/master";
|
"https://raw.githubusercontent.com/fishjar/kiss-translator/master";
|
||||||
|
|
||||||
|
export const URL_CACHE_TRAN = `https://${APP_LCNAME}/translate`;
|
||||||
|
export const URL_MICROSOFT_TRAN =
|
||||||
|
"https://api-edge.cognitive.microsofttranslator.com/translate";
|
||||||
export const URL_MICROSOFT_AUTH = "https://edge.microsoft.com/translate/auth";
|
export const URL_MICROSOFT_AUTH = "https://edge.microsoft.com/translate/auth";
|
||||||
|
export const URL_BAIDU_LANGDETECT = "https://fanyi.baidu.com/langdetect";
|
||||||
|
export const URL_BAIDU_WEB = "https://fanyi.baidu.com/";
|
||||||
|
export const URL_BAIDU_TRAN = "https://fanyi.baidu.com/v2transapi";
|
||||||
|
export const URL_DEEPLFREE_TRAN = "https://www2.deepl.com/jsonrpc";
|
||||||
|
export const URL_TENCENT_TRANSMART = "https://transmart.qq.com/api/imt";
|
||||||
|
|
||||||
export const OPT_TRANS_GOOGLE = "Google";
|
export const OPT_TRANS_GOOGLE = "Google";
|
||||||
export const OPT_TRANS_MICROSOFT = "Microsoft";
|
export const OPT_TRANS_MICROSOFT = "Microsoft";
|
||||||
export const OPT_TRANS_DEEPL = "DeepL";
|
export const OPT_TRANS_DEEPL = "DeepL";
|
||||||
|
export const OPT_TRANS_DEEPLX = "DeepLX";
|
||||||
|
export const OPT_TRANS_DEEPLFREE = "DeepLFree";
|
||||||
|
export const OPT_TRANS_BAIDU = "Baidu";
|
||||||
|
export const OPT_TRANS_TENCENT = "Tencent";
|
||||||
export const OPT_TRANS_OPENAI = "OpenAI";
|
export const OPT_TRANS_OPENAI = "OpenAI";
|
||||||
|
export const OPT_TRANS_GEMINI = "Gemini";
|
||||||
|
export const OPT_TRANS_CLOUDFLAREAI = "CloudflareAI";
|
||||||
export const OPT_TRANS_CUSTOMIZE = "Custom";
|
export const OPT_TRANS_CUSTOMIZE = "Custom";
|
||||||
export const OPT_TRANS_ALL = [
|
export const OPT_TRANS_ALL = [
|
||||||
OPT_TRANS_GOOGLE,
|
OPT_TRANS_GOOGLE,
|
||||||
OPT_TRANS_MICROSOFT,
|
OPT_TRANS_MICROSOFT,
|
||||||
OPT_TRANS_DEEPL,
|
OPT_TRANS_DEEPL,
|
||||||
|
OPT_TRANS_DEEPLFREE,
|
||||||
|
OPT_TRANS_DEEPLX,
|
||||||
|
OPT_TRANS_BAIDU,
|
||||||
|
OPT_TRANS_TENCENT,
|
||||||
OPT_TRANS_OPENAI,
|
OPT_TRANS_OPENAI,
|
||||||
|
OPT_TRANS_GEMINI,
|
||||||
|
OPT_TRANS_CLOUDFLAREAI,
|
||||||
OPT_TRANS_CUSTOMIZE,
|
OPT_TRANS_CUSTOMIZE,
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -123,7 +152,9 @@ export const OPT_LANGS_TO = [
|
|||||||
];
|
];
|
||||||
export const OPT_LANGS_FROM = [["auto", "Auto-detect"], ...OPT_LANGS_TO];
|
export const OPT_LANGS_FROM = [["auto", "Auto-detect"], ...OPT_LANGS_TO];
|
||||||
export const OPT_LANGS_SPECIAL = {
|
export const OPT_LANGS_SPECIAL = {
|
||||||
|
[OPT_TRANS_GOOGLE]: new Map(OPT_LANGS_FROM.map(([key]) => [key, key])),
|
||||||
[OPT_TRANS_MICROSOFT]: new Map([
|
[OPT_TRANS_MICROSOFT]: new Map([
|
||||||
|
...OPT_LANGS_FROM.map(([key]) => [key, key]),
|
||||||
["auto", ""],
|
["auto", ""],
|
||||||
["zh-CN", "zh-Hans"],
|
["zh-CN", "zh-Hans"],
|
||||||
["zh-TW", "zh-Hant"],
|
["zh-TW", "zh-Hant"],
|
||||||
@@ -134,12 +165,106 @@ export const OPT_LANGS_SPECIAL = {
|
|||||||
["zh-CN", "ZH"],
|
["zh-CN", "ZH"],
|
||||||
["zh-TW", "ZH"],
|
["zh-TW", "ZH"],
|
||||||
]),
|
]),
|
||||||
|
[OPT_TRANS_DEEPLFREE]: new Map([
|
||||||
|
...OPT_LANGS_FROM.map(([key]) => [key, key.toUpperCase()]),
|
||||||
|
["auto", "auto"],
|
||||||
|
["zh-CN", "ZH"],
|
||||||
|
["zh-TW", "ZH"],
|
||||||
|
]),
|
||||||
|
[OPT_TRANS_DEEPLX]: new Map([
|
||||||
|
...OPT_LANGS_FROM.map(([key]) => [key, key.toUpperCase()]),
|
||||||
|
["auto", ""],
|
||||||
|
["zh-CN", "ZH"],
|
||||||
|
["zh-TW", "ZH"],
|
||||||
|
]),
|
||||||
|
[OPT_TRANS_BAIDU]: new Map([
|
||||||
|
...OPT_LANGS_FROM.map(([key]) => [key, key]),
|
||||||
|
["zh-CN", "zh"],
|
||||||
|
["zh-TW", "cht"],
|
||||||
|
["ar", "ara"],
|
||||||
|
["bg", "bul"],
|
||||||
|
["ca", "cat"],
|
||||||
|
["hr", "hrv"],
|
||||||
|
["da", "dan"],
|
||||||
|
["fi", "fin"],
|
||||||
|
["fr", "fra"],
|
||||||
|
["hi", "mai"],
|
||||||
|
["ja", "jp"],
|
||||||
|
["ko", "kor"],
|
||||||
|
["ms", "may"],
|
||||||
|
["mt", "mlt"],
|
||||||
|
["nb", "nor"],
|
||||||
|
["ro", "rom"],
|
||||||
|
["ru", "ru"],
|
||||||
|
["sl", "slo"],
|
||||||
|
["es", "spa"],
|
||||||
|
["sv", "swe"],
|
||||||
|
["ta", "tam"],
|
||||||
|
["te", "tel"],
|
||||||
|
["uk", "ukr"],
|
||||||
|
["vi", "vie"],
|
||||||
|
]),
|
||||||
|
[OPT_TRANS_TENCENT]: new Map([
|
||||||
|
["auto", "auto"],
|
||||||
|
["zh-CN", "zh"],
|
||||||
|
["zh-TW", "zh"],
|
||||||
|
["en", "en"],
|
||||||
|
["ar", "ar"],
|
||||||
|
["de", "de"],
|
||||||
|
["ru", "ru"],
|
||||||
|
["fr", "fr"],
|
||||||
|
["fi", "fil"],
|
||||||
|
["ko", "ko"],
|
||||||
|
["ms", "ms"],
|
||||||
|
["pt", "pt"],
|
||||||
|
["ja", "ja"],
|
||||||
|
["th", "th"],
|
||||||
|
["tr", "tr"],
|
||||||
|
["es", "es"],
|
||||||
|
["it", "it"],
|
||||||
|
["hi", "hi"],
|
||||||
|
["id", "id"],
|
||||||
|
["vi", "vi"],
|
||||||
|
]),
|
||||||
[OPT_TRANS_OPENAI]: new Map(
|
[OPT_TRANS_OPENAI]: new Map(
|
||||||
OPT_LANGS_FROM.map(([key, val]) => [key, val.split(" - ")[0]])
|
OPT_LANGS_FROM.map(([key, val]) => [key, val.split(" - ")[0]])
|
||||||
),
|
),
|
||||||
[OPT_TRANS_CUSTOMIZE]: new Map([["auto", ""]]),
|
[OPT_TRANS_GEMINI]: new Map(
|
||||||
|
OPT_LANGS_FROM.map(([key, val]) => [key, val.split(" - ")[0]])
|
||||||
|
),
|
||||||
|
[OPT_TRANS_CLOUDFLAREAI]: new Map([
|
||||||
|
["auto", ""],
|
||||||
|
["zh-CN", "chinese"],
|
||||||
|
["zh-TW", "chinese"],
|
||||||
|
["en", "english"],
|
||||||
|
["ar", "arabic"],
|
||||||
|
["de", "german"],
|
||||||
|
["ru", "russian"],
|
||||||
|
["fr", "french"],
|
||||||
|
["pt", "portuguese"],
|
||||||
|
["ja", "japanese"],
|
||||||
|
["es", "spanish"],
|
||||||
|
["hi", "hindi"],
|
||||||
|
]),
|
||||||
|
[OPT_TRANS_CUSTOMIZE]: new Map([
|
||||||
|
...OPT_LANGS_FROM.map(([key]) => [key, key]),
|
||||||
|
["auto", ""],
|
||||||
|
]),
|
||||||
};
|
};
|
||||||
export const OPT_LANGS_LIST = OPT_LANGS_TO.map(([lang]) => lang);
|
export const OPT_LANGS_LIST = OPT_LANGS_TO.map(([lang]) => lang);
|
||||||
|
export const OPT_LANGS_BAIDU = new Map(
|
||||||
|
Array.from(OPT_LANGS_SPECIAL[OPT_TRANS_BAIDU].entries()).map(([k, v]) => [
|
||||||
|
v,
|
||||||
|
k,
|
||||||
|
])
|
||||||
|
);
|
||||||
|
export const OPT_LANGS_TENCENT = new Map(
|
||||||
|
Array.from(OPT_LANGS_SPECIAL[OPT_TRANS_TENCENT].entries()).map(([k, v]) => [
|
||||||
|
v,
|
||||||
|
k,
|
||||||
|
])
|
||||||
|
);
|
||||||
|
OPT_LANGS_TENCENT.set("zh", "zh-CN");
|
||||||
|
|
||||||
export const OPT_STYLE_NONE = "style_none"; // 无
|
export const OPT_STYLE_NONE = "style_none"; // 无
|
||||||
export const OPT_STYLE_LINE = "under_line"; // 下划线
|
export const OPT_STYLE_LINE = "under_line"; // 下划线
|
||||||
@@ -148,6 +273,7 @@ export const OPT_STYLE_DASHLINE = "dash_line"; // 虚线
|
|||||||
export const OPT_STYLE_WAVYLINE = "wavy_line"; // 波浪线
|
export const OPT_STYLE_WAVYLINE = "wavy_line"; // 波浪线
|
||||||
export const OPT_STYLE_FUZZY = "fuzzy"; // 模糊
|
export const OPT_STYLE_FUZZY = "fuzzy"; // 模糊
|
||||||
export const OPT_STYLE_HIGHLIGHT = "highlight"; // 高亮
|
export const OPT_STYLE_HIGHLIGHT = "highlight"; // 高亮
|
||||||
|
export const OPT_STYLE_BLOCKQUOTE = "blockquote"; // 引用
|
||||||
export const OPT_STYLE_DIY = "diy_style"; // 自定义样式
|
export const OPT_STYLE_DIY = "diy_style"; // 自定义样式
|
||||||
export const OPT_STYLE_ALL = [
|
export const OPT_STYLE_ALL = [
|
||||||
OPT_STYLE_NONE,
|
OPT_STYLE_NONE,
|
||||||
@@ -157,6 +283,7 @@ export const OPT_STYLE_ALL = [
|
|||||||
OPT_STYLE_WAVYLINE,
|
OPT_STYLE_WAVYLINE,
|
||||||
OPT_STYLE_FUZZY,
|
OPT_STYLE_FUZZY,
|
||||||
OPT_STYLE_HIGHLIGHT,
|
OPT_STYLE_HIGHLIGHT,
|
||||||
|
OPT_STYLE_BLOCKQUOTE,
|
||||||
OPT_STYLE_DIY,
|
OPT_STYLE_DIY,
|
||||||
];
|
];
|
||||||
export const OPT_STYLE_USE_COLOR = [
|
export const OPT_STYLE_USE_COLOR = [
|
||||||
@@ -165,6 +292,7 @@ export const OPT_STYLE_USE_COLOR = [
|
|||||||
OPT_STYLE_DASHLINE,
|
OPT_STYLE_DASHLINE,
|
||||||
OPT_STYLE_WAVYLINE,
|
OPT_STYLE_WAVYLINE,
|
||||||
OPT_STYLE_HIGHLIGHT,
|
OPT_STYLE_HIGHLIGHT,
|
||||||
|
OPT_STYLE_BLOCKQUOTE,
|
||||||
];
|
];
|
||||||
|
|
||||||
export const OPT_MOUSEKEY_DISABLE = "mk_disable";
|
export const OPT_MOUSEKEY_DISABLE = "mk_disable";
|
||||||
@@ -185,6 +313,7 @@ export const DEFAULT_FETCH_INTERVAL = 100; // 默认任务间隔时间
|
|||||||
|
|
||||||
export const PROMPT_PLACE_FROM = "{{from}}"; // 占位符
|
export const PROMPT_PLACE_FROM = "{{from}}"; // 占位符
|
||||||
export const PROMPT_PLACE_TO = "{{to}}"; // 占位符
|
export const PROMPT_PLACE_TO = "{{to}}"; // 占位符
|
||||||
|
export const PROMPT_PLACE_TEXT = "{{text}}"; // 占位符
|
||||||
|
|
||||||
export const DEFAULT_COLOR = "#209CEE"; // 默认高亮背景色/线条颜色
|
export const DEFAULT_COLOR = "#209CEE"; // 默认高亮背景色/线条颜色
|
||||||
|
|
||||||
@@ -215,6 +344,20 @@ export const DEFAULT_INPUT_RULE = {
|
|||||||
transSign: OPT_INPUT_TRANS_SIGNS[0],
|
transSign: OPT_INPUT_TRANS_SIGNS[0],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 划词翻译
|
||||||
|
export const DEFAULT_TRANBOX_SHORTCUT = ["AltLeft", "KeyS"];
|
||||||
|
export const DEFAULT_TRANBOX_SETTING = {
|
||||||
|
transOpen: true,
|
||||||
|
translator: OPT_TRANS_MICROSOFT,
|
||||||
|
fromLang: "auto",
|
||||||
|
toLang: "zh-CN",
|
||||||
|
toLang2: "en",
|
||||||
|
tranboxShortcut: DEFAULT_TRANBOX_SHORTCUT,
|
||||||
|
btnOffsetX: 10,
|
||||||
|
btnOffsetY: 10,
|
||||||
|
hideTranBtn: false,
|
||||||
|
};
|
||||||
|
|
||||||
// 订阅列表
|
// 订阅列表
|
||||||
export const DEFAULT_SUBRULES_LIST = [
|
export const DEFAULT_SUBRULES_LIST = [
|
||||||
{
|
{
|
||||||
@@ -237,20 +380,30 @@ export const DEFAULT_TRANS_APIS = {
|
|||||||
url: "https://translate.googleapis.com/translate_a/single",
|
url: "https://translate.googleapis.com/translate_a/single",
|
||||||
key: "",
|
key: "",
|
||||||
},
|
},
|
||||||
[OPT_TRANS_MICROSOFT]: {
|
|
||||||
url: "https://api-edge.cognitive.microsofttranslator.com/translate",
|
|
||||||
authUrl: "https://edge.microsoft.com/translate/auth",
|
|
||||||
},
|
|
||||||
[OPT_TRANS_DEEPL]: {
|
[OPT_TRANS_DEEPL]: {
|
||||||
url: "https://api-free.deepl.com/v2/translate",
|
url: "https://api-free.deepl.com/v2/translate",
|
||||||
key: "",
|
key: "",
|
||||||
},
|
},
|
||||||
|
[OPT_TRANS_DEEPLX]: {
|
||||||
|
url: "http://localhost:1188/translate",
|
||||||
|
key: "",
|
||||||
|
},
|
||||||
[OPT_TRANS_OPENAI]: {
|
[OPT_TRANS_OPENAI]: {
|
||||||
url: "https://api.openai.com/v1/chat/completion",
|
url: "https://api.openai.com/v1/chat/completions",
|
||||||
key: "",
|
key: "",
|
||||||
model: "gpt-4",
|
model: "gpt-4",
|
||||||
prompt: `You will be provided with a sentence in ${PROMPT_PLACE_FROM}, and your task is to translate it into ${PROMPT_PLACE_TO}.`,
|
prompt: `You will be provided with a sentence in ${PROMPT_PLACE_FROM}, and your task is to translate it into ${PROMPT_PLACE_TO}.`,
|
||||||
},
|
},
|
||||||
|
[OPT_TRANS_GEMINI]: {
|
||||||
|
url: "https://generativelanguage.googleapis.com/v1/models",
|
||||||
|
key: "",
|
||||||
|
model: "gemini-pro",
|
||||||
|
prompt: `Translate the following text from ${PROMPT_PLACE_FROM} to ${PROMPT_PLACE_TO}:\n\n${PROMPT_PLACE_TEXT}`,
|
||||||
|
},
|
||||||
|
[OPT_TRANS_CLOUDFLAREAI]: {
|
||||||
|
url: "https://api.cloudflare.com/client/v4/accounts/{ACCOUNT_ID}/ai/run/@cf/meta/m2m100-1.2b",
|
||||||
|
key: "",
|
||||||
|
},
|
||||||
[OPT_TRANS_CUSTOMIZE]: {
|
[OPT_TRANS_CUSTOMIZE]: {
|
||||||
url: "",
|
url: "",
|
||||||
key: "",
|
key: "",
|
||||||
@@ -266,12 +419,19 @@ export const DEFAULT_SHORTCUTS = {
|
|||||||
[OPT_SHORTCUT_TRANSLATE]: ["AltLeft", "KeyQ"],
|
[OPT_SHORTCUT_TRANSLATE]: ["AltLeft", "KeyQ"],
|
||||||
[OPT_SHORTCUT_STYLE]: ["AltLeft", "KeyC"],
|
[OPT_SHORTCUT_STYLE]: ["AltLeft", "KeyC"],
|
||||||
[OPT_SHORTCUT_POPUP]: ["AltLeft", "KeyK"],
|
[OPT_SHORTCUT_POPUP]: ["AltLeft", "KeyK"],
|
||||||
[OPT_SHORTCUT_SETTING]: ["AltLeft", "KeyN"],
|
[OPT_SHORTCUT_SETTING]: ["AltLeft", "KeyO"],
|
||||||
};
|
};
|
||||||
|
|
||||||
export const TRANS_MIN_LENGTH = 5; // 最短翻译长度
|
export const TRANS_MIN_LENGTH = 5; // 最短翻译长度
|
||||||
export const TRANS_MAX_LENGTH = 5000; // 最长翻译长度
|
export const TRANS_MAX_LENGTH = 5000; // 最长翻译长度
|
||||||
export const TRANS_NEWLINE_LENGTH = 20; // 换行字符数
|
export const TRANS_NEWLINE_LENGTH = 20; // 换行字符数
|
||||||
|
export const DEFAULT_BLACKLIST = [
|
||||||
|
"https://fishjar.github.io/kiss-translator/options.html",
|
||||||
|
"https://translate.google.com",
|
||||||
|
"https://www.deepl.com/translator",
|
||||||
|
"oapi.dingtalk.com",
|
||||||
|
"login.dingtalk.com",
|
||||||
|
]; // 禁用翻译名单
|
||||||
|
|
||||||
export const DEFAULT_SETTING = {
|
export const DEFAULT_SETTING = {
|
||||||
darkMode: false, // 深色模式
|
darkMode: false, // 深色模式
|
||||||
@@ -284,12 +444,18 @@ export const DEFAULT_SETTING = {
|
|||||||
clearCache: false, // 是否在浏览器下次启动时清除缓存
|
clearCache: false, // 是否在浏览器下次启动时清除缓存
|
||||||
injectRules: true, // 是否注入订阅规则
|
injectRules: true, // 是否注入订阅规则
|
||||||
injectWebfix: true, // 是否注入修复补丁
|
injectWebfix: true, // 是否注入修复补丁
|
||||||
|
detectRemote: false, // 是否使用远程语言检测
|
||||||
|
contextMenus: true, // 是否添加右键菜单
|
||||||
subrulesList: DEFAULT_SUBRULES_LIST, // 订阅列表
|
subrulesList: DEFAULT_SUBRULES_LIST, // 订阅列表
|
||||||
owSubrule: DEFAULT_OW_RULE, // 覆写订阅规则
|
owSubrule: DEFAULT_OW_RULE, // 覆写订阅规则
|
||||||
transApis: DEFAULT_TRANS_APIS, // 翻译接口
|
transApis: DEFAULT_TRANS_APIS, // 翻译接口
|
||||||
mouseKey: OPT_MOUSEKEY_DISABLE, // 鼠标悬停翻译
|
mouseKey: OPT_MOUSEKEY_DISABLE, // 鼠标悬停翻译
|
||||||
shortcuts: DEFAULT_SHORTCUTS, // 快捷键
|
shortcuts: DEFAULT_SHORTCUTS, // 快捷键
|
||||||
inputRule: DEFAULT_INPUT_RULE, // 输入框设置
|
inputRule: DEFAULT_INPUT_RULE, // 输入框设置
|
||||||
|
tranboxSetting: DEFAULT_TRANBOX_SETTING, // 划词翻译设置
|
||||||
|
touchTranslate: 2, // 触屏翻译
|
||||||
|
blacklist: DEFAULT_BLACKLIST.join(",\n"), // 禁用翻译名单
|
||||||
|
disableLangs: [], // 不翻译的语言
|
||||||
};
|
};
|
||||||
|
|
||||||
export const DEFAULT_RULES = [GLOBLA_RULE];
|
export const DEFAULT_RULES = [GLOBLA_RULE];
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
const els = `li, p, h1, h2, h3, h4, h5, h6, dd, blockquote`;
|
export const DEFAULT_SELECTOR = `:is(li, p, h1, h2, h3, h4, h5, h6, dd, blockquote)`;
|
||||||
|
|
||||||
export const DEFAULT_SELECTOR = `:is(${els})`;
|
|
||||||
|
|
||||||
export const GLOBAL_KEY = "*";
|
export const GLOBAL_KEY = "*";
|
||||||
export const REMAIN_KEY = "-";
|
export const REMAIN_KEY = "-";
|
||||||
@@ -42,145 +40,66 @@ export const DEFAULT_OW_RULE = {
|
|||||||
textDiyStyle: DEFAULT_DIY_STYLE,
|
textDiyStyle: DEFAULT_DIY_STYLE,
|
||||||
};
|
};
|
||||||
|
|
||||||
const RULES = [
|
const RULES_MAP = {
|
||||||
{
|
"www.google.com/search": `h3, .IsZvec, .VwiC3b`,
|
||||||
pattern: `www.google.com/search`,
|
"news.google.com": `[role="link"], .DY5T1d, .ifw3f, ${DEFAULT_SELECTOR}`,
|
||||||
selector: `h3, .IsZvec, .VwiC3b`,
|
"www.foxnews.com": `h1, h2, .title, .sidebar [data-type="Title"], .article-content ${DEFAULT_SELECTOR}; [data-spotim-module="conversation"]>div >>> [data-spot-im-class="message-text"] p, [data-spot-im-class="message-text"]`,
|
||||||
},
|
"bearblog.dev, www.theverge.com, www.tampermonkey.net/documentation.php": `${DEFAULT_SELECTOR}`,
|
||||||
{
|
"themessenger.com": `.leading-tight, .leading-tighter, .my-2 p, .font-body p, article ${DEFAULT_SELECTOR}`,
|
||||||
pattern: `news.google.com`,
|
"www.telegraph.co.uk, go.dev/doc/": `article ${DEFAULT_SELECTOR}`,
|
||||||
selector: `h4`,
|
"www.theguardian.com": `.show-underline, .dcr-hup5wm div, .dcr-7vl6y8 div, .dcr-12evv1c, figcaption, article ${DEFAULT_SELECTOR}, [data-cy="mostviewed-footer"] h4`,
|
||||||
},
|
"www.semafor.com": `${DEFAULT_SELECTOR}, .styles_intro__IYj__, [class*="styles_description"]`,
|
||||||
{
|
"www.noemamag.com": `.splash__title, .single-card__title, .single-card__type, .single-card__topic, .highlighted-content__title, .single-card__author, article ${DEFAULT_SELECTOR}, .quote__text, .wp-caption-text div`,
|
||||||
pattern: `www.foxnews.com`,
|
"restofworld.org": `${DEFAULT_SELECTOR}, .recirc-story__headline, .recirc-story__dek`,
|
||||||
selector: `h1, h2, .title, .sidebar [data-type="Title"], .article-content ${DEFAULT_SELECTOR}; [data-spotim-module="conversation"]>div >>> [data-spot-im-class="message-text"] p, [data-spot-im-class="message-text"]`,
|
"www.axios.com": `.h7, ${DEFAULT_SELECTOR}`,
|
||||||
},
|
"www.newyorker.com": `.summary-item__hed, .summary-item__dek, .summary-collection-grid__dek, .dqtvfu, .rubric__link, .caption, article ${DEFAULT_SELECTOR}, .HEhan ${DEFAULT_SELECTOR}, .ContributorBioBio-fBolsO`,
|
||||||
{
|
"time.com": `h1, h3, .summary, .video-title, #article-body ${DEFAULT_SELECTOR}, .image-wrap-container .credit.body-caption, .media-heading`,
|
||||||
pattern: `bearblog.dev, www.theverge.com, www.tampermonkey.net/documentation.php`,
|
"www.dw.com": `.ts-teaser-title a, .news-title a, .title a, .teaser-description a, .hbudab h3, .hbudab p, figcaption ,article ${DEFAULT_SELECTOR}`,
|
||||||
selector: DEFAULT_SELECTOR,
|
"www.bbc.com": `h1, h2, .media__link, .media__summary, article ${DEFAULT_SELECTOR}, .ssrcss-y7krbn-Stack, .ssrcss-17zglt8-PromoHeadline, .ssrcss-18cjaf3-Headline, .gs-c-promo-heading__title, .gs-c-promo-summary, .media__content h3, .article__intro`,
|
||||||
},
|
"www.chinadaily.com.cn": `h1, .tMain [shape="rect"], .cMain [shape="rect"], .photo_art [shape="rect"], .mai_r [shape="rect"], .lisBox li, #Content ${DEFAULT_SELECTOR}`,
|
||||||
{
|
"www.facebook.com": `[role="main"] [dir="auto"]`,
|
||||||
pattern: `themessenger.com`,
|
"www.reddit.com": `[slot="title"], [slot="text-body"] ${DEFAULT_SELECTOR}, #-post-rtjson-content p`,
|
||||||
selector: `.leading-tight, .leading-tighter, .my-2 p, .font-body p, article ${DEFAULT_SELECTOR}`,
|
"www.quora.com": `.qu-wordBreak--break-word`,
|
||||||
},
|
"edition.cnn.com": `.container__title, .container__headline, .headline__text, .image__caption, [data-type="Title"], .article__content ${DEFAULT_SELECTOR}`,
|
||||||
{
|
"www.reuters.com": `#main-content [data-testid="Heading"], #main-content [data-testid="Body"], .article-body__content__17Yit ${DEFAULT_SELECTOR}`,
|
||||||
pattern: `www.telegraph.co.uk`,
|
"www.bloomberg.com": `[data-component="headline"], [data-component="related-item-headline"], [data-component="title"], article ${DEFAULT_SELECTOR}`,
|
||||||
selector: `article ${DEFAULT_SELECTOR}`,
|
"deno.land, docs.github.com": `main ${DEFAULT_SELECTOR}`,
|
||||||
},
|
"doc.rust-lang.org": `.content ${DEFAULT_SELECTOR}`,
|
||||||
{
|
"www.indiehackers.com": `h1, h3, .content ${DEFAULT_SELECTOR}, .feed-item__title-link`,
|
||||||
pattern: `www.theguardian.com`,
|
"platform.openai.com/docs": `.docs-body ${DEFAULT_SELECTOR}`,
|
||||||
selector: `.show-underline, .dcr-hup5wm div, .dcr-7vl6y8 div, .dcr-12evv1c, figcaption, article ${DEFAULT_SELECTOR}, [data-cy="mostviewed-footer"] h4`,
|
"en.wikipedia.org": `h1, .mw-parser-output ${DEFAULT_SELECTOR}`,
|
||||||
},
|
"stackoverflow.com": `h1, .s-prose p, .comment-body .comment-copy`,
|
||||||
{
|
"www.npmjs.com/package, developer.chrome.com/docs, medium.com, developers.cloudflare.com, react.dev, create-react-app.dev, pytorch.org": `article ${DEFAULT_SELECTOR}`,
|
||||||
pattern: `www.semafor.com`,
|
"news.ycombinator.com": `.title, .commtext`,
|
||||||
selector: `${DEFAULT_SELECTOR}, .styles_intro__IYj__, [class*="styles_description"]`,
|
"github.com": `.markdown-body ${DEFAULT_SELECTOR}, .repo-description p, .Layout-sidebar .f4, .container-lg .py-4 .f5, .container-lg .my-4 .f5, .Box-row .pr-4, .Box-row article .mt-1, [itemprop="description"], .markdown-title, bdi, .ws-pre-wrap, .status-meta, span.status-meta, .col-10.color-fg-muted, .TimelineItem-body, .pinned-item-list-item-content .color-fg-muted, .markdown-body td, .markdown-body th`,
|
||||||
},
|
"twitter.com": `[data-testid="tweetText"]`,
|
||||||
{
|
"m.youtube.com": `.slim-video-information-title .yt-core-attributed-string, .media-item-headline .yt-core-attributed-string, .comment-text .yt-core-attributed-string, .typography-body-2b .yt-core-attributed-string, #ytp-caption-window-container .ytp-caption-segment`,
|
||||||
pattern: `www.noemamag.com`,
|
"www.youtube.com": `h1, #video-title, #content-text, #title, yt-attributed-string>span>span, #ytp-caption-window-container .ytp-caption-segment`,
|
||||||
selector: `.splash__title, .single-card__title, .single-card__type, .single-card__topic, .highlighted-content__title, .single-card__author, article ${DEFAULT_SELECTOR}, .quote__text, .wp-caption-text div`,
|
"bard.google.com": `.query-content ${DEFAULT_SELECTOR}, message-content ${DEFAULT_SELECTOR}`,
|
||||||
},
|
"www.bing.com": `.b_algoSlug, .rwrl_padref; .cib-serp-main >>> .ac-textBlock ${DEFAULT_SELECTOR}, .text-message-content div`,
|
||||||
{
|
"www.phoronix.com": `article ${DEFAULT_SELECTOR}`,
|
||||||
pattern: `restofworld.org`,
|
"wx2.qq.com": `.js_message_plain`,
|
||||||
selector: `${DEFAULT_SELECTOR}, .recirc-story__headline, .recirc-story__dek`,
|
"app.slack.com/client/": `.p-rich_text_section, .c-message_attachment__text, .p-rich_text_list li`,
|
||||||
},
|
"discord.com/channels/": `div[id^=message-content]`,
|
||||||
{
|
"t.me/s/": `.js-message_text ${DEFAULT_SELECTOR}`,
|
||||||
pattern: `www.axios.com`,
|
"web.telegram.org/k/": `.message, .bot-commands-list-element-description, .reply-markup-button-text`,
|
||||||
selector: `.h7, ${DEFAULT_SELECTOR}`,
|
"web.telegram.org/a/": `.message, .text-content, .bot-commands-list-element-description, .reply-markup-button-text`,
|
||||||
},
|
"chromereleases.googleblog.com": `.title, .publishdate, p, i, .header-desc, .header-title, .text`,
|
||||||
{
|
"www.instagram.com/": `h1, article span[dir=auto] > span[dir=auto], ._ab1y`,
|
||||||
pattern: `www.newyorker.com`,
|
"www.instagram.com/p/,www.instagram.com/reels/": `h1, div[class='x9f619 xjbqb8w x78zum5 x168nmei x13lgxp2 x5pf9jr xo71vjh x1uhb9sk x1plvlek xryxfnj x1c4vz4f x2lah0s xdt5ytf xqjyukv x1cy8zhl x1oa3qoh x1nhvcw1'] > span[class='x1lliihq x1plvlek xryxfnj x1n2onr6 x193iq5w xeuugli x1fj9vlw x13faqbe x1vvkbs x1s928wv xhkezso x1gmr53x x1cpjm7i x1fgarty x1943h6x x1i0vuye xvs91rp xo1l8bm x5n08af x10wh9bi x1wdrske x8viiok x18hxmgj'], span[class='x193iq5w xeuugli x1fj9vlw x13faqbe x1vvkbs xt0psk2 x1i0vuye xvs91rp xo1l8bm x5n08af x10wh9bi x1wdrske x8viiok x18hxmgj']`,
|
||||||
selector: `.summary-item__hed, .summary-item__dek, .summary-collection-grid__dek, .dqtvfu, .rubric__link, .caption, article ${DEFAULT_SELECTOR}, .HEhan ${DEFAULT_SELECTOR}, .ContributorBioBio-fBolsO`,
|
"mail.google.com": `${DEFAULT_SELECTOR}, h2[data-thread-perm-id], span[data-thread-id], div[data-message-id] div[class=''], .messageBody, #views`,
|
||||||
},
|
"web.whatsapp.com": `.copyable-text > span`,
|
||||||
{
|
"chat.openai.com": `div[data-message-author-role] > div ${DEFAULT_SELECTOR}`,
|
||||||
pattern: `https://time.com/`,
|
"forum.ru-board.com": `.tit, .dats, span.post ${DEFAULT_SELECTOR}`,
|
||||||
selector: `h1, h3, .summary, .video-title, #article-body ${DEFAULT_SELECTOR}, .image-wrap-container .credit.body-caption, .media-heading`,
|
"education.github.com": `${DEFAULT_SELECTOR}, a, summary, span.Button-content`,
|
||||||
},
|
"blogs.windows.com": `${DEFAULT_SELECTOR}, .c-uhf-nav-link, figcaption`,
|
||||||
{
|
"developer.apple.com/documentation/": `#main ${DEFAULT_SELECTOR}, #main .abstract .content, #main .abstract.content, #main .link span`,
|
||||||
pattern: `www.dw.com`,
|
};
|
||||||
selector: `.ts-teaser-title a, .news-title a, .title a, .teaser-description a, .hbudab h3, .hbudab p, figcaption ,article ${DEFAULT_SELECTOR}`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
pattern: `www.bbc.com`,
|
|
||||||
selector: `h1, h2, .media__link, .media__summary, article ${DEFAULT_SELECTOR}, .ssrcss-y7krbn-Stack, .ssrcss-1mrs5ns-PromoLink, .ssrcss-18cjaf3-Headline, .gs-c-promo-heading__title, .gs-c-promo-summary, .media__content h3, .article__intro`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
pattern: `www.chinadaily.com.cn`,
|
|
||||||
selector: `h1, .tMain [shape="rect"], .cMain [shape="rect"], .photo_art [shape="rect"], .mai_r [shape="rect"], .lisBox li, #Content ${DEFAULT_SELECTOR}`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
pattern: `www.facebook.com`,
|
|
||||||
selector: `[role="main"] [dir="auto"]`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
pattern: `www.reddit.com`,
|
|
||||||
selector: `[slot="title"], [slot="text-body"] ${DEFAULT_SELECTOR}, #-post-rtjson-content p`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
pattern: `www.quora.com`,
|
|
||||||
selector: `.qu-wordBreak--break-word`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
pattern: `edition.cnn.com`,
|
|
||||||
selector: `.container__title, .container__headline, .headline__text, .image__caption, [data-type="Title"], .article__content ${DEFAULT_SELECTOR}`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
pattern: `www.reuters.com`,
|
|
||||||
selector: `#main-content [data-testid="Heading"], #main-content [data-testid="Body"], .article-body__content__17Yit ${DEFAULT_SELECTOR}`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
pattern: `www.bloomberg.com`,
|
|
||||||
selector: `[data-component="headline"], [data-component="related-item-headline"], [data-component="title"], article ${DEFAULT_SELECTOR}`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
pattern: `deno.land, docs.github.com`,
|
|
||||||
selector: `main ${DEFAULT_SELECTOR}`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
pattern: `doc.rust-lang.org`,
|
|
||||||
selector: `#content ${DEFAULT_SELECTOR}`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
pattern: `www.indiehackers.com`,
|
|
||||||
selector: `h1, h3, .content ${DEFAULT_SELECTOR}, .feed-item__title-link`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
pattern: `platform.openai.com/docs`,
|
|
||||||
selector: `.docs-body ${DEFAULT_SELECTOR}`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
pattern: `en.wikipedia.org`,
|
|
||||||
selector: `h1, .mw-parser-output ${DEFAULT_SELECTOR}`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
pattern: `stackoverflow.com`,
|
|
||||||
selector: `h1, .s-prose p, .comment-body .comment-copy`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
pattern: `www.npmjs.com/package/, developer.chrome.com/docs, medium.com, developers.cloudflare.com, react.dev, create-react-app.dev, pytorch.org/`,
|
|
||||||
selector: `article ${DEFAULT_SELECTOR}`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
pattern: `news.ycombinator.com`,
|
|
||||||
selector: `.title, .commtext`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
pattern: `https://github.com/`,
|
|
||||||
selector: `.markdown-body ${DEFAULT_SELECTOR}, .repo-description p, .Layout-sidebar .f4, .container-lg .py-4 .f5, .container-lg .my-4 .f5, .Box-row .pr-4, .Box-row article .mt-1, [itemprop='description'], .markdown-title, bdi`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
pattern: `twitter.com`,
|
|
||||||
selector: `[data-testid='tweetText']`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
pattern: `youtube.com`,
|
|
||||||
selector: `h1, #video-title, #content-text, #title, yt-attributed-string>span>span`,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
export const BUILTIN_RULES = RULES.sort((a, b) =>
|
export const BUILTIN_RULES = Object.entries(RULES_MAP)
|
||||||
a.pattern.localeCompare(b.pattern)
|
.sort((a, b) => a[0].localeCompare(b[0]))
|
||||||
).map((item) => ({
|
.map(([pattern, selector]) => ({
|
||||||
...DEFAULT_RULE,
|
...DEFAULT_RULE,
|
||||||
...item,
|
pattern,
|
||||||
transOpen: "true",
|
selector,
|
||||||
}));
|
}));
|
||||||
|
|||||||
129
src/content.js
129
src/content.js
@@ -1,128 +1,3 @@
|
|||||||
import { browser } from "./libs/browser";
|
import { run } from "./common";
|
||||||
import React from "react";
|
|
||||||
import ReactDOM from "react-dom/client";
|
|
||||||
import Action from "./views/Action";
|
|
||||||
import createCache from "@emotion/cache";
|
|
||||||
import { CacheProvider } from "@emotion/react";
|
|
||||||
import {
|
|
||||||
MSG_TRANS_TOGGLE,
|
|
||||||
MSG_TRANS_TOGGLE_STYLE,
|
|
||||||
MSG_TRANS_GETRULE,
|
|
||||||
MSG_TRANS_PUTRULE,
|
|
||||||
} from "./config";
|
|
||||||
import {
|
|
||||||
getSettingWithDefault,
|
|
||||||
getRulesWithDefault,
|
|
||||||
getFabWithDefault,
|
|
||||||
} from "./libs/storage";
|
|
||||||
import { Translator } from "./libs/translator";
|
|
||||||
import { isIframe, sendIframeMsg, sendPrentMsg } from "./libs/iframe";
|
|
||||||
import { matchRule } from "./libs/rules";
|
|
||||||
import { webfix } from "./libs/webfix";
|
|
||||||
|
|
||||||
/**
|
run();
|
||||||
* 入口函数
|
|
||||||
*/
|
|
||||||
const init = async () => {
|
|
||||||
const setting = await getSettingWithDefault();
|
|
||||||
|
|
||||||
if (isIframe) {
|
|
||||||
let translator;
|
|
||||||
window.addEventListener("message", (e) => {
|
|
||||||
const { action, args } = e.data || {};
|
|
||||||
switch (action) {
|
|
||||||
case MSG_TRANS_TOGGLE:
|
|
||||||
translator?.toggle();
|
|
||||||
break;
|
|
||||||
case MSG_TRANS_TOGGLE_STYLE:
|
|
||||||
translator?.toggleStyle();
|
|
||||||
break;
|
|
||||||
case MSG_TRANS_PUTRULE:
|
|
||||||
if (!translator) {
|
|
||||||
translator = new Translator(args, setting);
|
|
||||||
} else {
|
|
||||||
translator.updateRule(args || {});
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
});
|
|
||||||
sendPrentMsg(MSG_TRANS_GETRULE);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const href = document.location.href;
|
|
||||||
const rules = await getRulesWithDefault();
|
|
||||||
const rule = await matchRule(rules, href, setting);
|
|
||||||
const translator = new Translator(rule, setting);
|
|
||||||
webfix(href, setting);
|
|
||||||
|
|
||||||
// 监听消息
|
|
||||||
browser?.runtime.onMessage.addListener(async ({ action, args }) => {
|
|
||||||
switch (action) {
|
|
||||||
case MSG_TRANS_TOGGLE:
|
|
||||||
translator.toggle();
|
|
||||||
sendIframeMsg(MSG_TRANS_TOGGLE);
|
|
||||||
break;
|
|
||||||
case MSG_TRANS_TOGGLE_STYLE:
|
|
||||||
translator.toggleStyle();
|
|
||||||
sendIframeMsg(MSG_TRANS_TOGGLE_STYLE);
|
|
||||||
break;
|
|
||||||
case MSG_TRANS_GETRULE:
|
|
||||||
break;
|
|
||||||
case MSG_TRANS_PUTRULE:
|
|
||||||
translator.updateRule(args);
|
|
||||||
sendIframeMsg(MSG_TRANS_PUTRULE, args);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return { error: `message action is unavailable: ${action}` };
|
|
||||||
}
|
|
||||||
return { data: translator.rule };
|
|
||||||
});
|
|
||||||
window.addEventListener("message", (e) => {
|
|
||||||
const { action } = e.data || {};
|
|
||||||
switch (action) {
|
|
||||||
case MSG_TRANS_GETRULE:
|
|
||||||
sendIframeMsg(MSG_TRANS_PUTRULE, rule);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// 浮球按钮
|
|
||||||
const fab = await getFabWithDefault();
|
|
||||||
if (!fab.isHide) {
|
|
||||||
const $action = document.createElement("div");
|
|
||||||
$action.setAttribute("id", "kiss-translator");
|
|
||||||
document.body.parentElement.appendChild($action);
|
|
||||||
const shadowContainer = $action.attachShadow({ mode: "closed" });
|
|
||||||
const emotionRoot = document.createElement("style");
|
|
||||||
const shadowRootElement = document.createElement("div");
|
|
||||||
shadowContainer.appendChild(emotionRoot);
|
|
||||||
shadowContainer.appendChild(shadowRootElement);
|
|
||||||
const cache = createCache({
|
|
||||||
key: "css",
|
|
||||||
prepend: true,
|
|
||||||
container: emotionRoot,
|
|
||||||
});
|
|
||||||
ReactDOM.createRoot(shadowRootElement).render(
|
|
||||||
<React.StrictMode>
|
|
||||||
<CacheProvider value={cache}>
|
|
||||||
<Action translator={translator} fab={fab} />
|
|
||||||
</CacheProvider>
|
|
||||||
</React.StrictMode>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
(async () => {
|
|
||||||
try {
|
|
||||||
await init();
|
|
||||||
} catch (err) {
|
|
||||||
console.error("[KISS-Translator]", err);
|
|
||||||
const $err = document.createElement("div");
|
|
||||||
$err.innerText = `KISS-Translator: ${err.message}`;
|
|
||||||
$err.style.cssText = "background:red; color:#fff;";
|
|
||||||
document.body.prepend($err);
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
|
|||||||
67
src/hooks/FavWords.js
Normal file
67
src/hooks/FavWords.js
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
import { KV_WORDS_KEY } from "../config";
|
||||||
|
import { useCallback, useEffect, useState } from "react";
|
||||||
|
import { trySyncWords } from "../libs/sync";
|
||||||
|
import { getWordsWithDefault, setWords } from "../libs/storage";
|
||||||
|
import { useSyncMeta } from "./Sync";
|
||||||
|
|
||||||
|
export function useFavWords() {
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [favWords, setFavWords] = useState({});
|
||||||
|
const { updateSyncMeta } = useSyncMeta();
|
||||||
|
|
||||||
|
const toggleFav = useCallback(
|
||||||
|
async (word) => {
|
||||||
|
const favs = { ...favWords };
|
||||||
|
if (favs[word]) {
|
||||||
|
delete favs[word];
|
||||||
|
} else {
|
||||||
|
favs[word] = { createdAt: Date.now() };
|
||||||
|
}
|
||||||
|
await setWords(favs);
|
||||||
|
await updateSyncMeta(KV_WORDS_KEY);
|
||||||
|
await trySyncWords();
|
||||||
|
setFavWords(favs);
|
||||||
|
},
|
||||||
|
[updateSyncMeta, favWords]
|
||||||
|
);
|
||||||
|
|
||||||
|
const mergeWords = useCallback(
|
||||||
|
async (newWords) => {
|
||||||
|
const favs = { ...favWords };
|
||||||
|
newWords.forEach((word) => {
|
||||||
|
if (!favs[word]) {
|
||||||
|
favs[word] = { createdAt: Date.now() };
|
||||||
|
}
|
||||||
|
});
|
||||||
|
await setWords(favs);
|
||||||
|
await updateSyncMeta(KV_WORDS_KEY);
|
||||||
|
await trySyncWords();
|
||||||
|
setFavWords(favs);
|
||||||
|
},
|
||||||
|
[updateSyncMeta, favWords]
|
||||||
|
);
|
||||||
|
|
||||||
|
const clearWords = useCallback(async () => {
|
||||||
|
await setWords({});
|
||||||
|
await updateSyncMeta(KV_WORDS_KEY);
|
||||||
|
await trySyncWords();
|
||||||
|
setFavWords({});
|
||||||
|
}, [updateSyncMeta]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
(async () => {
|
||||||
|
try {
|
||||||
|
setLoading(true);
|
||||||
|
await trySyncWords();
|
||||||
|
const favWords = await getWordsWithDefault();
|
||||||
|
setFavWords(favWords);
|
||||||
|
} catch (err) {
|
||||||
|
console.log("[query fav]", err);
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return { loading, favWords, toggleFav, mergeWords, clearWords };
|
||||||
|
}
|
||||||
@@ -1,6 +1,12 @@
|
|||||||
import { useCallback, useEffect, useState } from "react";
|
import { useCallback, useEffect, useState } from "react";
|
||||||
import { storage } from "../libs/storage";
|
import { storage } from "../libs/storage";
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {*} key
|
||||||
|
* @param {*} defaultVal 需为调用hook外的常量
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
export function useStorage(key, defaultVal) {
|
export function useStorage(key, defaultVal) {
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [data, setData] = useState(null);
|
const [data, setData] = useState(null);
|
||||||
|
|||||||
@@ -12,10 +12,24 @@ import { THEME_DARK, THEME_LIGHT } from "../config";
|
|||||||
export default function Theme({ children, options }) {
|
export default function Theme({ children, options }) {
|
||||||
const { darkMode } = useDarkMode();
|
const { darkMode } = useDarkMode();
|
||||||
const theme = useMemo(() => {
|
const theme = useMemo(() => {
|
||||||
|
let htmlFontSize = 16;
|
||||||
|
try {
|
||||||
|
const s = window.getComputedStyle(document.body.parentNode).fontSize;
|
||||||
|
const fontSize = parseInt(s.replace("px", ""));
|
||||||
|
if (fontSize > 0 && fontSize < 1000) {
|
||||||
|
htmlFontSize = fontSize;
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
return createTheme({
|
return createTheme({
|
||||||
palette: {
|
palette: {
|
||||||
mode: darkMode ? THEME_DARK : THEME_LIGHT,
|
mode: darkMode ? THEME_DARK : THEME_LIGHT,
|
||||||
},
|
},
|
||||||
|
typography: {
|
||||||
|
htmlFontSize,
|
||||||
|
},
|
||||||
...options,
|
...options,
|
||||||
});
|
});
|
||||||
}, [darkMode, options]);
|
}, [darkMode, options]);
|
||||||
|
|||||||
18
src/hooks/Tranbox.js
Normal file
18
src/hooks/Tranbox.js
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import { useCallback } from "react";
|
||||||
|
import { DEFAULT_TRANBOX_SETTING } from "../config";
|
||||||
|
import { useSetting } from "./Setting";
|
||||||
|
|
||||||
|
export function useTranbox() {
|
||||||
|
const { setting, updateSetting } = useSetting();
|
||||||
|
const tranboxSetting = setting?.tranboxSetting || DEFAULT_TRANBOX_SETTING;
|
||||||
|
|
||||||
|
const updateTranbox = useCallback(
|
||||||
|
async (obj) => {
|
||||||
|
Object.assign(tranboxSetting, obj);
|
||||||
|
await updateSetting({ tranboxSetting });
|
||||||
|
},
|
||||||
|
[tranboxSetting, updateSetting]
|
||||||
|
);
|
||||||
|
|
||||||
|
return { tranboxSetting, updateTranbox };
|
||||||
|
}
|
||||||
@@ -23,8 +23,12 @@ export function useTranslate(q, rule, setting) {
|
|||||||
try {
|
try {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
|
||||||
const deLang = await tryDetectLang(q);
|
const deLang = await tryDetectLang(q, setting.detectRemote);
|
||||||
if (deLang && toLang.includes(deLang)) {
|
const disableLangs = setting.disableLangs || [];
|
||||||
|
if (
|
||||||
|
deLang &&
|
||||||
|
(toLang.includes(deLang) || disableLangs.includes(deLang))
|
||||||
|
) {
|
||||||
setSamelang(true);
|
setSamelang(true);
|
||||||
} else {
|
} else {
|
||||||
const [trText, isSame] = await apiTranslate({
|
const [trText, isSame] = await apiTranslate({
|
||||||
@@ -32,7 +36,8 @@ export function useTranslate(q, rule, setting) {
|
|||||||
text: q,
|
text: q,
|
||||||
fromLang,
|
fromLang,
|
||||||
toLang,
|
toLang,
|
||||||
apiSetting: (setting.transApis || DEFAULT_TRANS_APIS)[translator],
|
apiSetting:
|
||||||
|
setting.transApis?.[translator] || DEFAULT_TRANS_APIS[translator],
|
||||||
});
|
});
|
||||||
setText(trText);
|
setText(trText);
|
||||||
setSamelang(isSame);
|
setSamelang(isSame);
|
||||||
|
|||||||
58
src/hooks/WebfixRules.js
Normal file
58
src/hooks/WebfixRules.js
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
import { STOKEY_WFRULES, KV_WFRULES_KEY } from "../config";
|
||||||
|
import { useStorage } from "./Storage";
|
||||||
|
import { trySyncWebfixRules } from "../libs/sync";
|
||||||
|
import { useCallback } from "react";
|
||||||
|
import { useSyncMeta } from "./Sync";
|
||||||
|
|
||||||
|
const DEFAULT_WFRULES = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修复规则 hook
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
export function useWebfixRules() {
|
||||||
|
const { data: list, save } = useStorage(STOKEY_WFRULES, DEFAULT_WFRULES);
|
||||||
|
const { updateSyncMeta } = useSyncMeta();
|
||||||
|
|
||||||
|
const updateRules = useCallback(
|
||||||
|
async (rules) => {
|
||||||
|
await save(rules);
|
||||||
|
await updateSyncMeta(KV_WFRULES_KEY);
|
||||||
|
trySyncWebfixRules();
|
||||||
|
},
|
||||||
|
[save, updateSyncMeta]
|
||||||
|
);
|
||||||
|
|
||||||
|
const add = useCallback(
|
||||||
|
async (rule) => {
|
||||||
|
const rules = [...list];
|
||||||
|
if (rules.map((item) => item.pattern).includes(rule.pattern)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
rules.unshift(rule);
|
||||||
|
await updateRules(rules);
|
||||||
|
},
|
||||||
|
[list, updateRules]
|
||||||
|
);
|
||||||
|
|
||||||
|
const del = useCallback(
|
||||||
|
async (pattern) => {
|
||||||
|
let rules = [...list];
|
||||||
|
rules = rules.filter((item) => item.pattern !== pattern);
|
||||||
|
await updateRules(rules);
|
||||||
|
},
|
||||||
|
[list, updateRules]
|
||||||
|
);
|
||||||
|
|
||||||
|
const put = useCallback(
|
||||||
|
async (pattern, obj) => {
|
||||||
|
const rules = [...list];
|
||||||
|
const rule = rules.find((r) => r.pattern === pattern);
|
||||||
|
rule && Object.assign(rule, obj);
|
||||||
|
await updateRules(rules);
|
||||||
|
},
|
||||||
|
[list, updateRules]
|
||||||
|
);
|
||||||
|
|
||||||
|
return { list, add, del, put };
|
||||||
|
}
|
||||||
13
src/libs/blacklist.js
Normal file
13
src/libs/blacklist.js
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import { isMatch } from "./utils";
|
||||||
|
import { DEFAULT_BLACKLIST } from "../config";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查是否在黑名单中
|
||||||
|
* @param {*} href
|
||||||
|
* @param {*} param1
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
export const isInBlacklist = (
|
||||||
|
href,
|
||||||
|
{ blacklist = DEFAULT_BLACKLIST.join(",\n") }
|
||||||
|
) => blacklist.split(",").some((url) => isMatch(href, url.trim()));
|
||||||
@@ -6,14 +6,11 @@ import {
|
|||||||
MSG_FETCH_LIMIT,
|
MSG_FETCH_LIMIT,
|
||||||
MSG_FETCH_CLEAR,
|
MSG_FETCH_CLEAR,
|
||||||
CACHE_NAME,
|
CACHE_NAME,
|
||||||
OPT_TRANS_MICROSOFT,
|
|
||||||
OPT_TRANS_DEEPL,
|
|
||||||
OPT_TRANS_OPENAI,
|
|
||||||
DEFAULT_FETCH_INTERVAL,
|
DEFAULT_FETCH_INTERVAL,
|
||||||
DEFAULT_FETCH_LIMIT,
|
DEFAULT_FETCH_LIMIT,
|
||||||
} from "../config";
|
} from "../config";
|
||||||
import { msAuth } from "./auth";
|
|
||||||
import { isBg } from "./browser";
|
import { isBg } from "./browser";
|
||||||
|
import { newCacheReq, newTransReq } from "./req";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 油猴脚本的请求封装
|
* 油猴脚本的请求封装
|
||||||
@@ -28,57 +25,38 @@ export const fetchGM = async (input, { method = "GET", headers, body } = {}) =>
|
|||||||
url: input,
|
url: input,
|
||||||
headers,
|
headers,
|
||||||
data: body,
|
data: body,
|
||||||
onload: ({ response, responseHeaders, status, statusText }) => {
|
// withCredentials: true,
|
||||||
const headers = new Headers();
|
onload: ({ response, responseHeaders, status, statusText, ...opts }) => {
|
||||||
|
const headers = {};
|
||||||
responseHeaders.split("\n").forEach((line) => {
|
responseHeaders.split("\n").forEach((line) => {
|
||||||
const [name, value] = line.split(":").map((item) => item.trim());
|
const [name, value] = line.split(":").map((item) => item.trim());
|
||||||
if (name && value) {
|
if (name && value) {
|
||||||
headers.append(name, value);
|
headers[name] = value;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
resolve(
|
resolve({
|
||||||
new Response(response, {
|
body: response,
|
||||||
headers,
|
headers,
|
||||||
status,
|
status,
|
||||||
statusText,
|
statusText,
|
||||||
})
|
});
|
||||||
);
|
|
||||||
},
|
},
|
||||||
onerror: reject,
|
onerror: reject,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
|
||||||
* 构造缓存 request
|
|
||||||
* @param {*} request
|
|
||||||
* @returns
|
|
||||||
*/
|
|
||||||
const newCacheReq = async (request) => {
|
|
||||||
if (request.method !== "GET") {
|
|
||||||
const body = await request.text();
|
|
||||||
const cacheUrl = new URL(request.url);
|
|
||||||
cacheUrl.pathname += body;
|
|
||||||
request = new Request(cacheUrl.toString(), { method: "GET" });
|
|
||||||
}
|
|
||||||
|
|
||||||
return request;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发起请求
|
* 发起请求
|
||||||
* @param {*} param0
|
* @param {*} param0
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export const fetchApi = async ({ input, init = {}, translator, token }) => {
|
export const fetchApi = async ({ input, init, transOpts, apiSetting }) => {
|
||||||
if (token) {
|
if (transOpts?.translator) {
|
||||||
if (translator === OPT_TRANS_DEEPL) {
|
[input, init] = await newTransReq(transOpts, apiSetting);
|
||||||
init.headers["Authorization"] = `DeepL-Auth-Key ${token}`; // DeepL
|
}
|
||||||
} else if (translator === OPT_TRANS_OPENAI) {
|
|
||||||
init.headers["Authorization"] = `Bearer ${token}`; // OpenAI
|
if (!input) {
|
||||||
init.headers["api-key"] = token; // Azure OpenAI
|
throw new Error("url is empty");
|
||||||
} else {
|
|
||||||
init.headers["Authorization"] = `Bearer ${token}`; // Microsoft & others
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isGm) {
|
if (isGm) {
|
||||||
@@ -88,19 +66,26 @@ export const fetchApi = async ({ input, init = {}, translator, token }) => {
|
|||||||
} else {
|
} else {
|
||||||
info = GM.info;
|
info = GM.info;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tampermonkey --> .connects
|
// Tampermonkey --> .connects
|
||||||
// Violentmonkey --> .connect
|
// Violentmonkey --> .connect
|
||||||
const connects = info?.script?.connects || info?.script?.connect || [];
|
const connects = info?.script?.connects || info?.script?.connect || [];
|
||||||
const url = new URL(input);
|
const url = new URL(input);
|
||||||
const isSafe = connects.find((item) => url.hostname.endsWith(item));
|
const isSafe = connects.find((item) => url.hostname.endsWith(item));
|
||||||
|
|
||||||
if (isSafe) {
|
if (isSafe) {
|
||||||
if (window.KISS_GM) {
|
const { body, headers, status, statusText } = window.KISS_GM
|
||||||
return window.KISS_GM.fetch(input, init);
|
? await window.KISS_GM.fetch(input, init)
|
||||||
} else {
|
: await fetchGM(input, init);
|
||||||
return fetchGM(input, init);
|
|
||||||
}
|
return new Response(body, {
|
||||||
|
headers: new Headers(headers),
|
||||||
|
status,
|
||||||
|
statusText,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return fetch(input, init);
|
return fetch(input, init);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -109,13 +94,7 @@ export const fetchApi = async ({ input, init = {}, translator, token }) => {
|
|||||||
*/
|
*/
|
||||||
export const fetchPool = taskPool(
|
export const fetchPool = taskPool(
|
||||||
fetchApi,
|
fetchApi,
|
||||||
async ({ translator }) => {
|
null,
|
||||||
if (translator === OPT_TRANS_MICROSOFT) {
|
|
||||||
const [token] = await msAuth();
|
|
||||||
return { token };
|
|
||||||
}
|
|
||||||
return {};
|
|
||||||
},
|
|
||||||
DEFAULT_FETCH_INTERVAL,
|
DEFAULT_FETCH_INTERVAL,
|
||||||
DEFAULT_FETCH_LIMIT
|
DEFAULT_FETCH_LIMIT
|
||||||
);
|
);
|
||||||
@@ -128,9 +107,9 @@ export const fetchPool = taskPool(
|
|||||||
*/
|
*/
|
||||||
export const fetchData = async (
|
export const fetchData = async (
|
||||||
input,
|
input,
|
||||||
{ useCache, usePool, translator, token, ...init } = {}
|
{ useCache, usePool, transOpts, apiSetting, ...init } = {}
|
||||||
) => {
|
) => {
|
||||||
const cacheReq = await newCacheReq(new Request(input, init));
|
const cacheReq = await newCacheReq(input, init);
|
||||||
let res;
|
let res;
|
||||||
|
|
||||||
// 查询缓存
|
// 查询缓存
|
||||||
@@ -146,13 +125,19 @@ export const fetchData = async (
|
|||||||
if (!res) {
|
if (!res) {
|
||||||
// 发送请求
|
// 发送请求
|
||||||
if (usePool) {
|
if (usePool) {
|
||||||
res = await fetchPool.push({ input, init, translator, token });
|
res = await fetchPool.push({ input, init, transOpts, apiSetting });
|
||||||
} else {
|
} else {
|
||||||
res = await fetchApi({ input, init, translator, token });
|
res = await fetchApi({ input, init, transOpts, apiSetting });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!res?.ok) {
|
if (!res?.ok) {
|
||||||
throw new Error(`response: ${res.statusText}`);
|
const cause = {
|
||||||
|
status: res.status,
|
||||||
|
};
|
||||||
|
if (res.headers.get("Content-Type")?.includes("json")) {
|
||||||
|
cause.body = await res.json();
|
||||||
|
}
|
||||||
|
throw new Error(`response: [${res.status}] ${res.statusText}`, { cause });
|
||||||
}
|
}
|
||||||
|
|
||||||
// 插入缓存
|
// 插入缓存
|
||||||
@@ -180,7 +165,7 @@ export const fetchData = async (
|
|||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export const fetchPolyfill = async (input, opts) => {
|
export const fetchPolyfill = async (input, opts) => {
|
||||||
if (!input.trim()) {
|
if (!input?.trim()) {
|
||||||
throw new Error("URL is empty");
|
throw new Error("URL is empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,7 +173,7 @@ export const fetchPolyfill = async (input, opts) => {
|
|||||||
if (isExt && !isBg()) {
|
if (isExt && !isBg()) {
|
||||||
const res = await sendBgMsg(MSG_FETCH, { input, opts });
|
const res = await sendBgMsg(MSG_FETCH, { input, opts });
|
||||||
if (res.error) {
|
if (res.error) {
|
||||||
throw new Error(res.error);
|
throw new Error(res.error, { cause: res.cause });
|
||||||
}
|
}
|
||||||
return res.data;
|
return res.data;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,6 @@ export const sendIframeMsg = (action, args) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const sendPrentMsg = (action, args) => {
|
export const sendParentMsg = (action, args) => {
|
||||||
window.parent.postMessage({ action, args }, "*");
|
window.parent.postMessage({ action, args }, "*");
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { CACHE_NAME } from "../config";
|
import { CACHE_NAME } from "../config";
|
||||||
import { browser } from "./browser";
|
import { browser } from "./browser";
|
||||||
|
import { apiBaiduLangdetect } from "../apis";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 清除缓存数据
|
* 清除缓存数据
|
||||||
@@ -13,15 +14,29 @@ export const tryClearCaches = async () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 本地语言识别
|
* 语言识别
|
||||||
* @param {*} q
|
* @param {*} q
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export const tryDetectLang = async (q) => {
|
export const tryDetectLang = async (q, useRemote = false) => {
|
||||||
try {
|
let lang = "";
|
||||||
const res = await browser?.i18n?.detectLanguage(q);
|
|
||||||
return res?.languages?.[0]?.language;
|
if (useRemote) {
|
||||||
} catch (err) {
|
try {
|
||||||
console.log("[detect lang]", err.message);
|
lang = await apiBaiduLangdetect(q);
|
||||||
|
} catch (err) {
|
||||||
|
console.log("[detect lang remote]", err.message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!lang) {
|
||||||
|
try {
|
||||||
|
const res = await browser?.i18n?.detectLanguage(q);
|
||||||
|
lang = res?.languages?.[0]?.language;
|
||||||
|
} catch (err) {
|
||||||
|
console.log("[detect lang local]", err.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return lang;
|
||||||
};
|
};
|
||||||
|
|||||||
205
src/libs/inputTranslate.js
Normal file
205
src/libs/inputTranslate.js
Normal file
@@ -0,0 +1,205 @@
|
|||||||
|
import {
|
||||||
|
DEFAULT_INPUT_RULE,
|
||||||
|
DEFAULT_TRANS_APIS,
|
||||||
|
DEFAULT_INPUT_SHORTCUT,
|
||||||
|
OPT_LANGS_LIST,
|
||||||
|
} from "../config";
|
||||||
|
import { genEventName, removeEndchar, matchInputStr, sleep } from "./utils";
|
||||||
|
import { stepShortcutRegister } from "./shortcut";
|
||||||
|
import { apiTranslate } from "../apis";
|
||||||
|
import { tryDetectLang } from ".";
|
||||||
|
import { loadingSvg } from "./svg";
|
||||||
|
|
||||||
|
function isInputNode(node) {
|
||||||
|
return node.nodeName === "INPUT" || node.nodeName === "TEXTAREA";
|
||||||
|
}
|
||||||
|
|
||||||
|
function isEditAbleNode(node) {
|
||||||
|
return node.hasAttribute("contenteditable");
|
||||||
|
}
|
||||||
|
|
||||||
|
function selectContent(node) {
|
||||||
|
node.focus();
|
||||||
|
const range = document.createRange();
|
||||||
|
range.selectNodeContents(node);
|
||||||
|
|
||||||
|
const selection = window.getSelection();
|
||||||
|
selection.removeAllRanges();
|
||||||
|
selection.addRange(range);
|
||||||
|
}
|
||||||
|
|
||||||
|
function pasteContentEvent(node, text) {
|
||||||
|
node.focus();
|
||||||
|
const data = new DataTransfer();
|
||||||
|
data.setData("text/plain", text);
|
||||||
|
|
||||||
|
const event = new ClipboardEvent("paste", { clipboardData: data });
|
||||||
|
document.dispatchEvent(event);
|
||||||
|
data.clearData();
|
||||||
|
}
|
||||||
|
|
||||||
|
function pasteContentCommand(node, text) {
|
||||||
|
node.focus();
|
||||||
|
document.execCommand("insertText", false, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
function collapseToEnd(node) {
|
||||||
|
node.focus();
|
||||||
|
const selection = window.getSelection();
|
||||||
|
selection.collapseToEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
function getNodeText(node) {
|
||||||
|
if (isInputNode(node)) {
|
||||||
|
return node.value;
|
||||||
|
}
|
||||||
|
return node.innerText || node.textContent || "";
|
||||||
|
}
|
||||||
|
|
||||||
|
function addLoading(node, loadingId) {
|
||||||
|
const div = document.createElement("div");
|
||||||
|
div.id = loadingId;
|
||||||
|
div.innerHTML = loadingSvg;
|
||||||
|
div.style.cssText = `
|
||||||
|
width: ${node.offsetWidth}px;
|
||||||
|
height: ${node.offsetHeight}px;
|
||||||
|
line-height: ${node.offsetHeight}px;
|
||||||
|
position: absolute;
|
||||||
|
text-align: center;
|
||||||
|
left: ${node.offsetLeft}px;
|
||||||
|
top: ${node.offsetTop}px;
|
||||||
|
z-index: 2147483647;
|
||||||
|
`;
|
||||||
|
node.offsetParent?.appendChild(div);
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeLoading(node, loadingId) {
|
||||||
|
const div = node.offsetParent.querySelector(`#${loadingId}`);
|
||||||
|
if (div) {
|
||||||
|
div.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 输入框翻译
|
||||||
|
*/
|
||||||
|
export default function inputTranslate ({
|
||||||
|
inputRule: {
|
||||||
|
transOpen,
|
||||||
|
triggerShortcut,
|
||||||
|
translator,
|
||||||
|
fromLang,
|
||||||
|
toLang,
|
||||||
|
triggerCount,
|
||||||
|
triggerTime,
|
||||||
|
transSign,
|
||||||
|
} = DEFAULT_INPUT_RULE,
|
||||||
|
transApis,
|
||||||
|
detectRemote,
|
||||||
|
}) {
|
||||||
|
if (!transOpen) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const apiSetting = transApis?.[translator] || DEFAULT_TRANS_APIS[translator];
|
||||||
|
if (triggerShortcut.length === 0) {
|
||||||
|
triggerShortcut = DEFAULT_INPUT_SHORTCUT;
|
||||||
|
triggerCount = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
stepShortcutRegister(
|
||||||
|
triggerShortcut,
|
||||||
|
async () => {
|
||||||
|
let node = document.activeElement;
|
||||||
|
|
||||||
|
if (!node) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (node.shadowRoot) {
|
||||||
|
node = node.shadowRoot.activeElement;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isInputNode(node) && !isEditAbleNode(node)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let initText = getNodeText(node);
|
||||||
|
if (triggerShortcut.length === 1 && triggerShortcut[0].length === 1) {
|
||||||
|
// todo: remove multiple char
|
||||||
|
initText = removeEndchar(initText, triggerShortcut[0], triggerCount);
|
||||||
|
}
|
||||||
|
if (!initText.trim()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let text = initText;
|
||||||
|
if (transSign) {
|
||||||
|
const res = matchInputStr(text, transSign);
|
||||||
|
if (res) {
|
||||||
|
let lang = res[1];
|
||||||
|
if (lang === "zh" || lang === "cn") {
|
||||||
|
lang = "zh-CN";
|
||||||
|
} else if (lang === "tw" || lang === "hk") {
|
||||||
|
lang = "zh-TW";
|
||||||
|
}
|
||||||
|
if (lang && OPT_LANGS_LIST.includes(lang)) {
|
||||||
|
toLang = lang;
|
||||||
|
}
|
||||||
|
text = res[2];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// console.log("input -->", text);
|
||||||
|
|
||||||
|
const loadingId = "kiss-" + genEventName();
|
||||||
|
try {
|
||||||
|
addLoading(node, loadingId);
|
||||||
|
|
||||||
|
const deLang = await tryDetectLang(text, detectRemote);
|
||||||
|
if (deLang && toLang.includes(deLang)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const [trText, isSame] = await apiTranslate({
|
||||||
|
translator,
|
||||||
|
text,
|
||||||
|
fromLang,
|
||||||
|
toLang,
|
||||||
|
apiSetting,
|
||||||
|
});
|
||||||
|
if (!trText || isSame) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isInputNode(node)) {
|
||||||
|
node.value = trText;
|
||||||
|
node.dispatchEvent(
|
||||||
|
new Event("input", { bubbles: true, cancelable: true })
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
selectContent(node);
|
||||||
|
await sleep(200);
|
||||||
|
|
||||||
|
pasteContentEvent(node, trText);
|
||||||
|
await sleep(200);
|
||||||
|
|
||||||
|
// todo: use includes?
|
||||||
|
if (getNodeText(node).startsWith(initText)) {
|
||||||
|
pasteContentCommand(node, trText);
|
||||||
|
await sleep(100);
|
||||||
|
} else {
|
||||||
|
collapseToEnd(node);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.log("[translate input]", err.message);
|
||||||
|
} finally {
|
||||||
|
removeLoading(node, loadingId);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
triggerCount,
|
||||||
|
triggerTime
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -6,7 +6,13 @@
|
|||||||
* @param {*} _limit
|
* @param {*} _limit
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export const taskPool = (fn, preFn, _interval = 100, _limit = 100) => {
|
export const taskPool = (
|
||||||
|
fn,
|
||||||
|
preFn,
|
||||||
|
_interval = 100,
|
||||||
|
_limit = 100,
|
||||||
|
_retryInteral = 1000
|
||||||
|
) => {
|
||||||
const pool = [];
|
const pool = [];
|
||||||
const maxRetry = 2; // 最大重试次数
|
const maxRetry = 2; // 最大重试次数
|
||||||
let maxCount = _limit; // 最大数量
|
let maxCount = _limit; // 最大数量
|
||||||
@@ -14,23 +20,6 @@ export const taskPool = (fn, preFn, _interval = 100, _limit = 100) => {
|
|||||||
let interval = _interval; // 间隔时间
|
let interval = _interval; // 间隔时间
|
||||||
let timer = null;
|
let timer = null;
|
||||||
|
|
||||||
const handleTask = async (item, preArgs) => {
|
|
||||||
curCount++;
|
|
||||||
const { args, resolve, reject, retry } = item;
|
|
||||||
try {
|
|
||||||
const res = await fn({ ...args, ...preArgs });
|
|
||||||
resolve(res);
|
|
||||||
} catch (err) {
|
|
||||||
if (retry < maxRetry) {
|
|
||||||
pool.push({ args, resolve, reject, retry: retry + 1 });
|
|
||||||
} else {
|
|
||||||
reject(err);
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
curCount--;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const run = async () => {
|
const run = async () => {
|
||||||
// console.log("timer", timer);
|
// console.log("timer", timer);
|
||||||
timer && clearTimeout(timer);
|
timer && clearTimeout(timer);
|
||||||
@@ -39,12 +28,24 @@ export const taskPool = (fn, preFn, _interval = 100, _limit = 100) => {
|
|||||||
if (curCount < maxCount) {
|
if (curCount < maxCount) {
|
||||||
const item = pool.shift();
|
const item = pool.shift();
|
||||||
if (item) {
|
if (item) {
|
||||||
|
curCount++;
|
||||||
|
const { args, resolve, reject, retry } = item;
|
||||||
try {
|
try {
|
||||||
const preArgs = await preFn(item.args);
|
const preArgs = preFn ? await preFn(item.args) : {};
|
||||||
handleTask(item, preArgs);
|
const res = await fn({ ...args, ...preArgs });
|
||||||
|
resolve(res);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log("[preFn]", err);
|
console.log("[task]", retry, err);
|
||||||
pool.push(item);
|
if (retry < maxRetry) {
|
||||||
|
const retryTimer = setTimeout(() => {
|
||||||
|
clearTimeout(retryTimer);
|
||||||
|
pool.push({ args, resolve, reject, retry: retry + 1 });
|
||||||
|
}, _retryInteral);
|
||||||
|
} else {
|
||||||
|
reject(err);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
curCount--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
286
src/libs/req.js
Normal file
286
src/libs/req.js
Normal file
@@ -0,0 +1,286 @@
|
|||||||
|
import queryString from "query-string";
|
||||||
|
import {
|
||||||
|
OPT_TRANS_GOOGLE,
|
||||||
|
OPT_TRANS_MICROSOFT,
|
||||||
|
OPT_TRANS_DEEPL,
|
||||||
|
OPT_TRANS_DEEPLFREE,
|
||||||
|
OPT_TRANS_DEEPLX,
|
||||||
|
OPT_TRANS_BAIDU,
|
||||||
|
OPT_TRANS_TENCENT,
|
||||||
|
OPT_TRANS_OPENAI,
|
||||||
|
OPT_TRANS_GEMINI,
|
||||||
|
OPT_TRANS_CLOUDFLAREAI,
|
||||||
|
OPT_TRANS_CUSTOMIZE,
|
||||||
|
URL_MICROSOFT_TRAN,
|
||||||
|
URL_TENCENT_TRANSMART,
|
||||||
|
PROMPT_PLACE_FROM,
|
||||||
|
PROMPT_PLACE_TO,
|
||||||
|
PROMPT_PLACE_TEXT,
|
||||||
|
} from "../config";
|
||||||
|
import { msAuth } from "./auth";
|
||||||
|
import { genDeeplFree } from "../apis/deepl";
|
||||||
|
import { genBaidu } from "../apis/baidu";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造缓存 request
|
||||||
|
* @param {*} request
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
export const newCacheReq = async (input, init) => {
|
||||||
|
let request = new Request(input, init);
|
||||||
|
if (request.method !== "GET") {
|
||||||
|
const body = await request.text();
|
||||||
|
const cacheUrl = new URL(request.url);
|
||||||
|
cacheUrl.pathname += body;
|
||||||
|
request = new Request(cacheUrl.toString(), { method: "GET" });
|
||||||
|
}
|
||||||
|
|
||||||
|
return request;
|
||||||
|
};
|
||||||
|
|
||||||
|
const genGoogle = ({ text, from, to, url, key }) => {
|
||||||
|
const params = {
|
||||||
|
client: "gtx",
|
||||||
|
dt: "t",
|
||||||
|
dj: 1,
|
||||||
|
ie: "UTF-8",
|
||||||
|
sl: from,
|
||||||
|
tl: to,
|
||||||
|
q: text,
|
||||||
|
};
|
||||||
|
const input = `${url}?${queryString.stringify(params)}`;
|
||||||
|
const init = {
|
||||||
|
headers: {
|
||||||
|
"Content-type": "application/json",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
if (key) {
|
||||||
|
init.headers.Authorization = `Bearer ${key}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [input, init];
|
||||||
|
};
|
||||||
|
|
||||||
|
const genMicrosoft = async ({ text, from, to }) => {
|
||||||
|
const [token] = await msAuth();
|
||||||
|
const params = {
|
||||||
|
from,
|
||||||
|
to,
|
||||||
|
"api-version": "3.0",
|
||||||
|
};
|
||||||
|
const input = `${URL_MICROSOFT_TRAN}?${queryString.stringify(params)}`;
|
||||||
|
const init = {
|
||||||
|
headers: {
|
||||||
|
"Content-type": "application/json",
|
||||||
|
Authorization: `Bearer ${token}`,
|
||||||
|
},
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify([{ Text: text }]),
|
||||||
|
};
|
||||||
|
|
||||||
|
return [input, init];
|
||||||
|
};
|
||||||
|
|
||||||
|
const genDeepl = ({ text, from, to, url, key }) => {
|
||||||
|
const data = {
|
||||||
|
text: [text],
|
||||||
|
target_lang: to,
|
||||||
|
source_lang: from,
|
||||||
|
// split_sentences: "0",
|
||||||
|
};
|
||||||
|
const init = {
|
||||||
|
headers: {
|
||||||
|
"Content-type": "application/json",
|
||||||
|
Authorization: `DeepL-Auth-Key ${key}`,
|
||||||
|
},
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify(data),
|
||||||
|
};
|
||||||
|
|
||||||
|
return [url, init];
|
||||||
|
};
|
||||||
|
|
||||||
|
const genDeeplX = ({ text, from, to, url, key }) => {
|
||||||
|
const data = {
|
||||||
|
text,
|
||||||
|
target_lang: to,
|
||||||
|
source_lang: from,
|
||||||
|
};
|
||||||
|
|
||||||
|
const init = {
|
||||||
|
headers: {
|
||||||
|
"Content-type": "application/json",
|
||||||
|
},
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify(data),
|
||||||
|
};
|
||||||
|
if (key) {
|
||||||
|
init.headers.Authorization = `Bearer ${key}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [url, init];
|
||||||
|
};
|
||||||
|
|
||||||
|
const genTencent = ({ text, from, to }) => {
|
||||||
|
const data = {
|
||||||
|
header: {
|
||||||
|
fn: "auto_translation_block",
|
||||||
|
},
|
||||||
|
source: {
|
||||||
|
text_block: text,
|
||||||
|
lang: from,
|
||||||
|
},
|
||||||
|
target: {
|
||||||
|
lang: to,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const init = {
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify(data),
|
||||||
|
};
|
||||||
|
|
||||||
|
return [URL_TENCENT_TRANSMART, init];
|
||||||
|
};
|
||||||
|
|
||||||
|
const genOpenAI = ({ text, from, to, url, key, prompt, model }) => {
|
||||||
|
prompt = prompt
|
||||||
|
.replaceAll(PROMPT_PLACE_FROM, from)
|
||||||
|
.replaceAll(PROMPT_PLACE_TO, to);
|
||||||
|
|
||||||
|
const data = {
|
||||||
|
model,
|
||||||
|
messages: [
|
||||||
|
{
|
||||||
|
role: "system",
|
||||||
|
content: prompt,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
role: "user",
|
||||||
|
content: text,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
temperature: 0,
|
||||||
|
max_tokens: 256,
|
||||||
|
};
|
||||||
|
|
||||||
|
const init = {
|
||||||
|
headers: {
|
||||||
|
"Content-type": "application/json",
|
||||||
|
Authorization: `Bearer ${key}`, // OpenAI
|
||||||
|
"api-key": key, // Azure OpenAI
|
||||||
|
},
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify(data),
|
||||||
|
};
|
||||||
|
|
||||||
|
return [url, init];
|
||||||
|
};
|
||||||
|
|
||||||
|
const genGemini = ({ text, from, to, url, key, prompt, model }) => {
|
||||||
|
prompt = prompt
|
||||||
|
.replaceAll(PROMPT_PLACE_FROM, from)
|
||||||
|
.replaceAll(PROMPT_PLACE_TO, to)
|
||||||
|
.replaceAll(PROMPT_PLACE_TEXT, text);
|
||||||
|
|
||||||
|
const data = {
|
||||||
|
contents: [
|
||||||
|
{
|
||||||
|
// role: "user",
|
||||||
|
parts: [
|
||||||
|
{
|
||||||
|
text: prompt,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
const input = `${url}/${model}:generateContent?key=${key}`;
|
||||||
|
const init = {
|
||||||
|
headers: {
|
||||||
|
"Content-type": "application/json",
|
||||||
|
},
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify(data),
|
||||||
|
};
|
||||||
|
|
||||||
|
return [input, init];
|
||||||
|
};
|
||||||
|
|
||||||
|
const genCloudflareAI = ({ text, from, to, url, key }) => {
|
||||||
|
const data = {
|
||||||
|
text,
|
||||||
|
source_lang: from,
|
||||||
|
target_lang: to,
|
||||||
|
};
|
||||||
|
|
||||||
|
const init = {
|
||||||
|
headers: {
|
||||||
|
"Content-type": "application/json",
|
||||||
|
Authorization: `Bearer ${key}`,
|
||||||
|
},
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify(data),
|
||||||
|
};
|
||||||
|
|
||||||
|
return [url, init];
|
||||||
|
};
|
||||||
|
|
||||||
|
const genCustom = ({ text, from, to, url, key }) => {
|
||||||
|
const data = {
|
||||||
|
text,
|
||||||
|
from,
|
||||||
|
to,
|
||||||
|
};
|
||||||
|
const init = {
|
||||||
|
headers: {
|
||||||
|
"Content-type": "application/json",
|
||||||
|
},
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify(data),
|
||||||
|
};
|
||||||
|
if (key) {
|
||||||
|
init.headers.Authorization = `Bearer ${key}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [url, init];
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造翻译接口 request
|
||||||
|
* @param {*}
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
export const newTransReq = ({ translator, text, from, to }, apiSetting) => {
|
||||||
|
const args = { text, from, to, ...apiSetting };
|
||||||
|
switch (translator) {
|
||||||
|
case OPT_TRANS_GOOGLE:
|
||||||
|
return genGoogle(args);
|
||||||
|
case OPT_TRANS_MICROSOFT:
|
||||||
|
return genMicrosoft(args);
|
||||||
|
case OPT_TRANS_DEEPL:
|
||||||
|
return genDeepl(args);
|
||||||
|
case OPT_TRANS_DEEPLFREE:
|
||||||
|
return genDeeplFree(args);
|
||||||
|
case OPT_TRANS_DEEPLX:
|
||||||
|
return genDeeplX(args);
|
||||||
|
case OPT_TRANS_BAIDU:
|
||||||
|
return genBaidu(args);
|
||||||
|
case OPT_TRANS_TENCENT:
|
||||||
|
return genTencent(args);
|
||||||
|
case OPT_TRANS_OPENAI:
|
||||||
|
return genOpenAI(args);
|
||||||
|
case OPT_TRANS_GEMINI:
|
||||||
|
return genGemini(args);
|
||||||
|
case OPT_TRANS_CLOUDFLAREAI:
|
||||||
|
return genCloudflareAI(args);
|
||||||
|
case OPT_TRANS_CUSTOMIZE:
|
||||||
|
return genCustom(args);
|
||||||
|
default:
|
||||||
|
throw new Error(`[trans] translator: ${translator} not support`);
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -21,7 +21,6 @@ import { trySyncRules } from "./sync";
|
|||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export const matchRule = async (
|
export const matchRule = async (
|
||||||
rules,
|
|
||||||
href,
|
href,
|
||||||
{
|
{
|
||||||
injectRules = true,
|
injectRules = true,
|
||||||
@@ -29,7 +28,7 @@ export const matchRule = async (
|
|||||||
owSubrule = DEFAULT_OW_RULE,
|
owSubrule = DEFAULT_OW_RULE,
|
||||||
}
|
}
|
||||||
) => {
|
) => {
|
||||||
rules = [...rules];
|
const rules = await getRulesWithDefault();
|
||||||
if (injectRules) {
|
if (injectRules) {
|
||||||
try {
|
try {
|
||||||
const selectedSub = subrulesList.find((item) => item.selected);
|
const selectedSub = subrulesList.find((item) => item.selected);
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
import {
|
import {
|
||||||
STOKEY_SETTING,
|
STOKEY_SETTING,
|
||||||
STOKEY_RULES,
|
STOKEY_RULES,
|
||||||
|
STOKEY_WFRULES,
|
||||||
|
STOKEY_WORDS,
|
||||||
STOKEY_FAB,
|
STOKEY_FAB,
|
||||||
STOKEY_SYNC,
|
STOKEY_SYNC,
|
||||||
STOKEY_MSAUTH,
|
STOKEY_MSAUTH,
|
||||||
|
STOKEY_BDAUTH,
|
||||||
STOKEY_RULESCACHE_PREFIX,
|
STOKEY_RULESCACHE_PREFIX,
|
||||||
STOKEY_WEBFIXCACHE_PREFIX,
|
STOKEY_WEBFIXCACHE_PREFIX,
|
||||||
DEFAULT_SETTING,
|
DEFAULT_SETTING,
|
||||||
@@ -96,6 +99,21 @@ export const getRulesWithDefault = async () =>
|
|||||||
(await getRules()) || DEFAULT_RULES;
|
(await getRules()) || DEFAULT_RULES;
|
||||||
export const setRules = (val) => setObj(STOKEY_RULES, val);
|
export const setRules = (val) => setObj(STOKEY_RULES, val);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修复规则列表
|
||||||
|
*/
|
||||||
|
export const getWebfixRules = () => getObj(STOKEY_WFRULES);
|
||||||
|
export const getWebfixRulesWithDefault = async () =>
|
||||||
|
(await getWebfixRules()) || [];
|
||||||
|
export const setWebfixRules = (val) => setObj(STOKEY_WFRULES, val);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 词汇列表
|
||||||
|
*/
|
||||||
|
export const getWords = () => getObj(STOKEY_WORDS);
|
||||||
|
export const getWordsWithDefault = async () => (await getWords()) || {};
|
||||||
|
export const setWords = (val) => setObj(STOKEY_WORDS, val);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 订阅规则
|
* 订阅规则
|
||||||
*/
|
*/
|
||||||
@@ -134,6 +152,12 @@ export const updateSync = (obj) => putObj(STOKEY_SYNC, obj);
|
|||||||
export const getMsauth = () => getObj(STOKEY_MSAUTH);
|
export const getMsauth = () => getObj(STOKEY_MSAUTH);
|
||||||
export const setMsauth = (val) => setObj(STOKEY_MSAUTH, val);
|
export const setMsauth = (val) => setObj(STOKEY_MSAUTH, val);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* baidu auth
|
||||||
|
*/
|
||||||
|
export const getBdauth = () => getObj(STOKEY_BDAUTH);
|
||||||
|
export const setBdauth = (val) => setObj(STOKEY_BDAUTH, val);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 存入默认数据
|
* 存入默认数据
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ import {
|
|||||||
APP_LCNAME,
|
APP_LCNAME,
|
||||||
KV_SETTING_KEY,
|
KV_SETTING_KEY,
|
||||||
KV_RULES_KEY,
|
KV_RULES_KEY,
|
||||||
|
KV_WFRULES_KEY,
|
||||||
|
KV_WORDS_KEY,
|
||||||
KV_RULES_SHARE_KEY,
|
KV_RULES_SHARE_KEY,
|
||||||
KV_SALT_SHARE,
|
KV_SALT_SHARE,
|
||||||
OPT_SYNCTYPE_WEBDAV,
|
OPT_SYNCTYPE_WEBDAV,
|
||||||
@@ -11,8 +13,12 @@ import {
|
|||||||
updateSync,
|
updateSync,
|
||||||
getSettingWithDefault,
|
getSettingWithDefault,
|
||||||
getRulesWithDefault,
|
getRulesWithDefault,
|
||||||
|
getWordsWithDefault,
|
||||||
|
getWebfixRulesWithDefault,
|
||||||
setSetting,
|
setSetting,
|
||||||
setRules,
|
setRules,
|
||||||
|
setWebfixRules,
|
||||||
|
setWords,
|
||||||
} from "./storage";
|
} from "./storage";
|
||||||
import { apiSyncData } from "../apis";
|
import { apiSyncData } from "../apis";
|
||||||
import { sha256, removeEndchar } from "./utils";
|
import { sha256, removeEndchar } from "./utils";
|
||||||
@@ -135,6 +141,44 @@ export const trySyncRules = async () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 同步修复规则
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
const syncWebfixRules = async () => {
|
||||||
|
const res = await syncData(KV_WFRULES_KEY, getWebfixRulesWithDefault);
|
||||||
|
if (res?.isNew) {
|
||||||
|
await setWebfixRules(res.value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const trySyncWebfixRules = async () => {
|
||||||
|
try {
|
||||||
|
await syncWebfixRules();
|
||||||
|
} catch (err) {
|
||||||
|
console.log("[sync user webfix rules]", err);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 同步词汇
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
const syncWords = async () => {
|
||||||
|
const res = await syncData(KV_WORDS_KEY, getWordsWithDefault);
|
||||||
|
if (res?.isNew) {
|
||||||
|
await setWords(res.value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const trySyncWords = async () => {
|
||||||
|
try {
|
||||||
|
await syncWords();
|
||||||
|
} catch (err) {
|
||||||
|
console.log("[sync fav words]", err);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 同步分享规则
|
* 同步分享规则
|
||||||
* @param {*} param0
|
* @param {*} param0
|
||||||
@@ -163,9 +207,13 @@ export const syncShareRules = async ({ rules, syncUrl, syncKey }) => {
|
|||||||
export const syncSettingAndRules = async () => {
|
export const syncSettingAndRules = async () => {
|
||||||
await syncSetting();
|
await syncSetting();
|
||||||
await syncRules();
|
await syncRules();
|
||||||
|
await syncWebfixRules();
|
||||||
|
await syncWords();
|
||||||
};
|
};
|
||||||
|
|
||||||
export const trySyncSettingAndRules = async () => {
|
export const trySyncSettingAndRules = async () => {
|
||||||
await trySyncSetting();
|
await trySyncSetting();
|
||||||
await trySyncRules();
|
await trySyncRules();
|
||||||
|
await trySyncWebfixRules();
|
||||||
|
await trySyncWords();
|
||||||
};
|
};
|
||||||
|
|||||||
12
src/libs/touch.js
Normal file
12
src/libs/touch.js
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
export function touchTapListener(fn, touchsLength) {
|
||||||
|
const handleTouchend = (e) => {
|
||||||
|
if (e.touches.length === touchsLength) {
|
||||||
|
fn();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
document.addEventListener("touchstart", handleTouchend);
|
||||||
|
return () => {
|
||||||
|
document.removeEventListener("touchstart", handleTouchend);
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -9,101 +9,16 @@ import {
|
|||||||
SHADOW_KEY,
|
SHADOW_KEY,
|
||||||
OPT_MOUSEKEY_DISABLE,
|
OPT_MOUSEKEY_DISABLE,
|
||||||
OPT_MOUSEKEY_MOUSEOVER,
|
OPT_MOUSEKEY_MOUSEOVER,
|
||||||
DEFAULT_INPUT_RULE,
|
|
||||||
DEFAULT_TRANS_APIS,
|
|
||||||
DEFAULT_INPUT_SHORTCUT,
|
|
||||||
OPT_LANGS_LIST,
|
|
||||||
} from "../config";
|
} from "../config";
|
||||||
import Content from "../views/Content";
|
import Content from "../views/Content";
|
||||||
import { updateFetchPool, clearFetchPool } from "./fetch";
|
import { updateFetchPool, clearFetchPool } from "./fetch";
|
||||||
import {
|
import { debounce, genEventName } from "./utils";
|
||||||
debounce,
|
|
||||||
genEventName,
|
|
||||||
removeEndchar,
|
|
||||||
matchInputStr,
|
|
||||||
sleep,
|
|
||||||
} from "./utils";
|
|
||||||
import { stepShortcutRegister } from "./shortcut";
|
|
||||||
import { apiTranslate } from "../apis";
|
|
||||||
import { tryDetectLang } from ".";
|
|
||||||
import { loadingSvg } from "./svg";
|
|
||||||
|
|
||||||
function isInputNode(node) {
|
|
||||||
return node.nodeName === "INPUT" || node.nodeName === "TEXTAREA";
|
|
||||||
}
|
|
||||||
|
|
||||||
function isEditAbleNode(node) {
|
|
||||||
return node.hasAttribute("contenteditable");
|
|
||||||
}
|
|
||||||
|
|
||||||
function selectContent(node) {
|
|
||||||
node.focus();
|
|
||||||
const range = document.createRange();
|
|
||||||
range.selectNodeContents(node);
|
|
||||||
|
|
||||||
const selection = window.getSelection();
|
|
||||||
selection.removeAllRanges();
|
|
||||||
selection.addRange(range);
|
|
||||||
}
|
|
||||||
|
|
||||||
function pasteContentEvent(node, text) {
|
|
||||||
node.focus();
|
|
||||||
const data = new DataTransfer();
|
|
||||||
data.setData("text/plain", text);
|
|
||||||
|
|
||||||
const event = new ClipboardEvent("paste", { clipboardData: data });
|
|
||||||
document.dispatchEvent(event);
|
|
||||||
data.clearData();
|
|
||||||
}
|
|
||||||
|
|
||||||
function pasteContentCommand(node, text) {
|
|
||||||
node.focus();
|
|
||||||
document.execCommand("insertText", false, text);
|
|
||||||
}
|
|
||||||
|
|
||||||
function collapseToEnd(node) {
|
|
||||||
node.focus();
|
|
||||||
const selection = window.getSelection();
|
|
||||||
selection.collapseToEnd();
|
|
||||||
}
|
|
||||||
|
|
||||||
function getNodeText(node) {
|
|
||||||
if (isInputNode(node)) {
|
|
||||||
return node.value;
|
|
||||||
}
|
|
||||||
return node.innerText || node.textContent || "";
|
|
||||||
}
|
|
||||||
|
|
||||||
function addLoading(node, loadingId) {
|
|
||||||
const div = document.createElement("div");
|
|
||||||
div.id = loadingId;
|
|
||||||
div.innerHTML = loadingSvg;
|
|
||||||
div.style.cssText = `
|
|
||||||
width: ${node.offsetWidth}px;
|
|
||||||
height: ${node.offsetHeight}px;
|
|
||||||
line-height: ${node.offsetHeight}px;
|
|
||||||
position: absolute;
|
|
||||||
text-align: center;
|
|
||||||
left: ${node.offsetLeft}px;
|
|
||||||
top: ${node.offsetTop}px;
|
|
||||||
z-index: 2147483647;
|
|
||||||
`;
|
|
||||||
node.offsetParent?.appendChild(div);
|
|
||||||
}
|
|
||||||
|
|
||||||
function removeLoading(node, loadingId) {
|
|
||||||
const div = node.offsetParent.querySelector(`#${loadingId}`);
|
|
||||||
if (div) {
|
|
||||||
div.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 翻译类
|
* 翻译类
|
||||||
*/
|
*/
|
||||||
export class Translator {
|
export class Translator {
|
||||||
_rule = {};
|
_rule = {};
|
||||||
_inputRule = {};
|
|
||||||
_setting = {};
|
_setting = {};
|
||||||
_rootNodes = new Set();
|
_rootNodes = new Set();
|
||||||
_tranNodes = new Map();
|
_tranNodes = new Map();
|
||||||
@@ -124,6 +39,7 @@ export class Translator {
|
|||||||
"iframe",
|
"iframe",
|
||||||
];
|
];
|
||||||
_eventName = genEventName();
|
_eventName = genEventName();
|
||||||
|
_mouseoverNode = null;
|
||||||
|
|
||||||
// 显示
|
// 显示
|
||||||
_interseObserver = new IntersectionObserver(
|
_interseObserver = new IntersectionObserver(
|
||||||
@@ -186,11 +102,6 @@ export class Translator {
|
|||||||
if (rule.transOpen === "true") {
|
if (rule.transOpen === "true") {
|
||||||
this._register();
|
this._register();
|
||||||
}
|
}
|
||||||
|
|
||||||
this._inputRule = setting.inputRule || DEFAULT_INPUT_RULE;
|
|
||||||
if (this._inputRule.transOpen) {
|
|
||||||
this._registerInput();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get setting() {
|
get setting() {
|
||||||
@@ -336,144 +247,65 @@ export class Translator {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
this._tranNodes.forEach((_, node) => {
|
if (
|
||||||
if (
|
!this._setting.mouseKey ||
|
||||||
!this._setting.mouseKey ||
|
this._setting.mouseKey === OPT_MOUSEKEY_DISABLE
|
||||||
this._setting.mouseKey === OPT_MOUSEKEY_DISABLE
|
) {
|
||||||
) {
|
// 监听节点显示
|
||||||
// 监听节点显示
|
this._tranNodes.forEach((_, node) => {
|
||||||
this._interseObserver.observe(node);
|
this._interseObserver.observe(node);
|
||||||
} else {
|
});
|
||||||
// 监听鼠标悬停
|
} else {
|
||||||
node.addEventListener("mouseover", this._handleMouseover);
|
// 监听鼠标悬停
|
||||||
}
|
window.addEventListener("keydown", this._handleKeydown);
|
||||||
});
|
this._tranNodes.forEach((_, node) => {
|
||||||
};
|
node.addEventListener("mouseenter", this._handleMouseover);
|
||||||
|
node.addEventListener("mouseleave", this._handleMouseout);
|
||||||
_registerInput = () => {
|
});
|
||||||
const {
|
|
||||||
triggerShortcut: initTriggerShortcut,
|
|
||||||
translator,
|
|
||||||
fromLang,
|
|
||||||
toLang: initToLang,
|
|
||||||
triggerCount: initTriggerCount,
|
|
||||||
triggerTime,
|
|
||||||
transSign,
|
|
||||||
} = this._inputRule;
|
|
||||||
const apiSetting = (this._setting.transApis || DEFAULT_TRANS_APIS)[
|
|
||||||
translator
|
|
||||||
];
|
|
||||||
|
|
||||||
let triggerShortcut = initTriggerShortcut;
|
|
||||||
let triggerCount = initTriggerCount;
|
|
||||||
if (triggerShortcut.length === 0) {
|
|
||||||
triggerShortcut = DEFAULT_INPUT_SHORTCUT;
|
|
||||||
triggerCount = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stepShortcutRegister(
|
|
||||||
triggerShortcut,
|
|
||||||
async () => {
|
|
||||||
let node = document.activeElement;
|
|
||||||
|
|
||||||
if (!node) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (node.shadowRoot) {
|
|
||||||
node = node.shadowRoot.activeElement;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isInputNode(node) && !isEditAbleNode(node)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let initText = getNodeText(node);
|
|
||||||
if (triggerShortcut.length === 1 && triggerShortcut[0].length === 1) {
|
|
||||||
// todo: remove multiple char
|
|
||||||
initText = removeEndchar(initText, triggerShortcut[0], triggerCount);
|
|
||||||
}
|
|
||||||
if (!initText.trim()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let text = initText;
|
|
||||||
let toLang = initToLang;
|
|
||||||
if (transSign) {
|
|
||||||
const res = matchInputStr(text, transSign);
|
|
||||||
if (res) {
|
|
||||||
let lang = res[1];
|
|
||||||
if (lang === "zh" || lang === "cn") {
|
|
||||||
lang = "zh-CN";
|
|
||||||
} else if (lang === "tw" || lang === "hk") {
|
|
||||||
lang = "zh-TW";
|
|
||||||
}
|
|
||||||
if (lang && OPT_LANGS_LIST.includes(lang)) {
|
|
||||||
toLang = lang;
|
|
||||||
}
|
|
||||||
text = res[2];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// console.log("input -->", text);
|
|
||||||
|
|
||||||
const loadingId = "kiss-" + genEventName();
|
|
||||||
try {
|
|
||||||
addLoading(node, loadingId);
|
|
||||||
|
|
||||||
const deLang = await tryDetectLang(text);
|
|
||||||
if (deLang && toLang.includes(deLang)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const [trText, isSame] = await apiTranslate({
|
|
||||||
translator,
|
|
||||||
text,
|
|
||||||
fromLang,
|
|
||||||
toLang,
|
|
||||||
apiSetting,
|
|
||||||
});
|
|
||||||
if (!trText || isSame) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isInputNode(node)) {
|
|
||||||
node.value = trText;
|
|
||||||
node.dispatchEvent(
|
|
||||||
new Event("input", { bubbles: true, cancelable: true })
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
selectContent(node);
|
|
||||||
await sleep(200);
|
|
||||||
|
|
||||||
pasteContentEvent(node, trText);
|
|
||||||
await sleep(200);
|
|
||||||
|
|
||||||
// todo: use includes?
|
|
||||||
if (getNodeText(node).startsWith(initText)) {
|
|
||||||
pasteContentCommand(node, trText);
|
|
||||||
await sleep(100);
|
|
||||||
} else {
|
|
||||||
collapseToEnd(node);
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
console.log("[translate input]", err.message);
|
|
||||||
} finally {
|
|
||||||
removeLoading(node, loadingId);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
triggerCount,
|
|
||||||
triggerTime
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
_handleMouseover = (e) => {
|
_handleMouseover = (e) => {
|
||||||
|
// console.log("mouseenter", e);
|
||||||
|
if (!this._tranNodes.has(e.target)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const key = this._setting.mouseKey.slice(3);
|
const key = this._setting.mouseKey.slice(3);
|
||||||
if (this._setting.mouseKey === OPT_MOUSEKEY_MOUSEOVER || e[key]) {
|
if (this._setting.mouseKey === OPT_MOUSEKEY_MOUSEOVER || e[key]) {
|
||||||
e.target.removeEventListener("mouseover", this._handleMouseover);
|
e.target.removeEventListener("mouseenter", this._handleMouseover);
|
||||||
|
e.target.removeEventListener("mouseleave", this._handleMouseout);
|
||||||
this._render(e.target);
|
this._render(e.target);
|
||||||
|
} else {
|
||||||
|
this._mouseoverNode = e.target;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
_handleMouseout = (e) => {
|
||||||
|
// console.log("mouseleave", e);
|
||||||
|
if (!this._tranNodes.has(e.target)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this._mouseoverNode = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
_handleKeydown = (e) => {
|
||||||
|
// console.log("keydown", e);
|
||||||
|
const key = this._setting.mouseKey.slice(3);
|
||||||
|
if (e[key] && this._mouseoverNode) {
|
||||||
|
this._mouseoverNode.removeEventListener(
|
||||||
|
"mouseenter",
|
||||||
|
this._handleMouseover
|
||||||
|
);
|
||||||
|
this._mouseoverNode.removeEventListener(
|
||||||
|
"mouseleave",
|
||||||
|
this._handleMouseout
|
||||||
|
);
|
||||||
|
|
||||||
|
const node = this._mouseoverNode;
|
||||||
|
this._render(node);
|
||||||
|
this._mouseoverNode = null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -484,21 +316,27 @@ export class Translator {
|
|||||||
// 解除节点显示监听
|
// 解除节点显示监听
|
||||||
// this._interseObserver.disconnect();
|
// this._interseObserver.disconnect();
|
||||||
|
|
||||||
this._tranNodes.forEach((_, node) => {
|
if (
|
||||||
if (
|
!this._setting.mouseKey ||
|
||||||
!this._setting.mouseKey ||
|
this._setting.mouseKey === OPT_MOUSEKEY_DISABLE
|
||||||
this._setting.mouseKey === OPT_MOUSEKEY_DISABLE
|
) {
|
||||||
) {
|
// 解除节点显示监听
|
||||||
// 解除节点显示监听
|
this._tranNodes.forEach((_, node) => {
|
||||||
this._interseObserver.unobserve(node);
|
this._interseObserver.unobserve(node);
|
||||||
} else {
|
// 移除已插入元素
|
||||||
// 移除鼠标悬停监听
|
node.querySelector(APP_LCNAME)?.remove();
|
||||||
node.removeEventListener("mouseover", this._handleMouseover);
|
});
|
||||||
}
|
} else {
|
||||||
|
// 移除鼠标悬停监听
|
||||||
// 移除已插入元素
|
window.removeEventListener("keydown", this._handleKeydown);
|
||||||
node.querySelector(APP_LCNAME)?.remove();
|
this._tranNodes.forEach((_, node) => {
|
||||||
});
|
// node.style.pointerEvents = "none";
|
||||||
|
node.removeEventListener("mouseenter", this._handleMouseover);
|
||||||
|
node.removeEventListener("mouseleave", this._handleMouseout);
|
||||||
|
// 移除已插入元素
|
||||||
|
node.querySelector(APP_LCNAME)?.remove();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// 清空节点集合
|
// 清空节点集合
|
||||||
this._rootNodes.clear();
|
this._rootNodes.clear();
|
||||||
|
|||||||
@@ -223,3 +223,13 @@ export const matchInputStr = (str, sign) => {
|
|||||||
}
|
}
|
||||||
return str.match(reg);
|
return str.match(reg);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断是否英文单词
|
||||||
|
* @param {*} str
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
export const isValidWord = (str) => {
|
||||||
|
const regex = /^[a-zA-Z-]+$/;
|
||||||
|
return regex.test(str);
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,12 +1,22 @@
|
|||||||
import { isMatch } from "./utils";
|
import { isMatch } from "./utils";
|
||||||
import { getWebfix, setWebfix } from "./storage";
|
import { getWebfix, setWebfix, getWebfixRulesWithDefault } from "./storage";
|
||||||
import { apiFetch } from "../apis";
|
import { apiFetch } from "../apis";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修复程序类型
|
* 修复程序类型
|
||||||
*/
|
*/
|
||||||
const FIXER_BR = "br";
|
const FIXER_BR = "br";
|
||||||
|
const FIXER_BN = "bn";
|
||||||
|
const FIXER_BR_DIV = "brToDiv";
|
||||||
|
const FIXER_BN_DIV = "bnToDiv";
|
||||||
const FIXER_FONTSIZE = "fontSize";
|
const FIXER_FONTSIZE = "fontSize";
|
||||||
|
export const FIXER_ALL = [
|
||||||
|
FIXER_BR,
|
||||||
|
FIXER_BN,
|
||||||
|
FIXER_BR_DIV,
|
||||||
|
FIXER_BN_DIV,
|
||||||
|
// FIXER_FONTSIZE,
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 需要修复的站点列表
|
* 需要修复的站点列表
|
||||||
@@ -34,6 +44,12 @@ const DEFAULT_SITES = [
|
|||||||
rootSelector: "",
|
rootSelector: "",
|
||||||
fixer: FIXER_FONTSIZE,
|
fixer: FIXER_FONTSIZE,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
pattern: "chat.openai.com",
|
||||||
|
selector: "div[data-testid^=conversation-turn] .items-start > div",
|
||||||
|
rootSelector: "",
|
||||||
|
fixer: FIXER_BN,
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -47,7 +63,7 @@ const fixedSign = "kissfixed";
|
|||||||
* @param {*} node
|
* @param {*} node
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
function brFixer(node) {
|
function brFixer(node, tag = "p") {
|
||||||
if (node.hasAttribute(fixedSign)) {
|
if (node.hasAttribute(fixedSign)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -74,13 +90,13 @@ function brFixer(node) {
|
|||||||
var html = "";
|
var html = "";
|
||||||
node.childNodes.forEach(function (child, index) {
|
node.childNodes.forEach(function (child, index) {
|
||||||
if (index === 0) {
|
if (index === 0) {
|
||||||
html += "<p>";
|
html += `<${tag} class="kiss-p">`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gapTags.indexOf(child.nodeName) !== -1) {
|
if (gapTags.indexOf(child.nodeName) !== -1) {
|
||||||
html += "</p><p>";
|
html += `</${tag}><${tag} class="kiss-p">`;
|
||||||
} else if (newlineTags.indexOf(child.nodeName) !== -1) {
|
} else if (newlineTags.indexOf(child.nodeName) !== -1) {
|
||||||
html += "</p>" + child.outerHTML + "<p>";
|
html += `</${tag}>${child.outerHTML}<${tag} class="kiss-p">`;
|
||||||
} else if (child.outerHTML) {
|
} else if (child.outerHTML) {
|
||||||
html += child.outerHTML;
|
html += child.outerHTML;
|
||||||
} else if (child.nodeValue) {
|
} else if (child.nodeValue) {
|
||||||
@@ -88,12 +104,36 @@ function brFixer(node) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (index === node.childNodes.length - 1) {
|
if (index === node.childNodes.length - 1) {
|
||||||
html += "</p>";
|
html += `</${tag}>`;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
node.innerHTML = html;
|
node.innerHTML = html;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function brDivFixer(node) {
|
||||||
|
return brFixer(node, "div");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 目标是将 `\n` 替换成 `p`
|
||||||
|
* @param {*} node
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
function bnFixer(node, tag = "p") {
|
||||||
|
if (node.hasAttribute(fixedSign)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
node.setAttribute(fixedSign, "true");
|
||||||
|
node.innerHTML = node.innerHTML
|
||||||
|
.split("\n")
|
||||||
|
.map((item) => `<${tag} class="kiss-p">${item || " "}</${tag}>`)
|
||||||
|
.join("");
|
||||||
|
}
|
||||||
|
|
||||||
|
function bnDivFixer(node) {
|
||||||
|
return bnFixer(node, "div");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修复字体大小问题,如 baidu.com
|
* 修复字体大小问题,如 baidu.com
|
||||||
* @param {*} node
|
* @param {*} node
|
||||||
@@ -107,6 +147,9 @@ function fontSizeFixer(node) {
|
|||||||
*/
|
*/
|
||||||
const fixerMap = {
|
const fixerMap = {
|
||||||
[FIXER_BR]: brFixer,
|
[FIXER_BR]: brFixer,
|
||||||
|
[FIXER_BN]: bnFixer,
|
||||||
|
[FIXER_BR_DIV]: brDivFixer,
|
||||||
|
[FIXER_BN_DIV]: bnDivFixer,
|
||||||
[FIXER_FONTSIZE]: fontSizeFixer,
|
[FIXER_FONTSIZE]: fontSizeFixer,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -120,7 +163,11 @@ function run(selector, fixer, rootSelector) {
|
|||||||
var mutaObserver = new MutationObserver(function (mutations) {
|
var mutaObserver = new MutationObserver(function (mutations) {
|
||||||
mutations.forEach(function (mutation) {
|
mutations.forEach(function (mutation) {
|
||||||
mutation.addedNodes.forEach(function (addNode) {
|
mutation.addedNodes.forEach(function (addNode) {
|
||||||
addNode.querySelectorAll(selector).forEach(fixer);
|
if (addNode && addNode.querySelectorAll) {
|
||||||
|
addNode.querySelectorAll(selector).forEach(function (node) {
|
||||||
|
fixer(node);
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -131,9 +178,12 @@ function run(selector, fixer, rootSelector) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
rootNodes.forEach(function (rootNode) {
|
rootNodes.forEach(function (rootNode) {
|
||||||
rootNode.querySelectorAll(selector).forEach(fixer);
|
rootNode.querySelectorAll(selector).forEach(function (node) {
|
||||||
|
fixer(node);
|
||||||
|
});
|
||||||
mutaObserver.observe(rootNode, {
|
mutaObserver.observe(rootNode, {
|
||||||
childList: true,
|
childList: true,
|
||||||
|
subtree: true,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -170,13 +220,16 @@ export const loadOrFetchWebfix = async (url) => {
|
|||||||
/**
|
/**
|
||||||
* 匹配站点
|
* 匹配站点
|
||||||
*/
|
*/
|
||||||
export async function webfix(href, { injectWebfix }) {
|
export async function runWebfix({ injectWebfix }) {
|
||||||
try {
|
try {
|
||||||
if (!injectWebfix) {
|
if (!injectWebfix) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const sites = await loadOrFetchWebfix(process.env.REACT_APP_WEBFIXURL);
|
const href = document.location.href;
|
||||||
|
const userSites = await getWebfixRulesWithDefault();
|
||||||
|
const subSites = await loadOrFetchWebfix(process.env.REACT_APP_WEBFIXURL);
|
||||||
|
const sites = [...userSites, ...subSites];
|
||||||
for (var i = 0; i < sites.length; i++) {
|
for (var i = 0; i < sites.length; i++) {
|
||||||
var site = sites[i];
|
var site = sites[i];
|
||||||
if (isMatch(href, site.pattern)) {
|
if (isMatch(href, site.pattern)) {
|
||||||
|
|||||||
@@ -1,135 +1,3 @@
|
|||||||
import React from "react";
|
import { run } from "./common";
|
||||||
import ReactDOM from "react-dom/client";
|
|
||||||
import Action from "./views/Action";
|
|
||||||
import createCache from "@emotion/cache";
|
|
||||||
import { CacheProvider } from "@emotion/react";
|
|
||||||
import {
|
|
||||||
getSettingWithDefault,
|
|
||||||
getRulesWithDefault,
|
|
||||||
getFabWithDefault,
|
|
||||||
} from "./libs/storage";
|
|
||||||
import { Translator } from "./libs/translator";
|
|
||||||
import { trySyncAllSubRules } from "./libs/subRules";
|
|
||||||
import {
|
|
||||||
MSG_TRANS_TOGGLE,
|
|
||||||
MSG_TRANS_TOGGLE_STYLE,
|
|
||||||
MSG_TRANS_GETRULE,
|
|
||||||
MSG_TRANS_PUTRULE,
|
|
||||||
} from "./config";
|
|
||||||
import { isIframe, sendIframeMsg, sendPrentMsg } from "./libs/iframe";
|
|
||||||
import { handlePing, injectScript } from "./libs/gm";
|
|
||||||
import { matchRule } from "./libs/rules";
|
|
||||||
import { genEventName } from "./libs/utils";
|
|
||||||
import { webfix } from "./libs/webfix";
|
|
||||||
|
|
||||||
/**
|
run(true);
|
||||||
* 入口函数
|
|
||||||
*/
|
|
||||||
const init = async () => {
|
|
||||||
// 设置页面
|
|
||||||
if (
|
|
||||||
document.location.href.includes(process.env.REACT_APP_OPTIONSPAGE_DEV) ||
|
|
||||||
document.location.href.includes(process.env.REACT_APP_OPTIONSPAGE) ||
|
|
||||||
document.location.href.includes(process.env.REACT_APP_OPTIONSPAGE2)
|
|
||||||
) {
|
|
||||||
if (GM?.info?.script?.grant?.includes("unsafeWindow")) {
|
|
||||||
unsafeWindow.GM = GM;
|
|
||||||
unsafeWindow.APP_INFO = {
|
|
||||||
name: process.env.REACT_APP_NAME,
|
|
||||||
version: process.env.REACT_APP_VERSION,
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
const ping = genEventName();
|
|
||||||
window.addEventListener(ping, handlePing);
|
|
||||||
// window.eval(`(${injectScript})("${ping}")`); // eslint-disable-line
|
|
||||||
const script = document.createElement("script");
|
|
||||||
script.textContent = `(${injectScript})("${ping}")`;
|
|
||||||
document.head.append(script);
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 翻译页面
|
|
||||||
const setting = await getSettingWithDefault();
|
|
||||||
|
|
||||||
if (isIframe) {
|
|
||||||
let translator;
|
|
||||||
window.addEventListener("message", (e) => {
|
|
||||||
const { action, args } = e.data || {};
|
|
||||||
switch (action) {
|
|
||||||
case MSG_TRANS_TOGGLE:
|
|
||||||
translator?.toggle();
|
|
||||||
break;
|
|
||||||
case MSG_TRANS_TOGGLE_STYLE:
|
|
||||||
translator?.toggleStyle();
|
|
||||||
break;
|
|
||||||
case MSG_TRANS_PUTRULE:
|
|
||||||
if (!translator) {
|
|
||||||
translator = new Translator(args, setting);
|
|
||||||
} else {
|
|
||||||
translator.updateRule(args || {});
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
});
|
|
||||||
sendPrentMsg(MSG_TRANS_GETRULE);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const href = isIframe ? document.referrer : document.location.href;
|
|
||||||
const rules = await getRulesWithDefault();
|
|
||||||
const rule = await matchRule(rules, href, setting);
|
|
||||||
const translator = new Translator(rule, setting);
|
|
||||||
webfix(href, setting);
|
|
||||||
|
|
||||||
// 监听消息
|
|
||||||
window.addEventListener("message", (e) => {
|
|
||||||
const { action } = e.data || {};
|
|
||||||
switch (action) {
|
|
||||||
case MSG_TRANS_GETRULE:
|
|
||||||
sendIframeMsg(MSG_TRANS_PUTRULE, rule);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// 浮球按钮
|
|
||||||
const fab = await getFabWithDefault();
|
|
||||||
const $action = document.createElement("div");
|
|
||||||
$action.setAttribute("id", "kiss-translator");
|
|
||||||
document.body.parentElement.appendChild($action);
|
|
||||||
const shadowContainer = $action.attachShadow({ mode: "closed" });
|
|
||||||
const emotionRoot = document.createElement("style");
|
|
||||||
const shadowRootElement = document.createElement("div");
|
|
||||||
shadowContainer.appendChild(emotionRoot);
|
|
||||||
shadowContainer.appendChild(shadowRootElement);
|
|
||||||
const cache = createCache({
|
|
||||||
key: "css",
|
|
||||||
prepend: true,
|
|
||||||
container: emotionRoot,
|
|
||||||
});
|
|
||||||
ReactDOM.createRoot(shadowRootElement).render(
|
|
||||||
<React.StrictMode>
|
|
||||||
<CacheProvider value={cache}>
|
|
||||||
<Action translator={translator} fab={fab} />
|
|
||||||
</CacheProvider>
|
|
||||||
</React.StrictMode>
|
|
||||||
);
|
|
||||||
|
|
||||||
// 同步订阅规则
|
|
||||||
trySyncAllSubRules(setting);
|
|
||||||
};
|
|
||||||
|
|
||||||
(async () => {
|
|
||||||
try {
|
|
||||||
await init();
|
|
||||||
} catch (err) {
|
|
||||||
console.error("[KISS-Translator]", err);
|
|
||||||
const $err = document.createElement("div");
|
|
||||||
$err.innerText = `KISS-Translator: ${err.message}`;
|
|
||||||
$err.style.cssText = "background:red; color:#fff;";
|
|
||||||
document.body.prepend($err);
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
|
|||||||
@@ -95,40 +95,42 @@ export default function Action({ translator, fab }) {
|
|||||||
// 注册菜单
|
// 注册菜单
|
||||||
try {
|
try {
|
||||||
const menuCommandIds = [];
|
const menuCommandIds = [];
|
||||||
menuCommandIds.push(
|
const { contextMenus = true } = translator.setting;
|
||||||
GM.registerMenuCommand(
|
contextMenus &&
|
||||||
"Toggle Translate (Alt+q)",
|
menuCommandIds.push(
|
||||||
(event) => {
|
GM.registerMenuCommand(
|
||||||
translator.toggle();
|
"Toggle Translate (Alt+q)",
|
||||||
sendIframeMsg(MSG_TRANS_TOGGLE);
|
(event) => {
|
||||||
setShowPopup(false);
|
translator.toggle();
|
||||||
},
|
sendIframeMsg(MSG_TRANS_TOGGLE);
|
||||||
"Q"
|
setShowPopup(false);
|
||||||
),
|
},
|
||||||
GM.registerMenuCommand(
|
"Q"
|
||||||
"Toggle Style (Alt+c)",
|
),
|
||||||
(event) => {
|
GM.registerMenuCommand(
|
||||||
translator.toggleStyle();
|
"Toggle Style (Alt+c)",
|
||||||
sendIframeMsg(MSG_TRANS_TOGGLE_STYLE);
|
(event) => {
|
||||||
setShowPopup(false);
|
translator.toggleStyle();
|
||||||
},
|
sendIframeMsg(MSG_TRANS_TOGGLE_STYLE);
|
||||||
"C"
|
setShowPopup(false);
|
||||||
),
|
},
|
||||||
GM.registerMenuCommand(
|
"C"
|
||||||
"Open Menu (Alt+k)",
|
),
|
||||||
(event) => {
|
GM.registerMenuCommand(
|
||||||
setShowPopup((pre) => !pre);
|
"Open Menu (Alt+k)",
|
||||||
},
|
(event) => {
|
||||||
"K"
|
setShowPopup((pre) => !pre);
|
||||||
),
|
},
|
||||||
GM.registerMenuCommand(
|
"K"
|
||||||
"Open Setting (Alt+o)",
|
),
|
||||||
(event) => {
|
GM.registerMenuCommand(
|
||||||
window.open(process.env.REACT_APP_OPTIONSPAGE, "_blank");
|
"Open Setting (Alt+o)",
|
||||||
},
|
(event) => {
|
||||||
"O"
|
window.open(process.env.REACT_APP_OPTIONSPAGE, "_blank");
|
||||||
)
|
},
|
||||||
);
|
"O"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
menuCommandIds.forEach((id) => {
|
menuCommandIds.forEach((id) => {
|
||||||
@@ -215,7 +217,12 @@ export default function Action({ translator, fab }) {
|
|||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<TranslateIcon />
|
<TranslateIcon
|
||||||
|
sx={{
|
||||||
|
width: 24,
|
||||||
|
height: 24,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
</Fab>
|
</Fab>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import {
|
|||||||
OPT_STYLE_WAVYLINE,
|
OPT_STYLE_WAVYLINE,
|
||||||
OPT_STYLE_FUZZY,
|
OPT_STYLE_FUZZY,
|
||||||
OPT_STYLE_HIGHLIGHT,
|
OPT_STYLE_HIGHLIGHT,
|
||||||
|
OPT_STYLE_BLOCKQUOTE,
|
||||||
OPT_STYLE_DIY,
|
OPT_STYLE_DIY,
|
||||||
DEFAULT_COLOR,
|
DEFAULT_COLOR,
|
||||||
MSG_TRANS_CURRULE,
|
MSG_TRANS_CURRULE,
|
||||||
@@ -34,6 +35,18 @@ const LineSpan = styled("span")`
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
const BlockquoteSpan = styled("span")`
|
||||||
|
opacity: 0.6;
|
||||||
|
-webkit-opacity: 0.6;
|
||||||
|
display: block;
|
||||||
|
padding: 0 0.75em;
|
||||||
|
border-left: 0.25em solid ${(props) => props.$lineColor};
|
||||||
|
&:hover {
|
||||||
|
opacity: 1;
|
||||||
|
-webkit-opacity: 1;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
const FuzzySpan = styled("span")`
|
const FuzzySpan = styled("span")`
|
||||||
filter: blur(0.2em);
|
filter: blur(0.2em);
|
||||||
-webkit-filter: blur(0.2em);
|
-webkit-filter: blur(0.2em);
|
||||||
@@ -86,6 +99,12 @@ function StyledSpan({ textStyle, textDiyStyle, bgColor, children }) {
|
|||||||
{children}
|
{children}
|
||||||
</HighlightSpan>
|
</HighlightSpan>
|
||||||
);
|
);
|
||||||
|
case OPT_STYLE_BLOCKQUOTE: // 引用
|
||||||
|
return (
|
||||||
|
<BlockquoteSpan $lineColor={bgColor || DEFAULT_COLOR}>
|
||||||
|
{children}
|
||||||
|
</BlockquoteSpan>
|
||||||
|
);
|
||||||
case OPT_STYLE_DIY: // 自定义
|
case OPT_STYLE_DIY: // 自定义
|
||||||
return <DiySpan $diyStyle={textDiyStyle}>{children}</DiySpan>;
|
return <DiySpan $diyStyle={textDiyStyle}>{children}</DiySpan>;
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -5,7 +5,11 @@ import CircularProgress from "@mui/material/CircularProgress";
|
|||||||
import {
|
import {
|
||||||
OPT_TRANS_ALL,
|
OPT_TRANS_ALL,
|
||||||
OPT_TRANS_MICROSOFT,
|
OPT_TRANS_MICROSOFT,
|
||||||
|
OPT_TRANS_DEEPLFREE,
|
||||||
|
OPT_TRANS_BAIDU,
|
||||||
|
OPT_TRANS_TENCENT,
|
||||||
OPT_TRANS_OPENAI,
|
OPT_TRANS_OPENAI,
|
||||||
|
OPT_TRANS_GEMINI,
|
||||||
OPT_TRANS_CUSTOMIZE,
|
OPT_TRANS_CUSTOMIZE,
|
||||||
URL_KISS_PROXY,
|
URL_KISS_PROXY,
|
||||||
} from "../../config";
|
} from "../../config";
|
||||||
@@ -35,14 +39,28 @@ function TestButton({ translator, api }) {
|
|||||||
text: "hello world",
|
text: "hello world",
|
||||||
fromLang: "en",
|
fromLang: "en",
|
||||||
toLang: "zh-CN",
|
toLang: "zh-CN",
|
||||||
apiSetting: { ...api, useCache: false },
|
apiSetting: api,
|
||||||
|
useCache: false,
|
||||||
});
|
});
|
||||||
if (!text) {
|
if (!text) {
|
||||||
throw new Error("empty reault");
|
throw new Error("empty reault");
|
||||||
}
|
}
|
||||||
alert.success(i18n("test_success"));
|
alert.success(i18n("test_success"));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
alert.error(`${i18n("test_failed")}: ${err.message}`);
|
// alert.error(`${i18n("test_failed")}: ${err.message}`);
|
||||||
|
alert.error(
|
||||||
|
<>
|
||||||
|
<div>{`${i18n("test_failed")}: ${err.message}`}</div>
|
||||||
|
<pre
|
||||||
|
style={{
|
||||||
|
maxWidth: 400,
|
||||||
|
overflow: "auto",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{JSON.stringify(err.cause || {}, null, 2)}
|
||||||
|
</pre>
|
||||||
|
</>
|
||||||
|
);
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
@@ -71,9 +89,16 @@ function ApiFields({ translator }) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const buildinTranslators = [
|
||||||
|
OPT_TRANS_MICROSOFT,
|
||||||
|
OPT_TRANS_DEEPLFREE,
|
||||||
|
OPT_TRANS_BAIDU,
|
||||||
|
OPT_TRANS_TENCENT,
|
||||||
|
];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack spacing={3}>
|
<Stack spacing={3}>
|
||||||
{translator !== OPT_TRANS_MICROSOFT && (
|
{!buildinTranslators.includes(translator) && (
|
||||||
<>
|
<>
|
||||||
<TextField
|
<TextField
|
||||||
size="small"
|
size="small"
|
||||||
@@ -91,7 +116,7 @@ function ApiFields({ translator }) {
|
|||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
{translator === OPT_TRANS_OPENAI && (
|
{(translator === OPT_TRANS_OPENAI || translator === OPT_TRANS_GEMINI) && (
|
||||||
<>
|
<>
|
||||||
<TextField
|
<TextField
|
||||||
size="small"
|
size="small"
|
||||||
@@ -113,7 +138,7 @@ function ApiFields({ translator }) {
|
|||||||
|
|
||||||
<Stack direction="row" spacing={2}>
|
<Stack direction="row" spacing={2}>
|
||||||
<TestButton translator={translator} api={api} />
|
<TestButton translator={translator} api={api} />
|
||||||
{translator !== OPT_TRANS_MICROSOFT && (
|
{!buildinTranslators.includes(translator) && (
|
||||||
<Button
|
<Button
|
||||||
size="small"
|
size="small"
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
|
|||||||
27
src/views/Options/DownloadButton.js
Normal file
27
src/views/Options/DownloadButton.js
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import FileDownloadIcon from "@mui/icons-material/FileDownload";
|
||||||
|
import Button from "@mui/material/Button";
|
||||||
|
|
||||||
|
export default function DownloadButton({ data, text, fileName }) {
|
||||||
|
const handleClick = (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
if (data) {
|
||||||
|
const url = window.URL.createObjectURL(new Blob([data]));
|
||||||
|
const link = document.createElement("a");
|
||||||
|
link.href = url;
|
||||||
|
link.setAttribute("download", fileName || `${Date.now()}.json`);
|
||||||
|
document.body.appendChild(link);
|
||||||
|
link.click();
|
||||||
|
link.remove();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
size="small"
|
||||||
|
variant="outlined"
|
||||||
|
onClick={handleClick}
|
||||||
|
startIcon={<FileDownloadIcon />}
|
||||||
|
>
|
||||||
|
{text}
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
}
|
||||||
150
src/views/Options/FavWords.js
Normal file
150
src/views/Options/FavWords.js
Normal file
@@ -0,0 +1,150 @@
|
|||||||
|
import Stack from "@mui/material/Stack";
|
||||||
|
import { OPT_TRANS_BAIDU } from "../../config";
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import Typography from "@mui/material/Typography";
|
||||||
|
import Accordion from "@mui/material/Accordion";
|
||||||
|
import AccordionSummary from "@mui/material/AccordionSummary";
|
||||||
|
import AccordionDetails from "@mui/material/AccordionDetails";
|
||||||
|
import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
|
||||||
|
import CircularProgress from "@mui/material/CircularProgress";
|
||||||
|
import { useI18n } from "../../hooks/I18n";
|
||||||
|
import Alert from "@mui/material/Alert";
|
||||||
|
import { apiTranslate } from "../../apis";
|
||||||
|
import Box from "@mui/material/Box";
|
||||||
|
import { useFavWords } from "../../hooks/FavWords";
|
||||||
|
import DictCont from "../Selection/DictCont";
|
||||||
|
import DownloadButton from "./DownloadButton";
|
||||||
|
import UploadButton from "./UploadButton";
|
||||||
|
import Button from "@mui/material/Button";
|
||||||
|
import ClearAllIcon from "@mui/icons-material/ClearAll";
|
||||||
|
import { isValidWord } from "../../libs/utils";
|
||||||
|
|
||||||
|
function DictField({ word }) {
|
||||||
|
const [dictResult, setDictResult] = useState(null);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [error, setError] = useState("");
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
(async () => {
|
||||||
|
try {
|
||||||
|
setLoading(true);
|
||||||
|
setError("");
|
||||||
|
const dictRes = await apiTranslate({
|
||||||
|
text: word,
|
||||||
|
translator: OPT_TRANS_BAIDU,
|
||||||
|
fromLang: "en",
|
||||||
|
toLang: "zh-CN",
|
||||||
|
});
|
||||||
|
setDictResult(dictRes[2].dict_result);
|
||||||
|
} catch (err) {
|
||||||
|
setError(err.message);
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
}, [word]);
|
||||||
|
|
||||||
|
if (loading) {
|
||||||
|
return <CircularProgress size={24} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
return <Alert severity="error">{error}</Alert>;
|
||||||
|
}
|
||||||
|
|
||||||
|
return <DictCont dictResult={dictResult} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
function FavAccordion({ word, index }) {
|
||||||
|
const [expanded, setExpanded] = useState(false);
|
||||||
|
|
||||||
|
const handleChange = (e) => {
|
||||||
|
setExpanded((pre) => !pre);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Accordion expanded={expanded} onChange={handleChange}>
|
||||||
|
<AccordionSummary expandIcon={<ExpandMoreIcon />}>
|
||||||
|
{/* <Typography>{`[${new Date(
|
||||||
|
createdAt
|
||||||
|
).toLocaleString()}] ${word}`}</Typography> */}
|
||||||
|
<Typography>{`${index + 1}. ${word}`}</Typography>
|
||||||
|
</AccordionSummary>
|
||||||
|
<AccordionDetails>
|
||||||
|
{expanded && <DictField word={word} />}
|
||||||
|
</AccordionDetails>
|
||||||
|
</Accordion>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function FavWords() {
|
||||||
|
const i18n = useI18n();
|
||||||
|
const { loading, favWords, mergeWords, clearWords } = useFavWords();
|
||||||
|
const favList = Object.entries(favWords).sort((a, b) =>
|
||||||
|
a[0].localeCompare(b[0])
|
||||||
|
);
|
||||||
|
const downloadList = favList.map(([word]) => word);
|
||||||
|
|
||||||
|
const handleImport = async (data) => {
|
||||||
|
try {
|
||||||
|
const newWords = data
|
||||||
|
.split("\n")
|
||||||
|
.map((line) => line.split(",")[0].trim())
|
||||||
|
.filter(isValidWord);
|
||||||
|
await mergeWords(newWords);
|
||||||
|
} catch (err) {
|
||||||
|
console.log("[import rules]", err);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box>
|
||||||
|
<Stack spacing={3}>
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
alignItems="center"
|
||||||
|
spacing={2}
|
||||||
|
useFlexGap
|
||||||
|
flexWrap="wrap"
|
||||||
|
>
|
||||||
|
<UploadButton
|
||||||
|
text={i18n("import")}
|
||||||
|
handleImport={handleImport}
|
||||||
|
fileType="text"
|
||||||
|
fileExts={[".txt", ".csv"]}
|
||||||
|
/>
|
||||||
|
<DownloadButton
|
||||||
|
data={downloadList.join("\n")}
|
||||||
|
text={i18n("export")}
|
||||||
|
fileName={`kiss-words_${Date.now()}.txt`}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
size="small"
|
||||||
|
variant="outlined"
|
||||||
|
onClick={() => {
|
||||||
|
clearWords();
|
||||||
|
}}
|
||||||
|
startIcon={<ClearAllIcon />}
|
||||||
|
>
|
||||||
|
{i18n("clear_all")}
|
||||||
|
</Button>
|
||||||
|
</Stack>
|
||||||
|
|
||||||
|
<Box>
|
||||||
|
{loading ? (
|
||||||
|
<CircularProgress size={24} />
|
||||||
|
) : (
|
||||||
|
favList.map(([word, { createdAt }], index) => (
|
||||||
|
<FavAccordion
|
||||||
|
key={word}
|
||||||
|
index={index}
|
||||||
|
word={word}
|
||||||
|
createdAt={createdAt}
|
||||||
|
/>
|
||||||
|
))
|
||||||
|
)}
|
||||||
|
</Box>
|
||||||
|
</Stack>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ import Box from "@mui/material/Box";
|
|||||||
import Link from "@mui/material/Link";
|
import Link from "@mui/material/Link";
|
||||||
import { useI18n } from "../../hooks/I18n";
|
import { useI18n } from "../../hooks/I18n";
|
||||||
import DarkModeButton from "./DarkModeButton";
|
import DarkModeButton from "./DarkModeButton";
|
||||||
|
import Typography from "@mui/material/Typography";
|
||||||
|
|
||||||
function Header(props) {
|
function Header(props) {
|
||||||
const i18n = useI18n();
|
const i18n = useI18n();
|
||||||
@@ -30,14 +31,14 @@ function Header(props) {
|
|||||||
<MenuIcon />
|
<MenuIcon />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</Box>
|
</Box>
|
||||||
<Box sx={{ flexGrow: 1 }}>
|
<Typography component="div" sx={{ flexGrow: 1, fontWeight: "bold" }}>
|
||||||
<Link
|
<Link
|
||||||
underline="none"
|
underline="none"
|
||||||
color="inherit"
|
color="inherit"
|
||||||
href={process.env.REACT_APP_HOMEPAGE}
|
href={process.env.REACT_APP_HOMEPAGE}
|
||||||
target="_blank"
|
target="_blank"
|
||||||
>{`${i18n("app_name")} v${process.env.REACT_APP_VERSION}`}</Link>
|
>{`${i18n("app_name")} v${process.env.REACT_APP_VERSION}`}</Link>
|
||||||
</Box>
|
</Typography>
|
||||||
<DarkModeButton />
|
<DarkModeButton />
|
||||||
</Toolbar>
|
</Toolbar>
|
||||||
</AppBar>
|
</AppBar>
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ export default function InputSetting() {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
label={i18n("input_box_translation")}
|
label={i18n("use_input_box_translation")}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<TextField
|
<TextField
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ import SyncIcon from "@mui/icons-material/Sync";
|
|||||||
import ApiIcon from "@mui/icons-material/Api";
|
import ApiIcon from "@mui/icons-material/Api";
|
||||||
import SendTimeExtensionIcon from "@mui/icons-material/SendTimeExtension";
|
import SendTimeExtensionIcon from "@mui/icons-material/SendTimeExtension";
|
||||||
import InputIcon from "@mui/icons-material/Input";
|
import InputIcon from "@mui/icons-material/Input";
|
||||||
|
import SelectAllIcon from "@mui/icons-material/SelectAll";
|
||||||
|
import EventNoteIcon from "@mui/icons-material/EventNote";
|
||||||
|
|
||||||
function LinkItem({ label, url, icon }) {
|
function LinkItem({ label, url, icon }) {
|
||||||
const match = useMatch(url);
|
const match = useMatch(url);
|
||||||
@@ -40,11 +42,17 @@ export default function Navigator(props) {
|
|||||||
icon: <DesignServicesIcon />,
|
icon: <DesignServicesIcon />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: "input_setting",
|
id: "input_translate",
|
||||||
label: i18n("input_setting"),
|
label: i18n("input_translate"),
|
||||||
url: "/input",
|
url: "/input",
|
||||||
icon: <InputIcon />,
|
icon: <InputIcon />,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
id: "selection_translate",
|
||||||
|
label: i18n("selection_translate"),
|
||||||
|
url: "/tranbox",
|
||||||
|
icon: <SelectAllIcon />,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
id: "apis_setting",
|
id: "apis_setting",
|
||||||
label: i18n("apis_setting"),
|
label: i18n("apis_setting"),
|
||||||
@@ -63,6 +71,12 @@ export default function Navigator(props) {
|
|||||||
url: "/webfix",
|
url: "/webfix",
|
||||||
icon: <SendTimeExtensionIcon />,
|
icon: <SendTimeExtensionIcon />,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
id: "words",
|
||||||
|
label: i18n("favorite_words"),
|
||||||
|
url: "/words",
|
||||||
|
icon: <EventNoteIcon />,
|
||||||
|
},
|
||||||
{ id: "about", label: i18n("about"), url: "/about", icon: <InfoIcon /> },
|
{ id: "about", label: i18n("about"), url: "/about", icon: <InfoIcon /> },
|
||||||
];
|
];
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import {
|
|||||||
URL_KISS_RULES_NEW_ISSUE,
|
URL_KISS_RULES_NEW_ISSUE,
|
||||||
OPT_SYNCTYPE_WORKER,
|
OPT_SYNCTYPE_WORKER,
|
||||||
} from "../../config";
|
} from "../../config";
|
||||||
import { useState, useRef, useEffect, useMemo } from "react";
|
import { useState, useEffect, useMemo } from "react";
|
||||||
import { useI18n } from "../../hooks/I18n";
|
import { useI18n } from "../../hooks/I18n";
|
||||||
import Typography from "@mui/material/Typography";
|
import Typography from "@mui/material/Typography";
|
||||||
import Accordion from "@mui/material/Accordion";
|
import Accordion from "@mui/material/Accordion";
|
||||||
@@ -26,8 +26,6 @@ import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
|
|||||||
import { useRules } from "../../hooks/Rules";
|
import { useRules } from "../../hooks/Rules";
|
||||||
import MenuItem from "@mui/material/MenuItem";
|
import MenuItem from "@mui/material/MenuItem";
|
||||||
import Grid from "@mui/material/Grid";
|
import Grid from "@mui/material/Grid";
|
||||||
import FileDownloadIcon from "@mui/icons-material/FileDownload";
|
|
||||||
import FileUploadIcon from "@mui/icons-material/FileUpload";
|
|
||||||
import { useSetting } from "../../hooks/Setting";
|
import { useSetting } from "../../hooks/Setting";
|
||||||
import FormControlLabel from "@mui/material/FormControlLabel";
|
import FormControlLabel from "@mui/material/FormControlLabel";
|
||||||
import Switch from "@mui/material/Switch";
|
import Switch from "@mui/material/Switch";
|
||||||
@@ -50,6 +48,8 @@ import OwSubRule from "./OwSubRule";
|
|||||||
import ClearAllIcon from "@mui/icons-material/ClearAll";
|
import ClearAllIcon from "@mui/icons-material/ClearAll";
|
||||||
import HelpButton from "./HelpButton";
|
import HelpButton from "./HelpButton";
|
||||||
import { useSyncCaches } from "../../hooks/Sync";
|
import { useSyncCaches } from "../../hooks/Sync";
|
||||||
|
import DownloadButton from "./DownloadButton";
|
||||||
|
import UploadButton from "./UploadButton";
|
||||||
|
|
||||||
function RuleFields({ rule, rules, setShow, setKeyword }) {
|
function RuleFields({ rule, rules, setShow, setKeyword }) {
|
||||||
const initFormValues = rule || {
|
const initFormValues = rule || {
|
||||||
@@ -375,8 +375,9 @@ function RuleAccordion({ rule, rules }) {
|
|||||||
<Accordion expanded={expanded} onChange={handleChange}>
|
<Accordion expanded={expanded} onChange={handleChange}>
|
||||||
<AccordionSummary expandIcon={<ExpandMoreIcon />}>
|
<AccordionSummary expandIcon={<ExpandMoreIcon />}>
|
||||||
<Typography
|
<Typography
|
||||||
style={{
|
sx={{
|
||||||
opacity: rules ? 1 : 0.5,
|
opacity: rules ? 1 : 0.5,
|
||||||
|
overflowWrap: "anywhere",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{rule.pattern === GLOBAL_KEY
|
{rule.pattern === GLOBAL_KEY
|
||||||
@@ -391,56 +392,6 @@ function RuleAccordion({ rule, rules }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function DownloadButton({ data, text, fileName }) {
|
|
||||||
const handleClick = (e) => {
|
|
||||||
e.preventDefault();
|
|
||||||
if (data) {
|
|
||||||
const url = window.URL.createObjectURL(new Blob([data]));
|
|
||||||
const link = document.createElement("a");
|
|
||||||
link.href = url;
|
|
||||||
link.setAttribute("download", fileName || `${Date.now()}.json`);
|
|
||||||
document.body.appendChild(link);
|
|
||||||
link.click();
|
|
||||||
link.remove();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return (
|
|
||||||
<Button
|
|
||||||
size="small"
|
|
||||||
variant="outlined"
|
|
||||||
onClick={handleClick}
|
|
||||||
startIcon={<FileDownloadIcon />}
|
|
||||||
>
|
|
||||||
{text}
|
|
||||||
</Button>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function UploadButton({ onChange, text }) {
|
|
||||||
const inputRef = useRef(null);
|
|
||||||
const handleClick = () => {
|
|
||||||
inputRef.current && inputRef.current.click();
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Button
|
|
||||||
size="small"
|
|
||||||
variant="outlined"
|
|
||||||
onClick={handleClick}
|
|
||||||
startIcon={<FileUploadIcon />}
|
|
||||||
>
|
|
||||||
{text}
|
|
||||||
<input
|
|
||||||
type="file"
|
|
||||||
accept=".json"
|
|
||||||
ref={inputRef}
|
|
||||||
onChange={onChange}
|
|
||||||
hidden
|
|
||||||
/>
|
|
||||||
</Button>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function ShareButton({ rules, injectRules, selectedUrl }) {
|
function ShareButton({ rules, injectRules, selectedUrl }) {
|
||||||
const alert = useAlert();
|
const alert = useAlert();
|
||||||
const i18n = useI18n();
|
const i18n = useI18n();
|
||||||
@@ -493,26 +444,12 @@ function UserRules({ subRules }) {
|
|||||||
const injectRules = !!setting?.injectRules;
|
const injectRules = !!setting?.injectRules;
|
||||||
const { selectedUrl, selectedRules } = subRules;
|
const { selectedUrl, selectedRules } = subRules;
|
||||||
|
|
||||||
const handleImport = (e) => {
|
const handleImport = async (data) => {
|
||||||
const file = e.target.files[0];
|
try {
|
||||||
if (!file) {
|
await rules.merge(JSON.parse(data));
|
||||||
return;
|
} catch (err) {
|
||||||
|
console.log("[import rules]", err);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!file.type.includes("json")) {
|
|
||||||
alert(i18n("error_wrong_file_type"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const reader = new FileReader();
|
|
||||||
reader.onload = async (e) => {
|
|
||||||
try {
|
|
||||||
await rules.merge(JSON.parse(e.target.result));
|
|
||||||
} catch (err) {
|
|
||||||
console.log("[import rules]", err);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
reader.readAsText(file);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleInject = () => {
|
const handleInject = () => {
|
||||||
@@ -552,10 +489,11 @@ function UserRules({ subRules }) {
|
|||||||
{i18n("add")}
|
{i18n("add")}
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<UploadButton text={i18n("import")} onChange={handleImport} />
|
<UploadButton text={i18n("import")} handleImport={handleImport} />
|
||||||
<DownloadButton
|
<DownloadButton
|
||||||
data={JSON.stringify([...rules.list].reverse(), null, 2)}
|
data={JSON.stringify([...rules.list].reverse(), null, 2)}
|
||||||
text={i18n("export")}
|
text={i18n("export")}
|
||||||
|
fileName={`kiss-rules_${Date.now()}.json`}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<ShareButton
|
<ShareButton
|
||||||
@@ -663,7 +601,14 @@ function SubRulesItem({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack direction="row" alignItems="center" spacing={2}>
|
<Stack direction="row" alignItems="center" spacing={2}>
|
||||||
<FormControlLabel value={url} control={<Radio />} label={url} />
|
<FormControlLabel
|
||||||
|
value={url}
|
||||||
|
control={<Radio />}
|
||||||
|
sx={{
|
||||||
|
overflowWrap: "anywhere",
|
||||||
|
}}
|
||||||
|
label={url}
|
||||||
|
/>
|
||||||
|
|
||||||
{syncAt && (
|
{syncAt && (
|
||||||
<span style={{ marginLeft: "0.5em", opacity: 0.5 }}>
|
<span style={{ marginLeft: "0.5em", opacity: 0.5 }}>
|
||||||
|
|||||||
@@ -23,10 +23,14 @@ import {
|
|||||||
OPT_SHORTCUT_STYLE,
|
OPT_SHORTCUT_STYLE,
|
||||||
OPT_SHORTCUT_POPUP,
|
OPT_SHORTCUT_POPUP,
|
||||||
OPT_SHORTCUT_SETTING,
|
OPT_SHORTCUT_SETTING,
|
||||||
|
OPT_LANGS_TO,
|
||||||
|
DEFAULT_BLACKLIST,
|
||||||
|
MSG_CONTEXT_MENUS,
|
||||||
} from "../../config";
|
} from "../../config";
|
||||||
import { useShortcut } from "../../hooks/Shortcut";
|
import { useShortcut } from "../../hooks/Shortcut";
|
||||||
import ShortcutInput from "./ShortcutInput";
|
import ShortcutInput from "./ShortcutInput";
|
||||||
import { useFab } from "../../hooks/Fab";
|
import { useFab } from "../../hooks/Fab";
|
||||||
|
import { sendBgMsg } from "../../libs/msg";
|
||||||
|
|
||||||
function ShortcutItem({ action, label }) {
|
function ShortcutItem({ action, label }) {
|
||||||
const { shortcut, setShortcut } = useShortcut(action);
|
const { shortcut, setShortcut } = useShortcut(action);
|
||||||
@@ -60,6 +64,12 @@ export default function Settings() {
|
|||||||
case "newlineLength":
|
case "newlineLength":
|
||||||
value = limitNumber(value, 1, 1000);
|
value = limitNumber(value, 1, 1000);
|
||||||
break;
|
break;
|
||||||
|
case "touchTranslate":
|
||||||
|
value = limitNumber(value, 0, 4);
|
||||||
|
break;
|
||||||
|
case "contextMenus":
|
||||||
|
isExt && sendBgMsg(MSG_CONTEXT_MENUS, { contextMenus: value });
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
updateSetting({
|
updateSetting({
|
||||||
@@ -85,6 +95,11 @@ export default function Settings() {
|
|||||||
clearCache,
|
clearCache,
|
||||||
newlineLength = TRANS_NEWLINE_LENGTH,
|
newlineLength = TRANS_NEWLINE_LENGTH,
|
||||||
mouseKey = OPT_MOUSEKEY_DISABLE,
|
mouseKey = OPT_MOUSEKEY_DISABLE,
|
||||||
|
detectRemote = false,
|
||||||
|
contextMenus = true,
|
||||||
|
touchTranslate = 2,
|
||||||
|
blacklist = DEFAULT_BLACKLIST.join(",\n"),
|
||||||
|
disableLangs = [],
|
||||||
} = setting;
|
} = setting;
|
||||||
const { isHide = false } = fab || {};
|
const { isHide = false } = fab || {};
|
||||||
|
|
||||||
@@ -168,6 +183,22 @@ export default function Settings() {
|
|||||||
</Select>
|
</Select>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
|
|
||||||
|
<FormControl size="small">
|
||||||
|
<InputLabel>{i18n("touch_translate_shortcut")}</InputLabel>
|
||||||
|
<Select
|
||||||
|
name="touchTranslate"
|
||||||
|
value={touchTranslate}
|
||||||
|
label={i18n("touch_translate_shortcut")}
|
||||||
|
onChange={handleChange}
|
||||||
|
>
|
||||||
|
{[0, 2, 3, 4].map((item) => (
|
||||||
|
<MenuItem key={item} value={item}>
|
||||||
|
{i18n(`touch_tap_${item}`)}
|
||||||
|
</MenuItem>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
|
</FormControl>
|
||||||
|
|
||||||
<FormControl size="small">
|
<FormControl size="small">
|
||||||
<InputLabel>{i18n("hide_fab_button")}</InputLabel>
|
<InputLabel>{i18n("hide_fab_button")}</InputLabel>
|
||||||
<Select
|
<Select
|
||||||
@@ -183,24 +214,71 @@ export default function Settings() {
|
|||||||
</Select>
|
</Select>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
|
|
||||||
|
<FormControl size="small">
|
||||||
|
<InputLabel>{i18n("add_context_menus")}</InputLabel>
|
||||||
|
<Select
|
||||||
|
name="contextMenus"
|
||||||
|
value={contextMenus}
|
||||||
|
label={i18n("add_context_menus")}
|
||||||
|
onChange={handleChange}
|
||||||
|
>
|
||||||
|
<MenuItem value={false}>{i18n("disable")}</MenuItem>
|
||||||
|
<MenuItem value={true}>{i18n("enable")}</MenuItem>
|
||||||
|
</Select>
|
||||||
|
</FormControl>
|
||||||
|
|
||||||
|
<FormControl size="small">
|
||||||
|
<InputLabel>{i18n("detect_lang_remote")}</InputLabel>
|
||||||
|
<Select
|
||||||
|
name="detectRemote"
|
||||||
|
value={detectRemote}
|
||||||
|
label={i18n("detect_lang_remote")}
|
||||||
|
onChange={handleChange}
|
||||||
|
>
|
||||||
|
<MenuItem value={false}>{i18n("disable")}</MenuItem>
|
||||||
|
<MenuItem value={true}>{i18n("enable")}</MenuItem>
|
||||||
|
</Select>
|
||||||
|
<FormHelperText>{i18n("detect_lang_remote_help")}</FormHelperText>
|
||||||
|
</FormControl>
|
||||||
|
|
||||||
|
<FormControl size="small">
|
||||||
|
<InputLabel>{i18n("disable_langs")}</InputLabel>
|
||||||
|
<Select
|
||||||
|
multiple
|
||||||
|
name="disableLangs"
|
||||||
|
value={disableLangs}
|
||||||
|
label={i18n("disable_langs")}
|
||||||
|
onChange={handleChange}
|
||||||
|
>
|
||||||
|
{OPT_LANGS_TO.map(([langKey, langName]) => (
|
||||||
|
<MenuItem key={langKey} value={langKey}>
|
||||||
|
{langName}
|
||||||
|
</MenuItem>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
|
<FormHelperText>{i18n("disable_langs_helper")}</FormHelperText>
|
||||||
|
</FormControl>
|
||||||
|
|
||||||
{isExt ? (
|
{isExt ? (
|
||||||
<FormControl size="small">
|
<>
|
||||||
<InputLabel>{i18n("if_clear_cache")}</InputLabel>
|
<FormControl size="small">
|
||||||
<Select
|
<InputLabel>{i18n("if_clear_cache")}</InputLabel>
|
||||||
name="clearCache"
|
<Select
|
||||||
value={clearCache}
|
name="clearCache"
|
||||||
label={i18n("if_clear_cache")}
|
value={clearCache}
|
||||||
onChange={handleChange}
|
label={i18n("if_clear_cache")}
|
||||||
>
|
onChange={handleChange}
|
||||||
<MenuItem value={false}>{i18n("clear_cache_never")}</MenuItem>
|
>
|
||||||
<MenuItem value={true}>{i18n("clear_cache_restart")}</MenuItem>
|
<MenuItem value={false}>{i18n("clear_cache_never")}</MenuItem>
|
||||||
</Select>
|
<MenuItem value={true}>{i18n("clear_cache_restart")}</MenuItem>
|
||||||
<FormHelperText>
|
</Select>
|
||||||
<Link component="button" onClick={handleClearCache}>
|
<FormHelperText>
|
||||||
{i18n("clear_all_cache_now")}
|
<Link component="button" onClick={handleClearCache}>
|
||||||
</Link>
|
{i18n("clear_all_cache_now")}
|
||||||
</FormHelperText>
|
</Link>
|
||||||
</FormControl>
|
</FormHelperText>
|
||||||
|
</FormControl>
|
||||||
|
</>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<Box>
|
<Box>
|
||||||
@@ -233,6 +311,16 @@ export default function Settings() {
|
|||||||
</Box>
|
</Box>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
<TextField
|
||||||
|
size="small"
|
||||||
|
label={i18n("translate_blacklist")}
|
||||||
|
helperText={i18n("pattern_helper")}
|
||||||
|
name="blacklist"
|
||||||
|
defaultValue={blacklist}
|
||||||
|
onChange={handleChange}
|
||||||
|
multiline
|
||||||
|
/>
|
||||||
</Stack>
|
</Stack>
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
|
|||||||
170
src/views/Options/Tranbox.js
Normal file
170
src/views/Options/Tranbox.js
Normal file
@@ -0,0 +1,170 @@
|
|||||||
|
import Box from "@mui/material/Box";
|
||||||
|
import Stack from "@mui/material/Stack";
|
||||||
|
import TextField from "@mui/material/TextField";
|
||||||
|
import MenuItem from "@mui/material/MenuItem";
|
||||||
|
import { useI18n } from "../../hooks/I18n";
|
||||||
|
import { OPT_TRANS_ALL, OPT_LANGS_FROM, OPT_LANGS_TO } from "../../config";
|
||||||
|
import ShortcutInput from "./ShortcutInput";
|
||||||
|
import FormControlLabel from "@mui/material/FormControlLabel";
|
||||||
|
import Switch from "@mui/material/Switch";
|
||||||
|
import { useCallback } from "react";
|
||||||
|
import { limitNumber } from "../../libs/utils";
|
||||||
|
import { useTranbox } from "../../hooks/Tranbox";
|
||||||
|
|
||||||
|
export default function Tranbox() {
|
||||||
|
const i18n = useI18n();
|
||||||
|
const { tranboxSetting, updateTranbox } = useTranbox();
|
||||||
|
|
||||||
|
const handleChange = (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
let { name, value } = e.target;
|
||||||
|
switch (name) {
|
||||||
|
case "btnOffsetX":
|
||||||
|
value = limitNumber(value, 0, 100);
|
||||||
|
break;
|
||||||
|
case "btnOffsetY":
|
||||||
|
value = limitNumber(value, 0, 100);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
updateTranbox({
|
||||||
|
[name]: value,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleShortcutInput = useCallback(
|
||||||
|
(val) => {
|
||||||
|
updateTranbox({ tranboxShortcut: val });
|
||||||
|
},
|
||||||
|
[updateTranbox]
|
||||||
|
);
|
||||||
|
|
||||||
|
const {
|
||||||
|
transOpen,
|
||||||
|
translator,
|
||||||
|
fromLang,
|
||||||
|
toLang,
|
||||||
|
toLang2 = "en",
|
||||||
|
tranboxShortcut,
|
||||||
|
btnOffsetX,
|
||||||
|
btnOffsetY,
|
||||||
|
hideTranBtn = false,
|
||||||
|
} = tranboxSetting;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box>
|
||||||
|
<Stack spacing={3}>
|
||||||
|
<FormControlLabel
|
||||||
|
control={
|
||||||
|
<Switch
|
||||||
|
size="small"
|
||||||
|
name="transOpen"
|
||||||
|
checked={transOpen}
|
||||||
|
onChange={() => {
|
||||||
|
updateTranbox({ transOpen: !transOpen });
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
label={i18n("toggle_selection_translate")}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<TextField
|
||||||
|
select
|
||||||
|
size="small"
|
||||||
|
name="translator"
|
||||||
|
value={translator}
|
||||||
|
label={i18n("translate_service")}
|
||||||
|
onChange={handleChange}
|
||||||
|
>
|
||||||
|
{OPT_TRANS_ALL.map((item) => (
|
||||||
|
<MenuItem key={item} value={item}>
|
||||||
|
{item}
|
||||||
|
</MenuItem>
|
||||||
|
))}
|
||||||
|
</TextField>
|
||||||
|
|
||||||
|
<TextField
|
||||||
|
select
|
||||||
|
size="small"
|
||||||
|
name="fromLang"
|
||||||
|
value={fromLang}
|
||||||
|
label={i18n("from_lang")}
|
||||||
|
onChange={handleChange}
|
||||||
|
>
|
||||||
|
{OPT_LANGS_FROM.map(([lang, name]) => (
|
||||||
|
<MenuItem key={lang} value={lang}>
|
||||||
|
{name}
|
||||||
|
</MenuItem>
|
||||||
|
))}
|
||||||
|
</TextField>
|
||||||
|
|
||||||
|
<TextField
|
||||||
|
select
|
||||||
|
size="small"
|
||||||
|
name="toLang"
|
||||||
|
value={toLang}
|
||||||
|
label={i18n("to_lang")}
|
||||||
|
onChange={handleChange}
|
||||||
|
>
|
||||||
|
{OPT_LANGS_TO.map(([lang, name]) => (
|
||||||
|
<MenuItem key={lang} value={lang}>
|
||||||
|
{name}
|
||||||
|
</MenuItem>
|
||||||
|
))}
|
||||||
|
</TextField>
|
||||||
|
|
||||||
|
<TextField
|
||||||
|
select
|
||||||
|
size="small"
|
||||||
|
name="toLang2"
|
||||||
|
value={toLang2}
|
||||||
|
label={i18n("to_lang2")}
|
||||||
|
helperText={i18n("to_lang2_helper")}
|
||||||
|
onChange={handleChange}
|
||||||
|
>
|
||||||
|
{[["none", "None"], ...OPT_LANGS_TO].map(([lang, name]) => (
|
||||||
|
<MenuItem key={lang} value={lang}>
|
||||||
|
{name}
|
||||||
|
</MenuItem>
|
||||||
|
))}
|
||||||
|
</TextField>
|
||||||
|
|
||||||
|
<TextField
|
||||||
|
size="small"
|
||||||
|
label={i18n("tranbtn_offset_x")}
|
||||||
|
type="number"
|
||||||
|
name="btnOffsetX"
|
||||||
|
defaultValue={btnOffsetX}
|
||||||
|
onChange={handleChange}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<TextField
|
||||||
|
size="small"
|
||||||
|
label={i18n("tranbtn_offset_y")}
|
||||||
|
type="number"
|
||||||
|
name="btnOffsetY"
|
||||||
|
defaultValue={btnOffsetY}
|
||||||
|
onChange={handleChange}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<TextField
|
||||||
|
select
|
||||||
|
size="small"
|
||||||
|
name="hideTranBtn"
|
||||||
|
value={hideTranBtn}
|
||||||
|
label={i18n("hide_tran_button")}
|
||||||
|
onChange={handleChange}
|
||||||
|
>
|
||||||
|
<MenuItem value={false}>{i18n("show")}</MenuItem>
|
||||||
|
<MenuItem value={true}>{i18n("hide")}</MenuItem>
|
||||||
|
</TextField>
|
||||||
|
|
||||||
|
<ShortcutInput
|
||||||
|
value={tranboxShortcut}
|
||||||
|
onChange={handleShortcutInput}
|
||||||
|
label={i18n("trigger_tranbox_shortcut")}
|
||||||
|
/>
|
||||||
|
</Stack>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}
|
||||||
55
src/views/Options/UploadButton.js
Normal file
55
src/views/Options/UploadButton.js
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
import { useRef } from "react";
|
||||||
|
import FileUploadIcon from "@mui/icons-material/FileUpload";
|
||||||
|
import { useI18n } from "../../hooks/I18n";
|
||||||
|
import Button from "@mui/material/Button";
|
||||||
|
|
||||||
|
export default function UploadButton({
|
||||||
|
handleImport,
|
||||||
|
text,
|
||||||
|
fileType = "json",
|
||||||
|
fileExts = [".json"],
|
||||||
|
}) {
|
||||||
|
const i18n = useI18n();
|
||||||
|
const inputRef = useRef(null);
|
||||||
|
const handleClick = () => {
|
||||||
|
if (inputRef.current) {
|
||||||
|
inputRef.current.click();
|
||||||
|
inputRef.current.value = null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const onChange = (e) => {
|
||||||
|
const file = e.target.files[0];
|
||||||
|
if (!file) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!file.type.includes(fileType)) {
|
||||||
|
alert(i18n("error_wrong_file_type"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const reader = new FileReader();
|
||||||
|
reader.onload = async (e) => {
|
||||||
|
handleImport(e.target.result);
|
||||||
|
};
|
||||||
|
reader.readAsText(file);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
size="small"
|
||||||
|
variant="outlined"
|
||||||
|
onClick={handleClick}
|
||||||
|
startIcon={<FileUploadIcon />}
|
||||||
|
>
|
||||||
|
{text}
|
||||||
|
<input
|
||||||
|
type="file"
|
||||||
|
accept={fileExts.join(", ")}
|
||||||
|
ref={inputRef}
|
||||||
|
onChange={onChange}
|
||||||
|
hidden
|
||||||
|
/>
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -13,43 +13,204 @@ import FormControlLabel from "@mui/material/FormControlLabel";
|
|||||||
import Switch from "@mui/material/Switch";
|
import Switch from "@mui/material/Switch";
|
||||||
import { useSetting } from "../../hooks/Setting";
|
import { useSetting } from "../../hooks/Setting";
|
||||||
import CircularProgress from "@mui/material/CircularProgress";
|
import CircularProgress from "@mui/material/CircularProgress";
|
||||||
import { syncWebfix, loadOrFetchWebfix } from "../../libs/webfix";
|
import { syncWebfix, loadOrFetchWebfix, FIXER_ALL } from "../../libs/webfix";
|
||||||
import Button from "@mui/material/Button";
|
import Button from "@mui/material/Button";
|
||||||
import SyncIcon from "@mui/icons-material/Sync";
|
import SyncIcon from "@mui/icons-material/Sync";
|
||||||
import { useAlert } from "../../hooks/Alert";
|
import { useAlert } from "../../hooks/Alert";
|
||||||
import HelpButton from "./HelpButton";
|
import HelpButton from "./HelpButton";
|
||||||
import { URL_KISS_RULES_NEW_ISSUE } from "../../config";
|
import { URL_KISS_RULES_NEW_ISSUE } from "../../config";
|
||||||
|
import MenuItem from "@mui/material/MenuItem";
|
||||||
|
import { useWebfixRules } from "../../hooks/WebfixRules";
|
||||||
|
|
||||||
|
function WebfixFields({ rule, webfix, setShow }) {
|
||||||
|
const editMode = !!rule;
|
||||||
|
const initFormValues = rule || {
|
||||||
|
pattern: "",
|
||||||
|
selector: "",
|
||||||
|
rootSelector: "",
|
||||||
|
fixer: FIXER_ALL[0],
|
||||||
|
};
|
||||||
|
const i18n = useI18n();
|
||||||
|
const [disabled, setDisabled] = useState(editMode);
|
||||||
|
const [errors, setErrors] = useState({});
|
||||||
|
const [formValues, setFormValues] = useState(initFormValues);
|
||||||
|
|
||||||
|
const { pattern, selector, rootSelector, fixer } = formValues;
|
||||||
|
|
||||||
|
const hasSamePattern = (str) => {
|
||||||
|
for (const item of webfix.list || []) {
|
||||||
|
if (item.pattern === str && rule?.pattern !== str) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleFocus = (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
const { name } = e.target;
|
||||||
|
setErrors((pre) => ({ ...pre, [name]: "" }));
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleChange = (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
const { name, value } = e.target;
|
||||||
|
setFormValues((pre) => ({ ...pre, [name]: value }));
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleCancel = (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
if (editMode) {
|
||||||
|
setDisabled(true);
|
||||||
|
} else {
|
||||||
|
setShow(false);
|
||||||
|
}
|
||||||
|
setFormValues(initFormValues);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSubmit = (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
const errors = {};
|
||||||
|
if (!pattern.trim()) {
|
||||||
|
errors.pattern = i18n("error_cant_be_blank");
|
||||||
|
}
|
||||||
|
if (hasSamePattern(pattern)) {
|
||||||
|
errors.pattern = i18n("error_duplicate_values");
|
||||||
|
}
|
||||||
|
if (!selector.trim()) {
|
||||||
|
errors.selector = i18n("error_cant_be_blank");
|
||||||
|
}
|
||||||
|
if (Object.keys(errors).length > 0) {
|
||||||
|
setErrors(errors);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (editMode) {
|
||||||
|
// 编辑
|
||||||
|
setDisabled(true);
|
||||||
|
webfix.put(rule.pattern, formValues);
|
||||||
|
} else {
|
||||||
|
// 添加
|
||||||
|
webfix.add(formValues);
|
||||||
|
setShow(false);
|
||||||
|
setFormValues(initFormValues);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
function ApiFields({ site }) {
|
|
||||||
const { selector, rootSelector, fixer } = site;
|
|
||||||
return (
|
return (
|
||||||
<Stack spacing={3}>
|
<form onSubmit={handleSubmit}>
|
||||||
<TextField
|
<Stack spacing={3}>
|
||||||
size="small"
|
<TextField
|
||||||
label={"rootSelector"}
|
size="small"
|
||||||
name="rootSelector"
|
label={i18n("pattern")}
|
||||||
value={rootSelector || "document"}
|
error={!!errors.pattern}
|
||||||
disabled
|
helperText={errors.pattern}
|
||||||
/>
|
name="pattern"
|
||||||
<TextField
|
value={pattern}
|
||||||
size="small"
|
disabled={disabled}
|
||||||
label={"selector"}
|
onChange={handleChange}
|
||||||
name="selector"
|
onFocus={handleFocus}
|
||||||
value={selector}
|
multiline
|
||||||
disabled
|
/>
|
||||||
/>
|
<TextField
|
||||||
<TextField
|
size="small"
|
||||||
size="small"
|
label={i18n("root_selector")}
|
||||||
label={"fixer"}
|
error={!!errors.rootSelector}
|
||||||
name="fixer"
|
helperText={errors.rootSelector}
|
||||||
value={fixer}
|
name="rootSelector"
|
||||||
disabled
|
value={rootSelector}
|
||||||
/>
|
disabled={disabled}
|
||||||
</Stack>
|
onChange={handleChange}
|
||||||
|
onFocus={handleFocus}
|
||||||
|
multiline
|
||||||
|
/>
|
||||||
|
<TextField
|
||||||
|
size="small"
|
||||||
|
label={i18n("selector")}
|
||||||
|
error={!!errors.selector}
|
||||||
|
helperText={errors.selector}
|
||||||
|
name="selector"
|
||||||
|
value={selector}
|
||||||
|
disabled={disabled}
|
||||||
|
onChange={handleChange}
|
||||||
|
onFocus={handleFocus}
|
||||||
|
multiline
|
||||||
|
/>
|
||||||
|
<TextField
|
||||||
|
select
|
||||||
|
size="small"
|
||||||
|
name="fixer"
|
||||||
|
value={fixer}
|
||||||
|
label={i18n("fixer_function")}
|
||||||
|
disabled={disabled}
|
||||||
|
onChange={handleChange}
|
||||||
|
>
|
||||||
|
{FIXER_ALL.map((item) => (
|
||||||
|
<MenuItem key={item} value={item}>
|
||||||
|
{item}
|
||||||
|
</MenuItem>
|
||||||
|
))}
|
||||||
|
</TextField>
|
||||||
|
|
||||||
|
{webfix &&
|
||||||
|
(editMode ? (
|
||||||
|
// 编辑
|
||||||
|
<Stack direction="row" spacing={2}>
|
||||||
|
{disabled ? (
|
||||||
|
<>
|
||||||
|
<Button
|
||||||
|
size="small"
|
||||||
|
variant="contained"
|
||||||
|
onClick={(e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
setDisabled(false);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{i18n("edit")}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
size="small"
|
||||||
|
variant="outlined"
|
||||||
|
onClick={(e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
webfix.del(rule.pattern);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{i18n("delete")}
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<Button size="small" variant="contained" type="submit">
|
||||||
|
{i18n("save")}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
size="small"
|
||||||
|
variant="outlined"
|
||||||
|
onClick={handleCancel}
|
||||||
|
>
|
||||||
|
{i18n("cancel")}
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Stack>
|
||||||
|
) : (
|
||||||
|
// 添加
|
||||||
|
<Stack direction="row" spacing={2}>
|
||||||
|
<Button size="small" variant="contained" type="submit">
|
||||||
|
{i18n("save")}
|
||||||
|
</Button>
|
||||||
|
<Button size="small" variant="outlined" onClick={handleCancel}>
|
||||||
|
{i18n("cancel")}
|
||||||
|
</Button>
|
||||||
|
</Stack>
|
||||||
|
))}
|
||||||
|
</Stack>
|
||||||
|
</form>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function ApiAccordion({ site }) {
|
function WebfixAccordion({ rule, webfix }) {
|
||||||
const [expanded, setExpanded] = useState(false);
|
const [expanded, setExpanded] = useState(false);
|
||||||
|
|
||||||
const handleChange = (e) => {
|
const handleChange = (e) => {
|
||||||
@@ -59,10 +220,17 @@ function ApiAccordion({ site }) {
|
|||||||
return (
|
return (
|
||||||
<Accordion expanded={expanded} onChange={handleChange}>
|
<Accordion expanded={expanded} onChange={handleChange}>
|
||||||
<AccordionSummary expandIcon={<ExpandMoreIcon />}>
|
<AccordionSummary expandIcon={<ExpandMoreIcon />}>
|
||||||
<Typography>{site.pattern}</Typography>
|
<Typography
|
||||||
|
sx={{
|
||||||
|
opacity: webfix ? 1 : 0.5,
|
||||||
|
overflowWrap: "anywhere",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{rule.pattern}
|
||||||
|
</Typography>
|
||||||
</AccordionSummary>
|
</AccordionSummary>
|
||||||
<AccordionDetails>
|
<AccordionDetails>
|
||||||
{expanded && <ApiFields site={site} />}
|
{expanded && <WebfixFields rule={rule} webfix={webfix} />}
|
||||||
</AccordionDetails>
|
</AccordionDetails>
|
||||||
</Accordion>
|
</Accordion>
|
||||||
);
|
);
|
||||||
@@ -74,6 +242,8 @@ export default function Webfix() {
|
|||||||
const i18n = useI18n();
|
const i18n = useI18n();
|
||||||
const alert = useAlert();
|
const alert = useAlert();
|
||||||
const { setting, updateSetting } = useSetting();
|
const { setting, updateSetting } = useSetting();
|
||||||
|
const [showAdd, setShowAdd] = useState(false);
|
||||||
|
const webfix = useWebfixRules();
|
||||||
|
|
||||||
const loadSites = useCallback(async () => {
|
const loadSites = useCallback(async () => {
|
||||||
const sites = await loadOrFetchWebfix(process.env.REACT_APP_WEBFIXURL);
|
const sites = await loadOrFetchWebfix(process.env.REACT_APP_WEBFIXURL);
|
||||||
@@ -120,6 +290,18 @@ export default function Webfix() {
|
|||||||
useFlexGap
|
useFlexGap
|
||||||
flexWrap="wrap"
|
flexWrap="wrap"
|
||||||
>
|
>
|
||||||
|
<Button
|
||||||
|
size="small"
|
||||||
|
variant="contained"
|
||||||
|
disabled={showAdd}
|
||||||
|
onClick={(e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
setShowAdd(true);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{i18n("add")}
|
||||||
|
</Button>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
size="small"
|
size="small"
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
@@ -146,6 +328,16 @@ export default function Webfix() {
|
|||||||
/>
|
/>
|
||||||
</Stack>
|
</Stack>
|
||||||
|
|
||||||
|
{showAdd && <WebfixFields webfix={webfix} setShow={setShowAdd} />}
|
||||||
|
|
||||||
|
{webfix.list?.length > 0 && (
|
||||||
|
<Box>
|
||||||
|
{webfix.list.map((rule) => (
|
||||||
|
<WebfixAccordion key={rule.pattern} rule={rule} webfix={webfix} />
|
||||||
|
))}
|
||||||
|
</Box>
|
||||||
|
)}
|
||||||
|
|
||||||
{setting.injectWebfix && (
|
{setting.injectWebfix && (
|
||||||
<Box>
|
<Box>
|
||||||
{loading ? (
|
{loading ? (
|
||||||
@@ -153,8 +345,8 @@ export default function Webfix() {
|
|||||||
<CircularProgress size={16} />
|
<CircularProgress size={16} />
|
||||||
</center>
|
</center>
|
||||||
) : (
|
) : (
|
||||||
sites.map((site) => (
|
sites.map((rule) => (
|
||||||
<ApiAccordion key={site.pattern} site={site} />
|
<WebfixAccordion key={rule.pattern} rule={rule} />
|
||||||
))
|
))
|
||||||
)}
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ import Alert from "@mui/material/Alert";
|
|||||||
import Apis from "./Apis";
|
import Apis from "./Apis";
|
||||||
import Webfix from "./Webfix";
|
import Webfix from "./Webfix";
|
||||||
import InputSetting from "./InputSetting";
|
import InputSetting from "./InputSetting";
|
||||||
|
import Tranbox from "./Tranbox";
|
||||||
|
import FavWords from "./FavWords";
|
||||||
|
|
||||||
export default function Options() {
|
export default function Options() {
|
||||||
const [error, setError] = useState("");
|
const [error, setError] = useState("");
|
||||||
@@ -120,9 +122,11 @@ export default function Options() {
|
|||||||
<Route index element={<Setting />} />
|
<Route index element={<Setting />} />
|
||||||
<Route path="rules" element={<Rules />} />
|
<Route path="rules" element={<Rules />} />
|
||||||
<Route path="input" element={<InputSetting />} />
|
<Route path="input" element={<InputSetting />} />
|
||||||
|
<Route path="tranbox" element={<Tranbox />} />
|
||||||
<Route path="apis" element={<Apis />} />
|
<Route path="apis" element={<Apis />} />
|
||||||
<Route path="sync" element={<SyncSetting />} />
|
<Route path="sync" element={<SyncSetting />} />
|
||||||
<Route path="webfix" element={<Webfix />} />
|
<Route path="webfix" element={<Webfix />} />
|
||||||
|
<Route path="words" element={<FavWords />} />
|
||||||
<Route path="about" element={<About />} />
|
<Route path="about" element={<About />} />
|
||||||
</Route>
|
</Route>
|
||||||
</Routes>
|
</Routes>
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import Box from "@mui/material/Box";
|
|
||||||
import IconButton from "@mui/material/IconButton";
|
import IconButton from "@mui/material/IconButton";
|
||||||
import CloseIcon from "@mui/icons-material/Close";
|
import CloseIcon from "@mui/icons-material/Close";
|
||||||
import HomeIcon from "@mui/icons-material/Home";
|
import HomeIcon from "@mui/icons-material/Home";
|
||||||
import Stack from "@mui/material/Stack";
|
import Stack from "@mui/material/Stack";
|
||||||
import DarkModeButton from "../Options/DarkModeButton";
|
import DarkModeButton from "../Options/DarkModeButton";
|
||||||
|
import Typography from "@mui/material/Typography";
|
||||||
|
|
||||||
export default function Header({ setShowPopup }) {
|
export default function Header({ setShowPopup }) {
|
||||||
const handleHomepage = () => {
|
const handleHomepage = () => {
|
||||||
@@ -21,14 +21,16 @@ export default function Header({ setShowPopup }) {
|
|||||||
<IconButton onClick={handleHomepage}>
|
<IconButton onClick={handleHomepage}>
|
||||||
<HomeIcon />
|
<HomeIcon />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
<Box
|
<Typography
|
||||||
|
component="div"
|
||||||
sx={{
|
sx={{
|
||||||
userSelect: "none",
|
userSelect: "none",
|
||||||
WebkitUserSelect: "none",
|
WebkitUserSelect: "none",
|
||||||
|
fontWeight: "bold",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{`${process.env.REACT_APP_NAME} v${process.env.REACT_APP_VERSION}`}
|
{`${process.env.REACT_APP_NAME} v${process.env.REACT_APP_VERSION}`}
|
||||||
</Box>
|
</Typography>
|
||||||
</Stack>
|
</Stack>
|
||||||
|
|
||||||
{setShowPopup ? (
|
{setShowPopup ? (
|
||||||
|
|||||||
35
src/views/Selection/CopyBtn.js
Normal file
35
src/views/Selection/CopyBtn.js
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
import IconButton from "@mui/material/IconButton";
|
||||||
|
import ContentCopyIcon from "@mui/icons-material/ContentCopy";
|
||||||
|
import LibraryAddCheckIcon from "@mui/icons-material/LibraryAddCheck";
|
||||||
|
import { useState } from "react";
|
||||||
|
|
||||||
|
export default function CopyBtn({ text }) {
|
||||||
|
const [copied, setCopied] = useState(false);
|
||||||
|
const handleClick = async (e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
await navigator.clipboard.writeText(text);
|
||||||
|
setCopied(true);
|
||||||
|
const timer = setTimeout(() => {
|
||||||
|
clearTimeout(timer);
|
||||||
|
setCopied(false);
|
||||||
|
}, 500);
|
||||||
|
};
|
||||||
|
return (
|
||||||
|
<IconButton
|
||||||
|
size="small"
|
||||||
|
sx={{
|
||||||
|
opacity: 0.5,
|
||||||
|
"&:hover": {
|
||||||
|
opacity: 1,
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
onClick={handleClick}
|
||||||
|
>
|
||||||
|
{copied ? (
|
||||||
|
<LibraryAddCheckIcon fontSize="inherit" />
|
||||||
|
) : (
|
||||||
|
<ContentCopyIcon fontSize="inherit" />
|
||||||
|
)}
|
||||||
|
</IconButton>
|
||||||
|
);
|
||||||
|
}
|
||||||
65
src/views/Selection/DictCont.js
Normal file
65
src/views/Selection/DictCont.js
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
import Box from "@mui/material/Box";
|
||||||
|
import Chip from "@mui/material/Chip";
|
||||||
|
import Stack from "@mui/material/Stack";
|
||||||
|
import FavBtn from "./FavBtn";
|
||||||
|
import Typography from "@mui/material/Typography";
|
||||||
|
|
||||||
|
const exchangeMap = {
|
||||||
|
word_third: "第三人称单数",
|
||||||
|
word_ing: "现在分词",
|
||||||
|
word_done: "过去式",
|
||||||
|
word_past: "过去分词",
|
||||||
|
word_pl: "复数",
|
||||||
|
word_proto: "词源",
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function DictCont({ dictResult }) {
|
||||||
|
if (!dictResult) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box>
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
justifyContent="space-between"
|
||||||
|
alignItems="flex-start"
|
||||||
|
>
|
||||||
|
<Typography variant="subtitle1" style={{ fontWeight: "bold" }}>
|
||||||
|
{dictResult.simple_means?.word_name}
|
||||||
|
</Typography>
|
||||||
|
<FavBtn word={dictResult.simple_means?.word_name} />
|
||||||
|
</Stack>
|
||||||
|
|
||||||
|
{dictResult.simple_means?.symbols?.map(({ ph_en, ph_am, parts }, idx) => (
|
||||||
|
<Typography key={idx} component="div">
|
||||||
|
{(ph_en || ph_am) && (
|
||||||
|
<Typography>{`英 /${ph_en || ""}/ 美 /${ph_am || ""}/`}</Typography>
|
||||||
|
)}
|
||||||
|
<ul style={{ margin: "0.5em 0" }}>
|
||||||
|
{parts.map(({ part, means }, idx) => (
|
||||||
|
<li key={idx}>
|
||||||
|
{part ? `[${part}] ${means.join("; ")}` : means.join("; ")}
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
</Typography>
|
||||||
|
))}
|
||||||
|
|
||||||
|
<Typography>
|
||||||
|
{Object.entries(dictResult.simple_means?.exchange || {})
|
||||||
|
.map(([key, val]) => `${exchangeMap[key] || key}: ${val.join(", ")}`)
|
||||||
|
.join("; ")}
|
||||||
|
</Typography>
|
||||||
|
|
||||||
|
<Stack direction="row" spacing={1} flexWrap="wrap" useFlexGap>
|
||||||
|
{Object.values(dictResult.simple_means?.tags || {})
|
||||||
|
.flat()
|
||||||
|
.filter((item) => item)
|
||||||
|
.map((item) => (
|
||||||
|
<Chip label={item} size="small" />
|
||||||
|
))}
|
||||||
|
</Stack>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}
|
||||||
258
src/views/Selection/DraggableResizable.js
Normal file
258
src/views/Selection/DraggableResizable.js
Normal file
@@ -0,0 +1,258 @@
|
|||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import Paper from "@mui/material/Paper";
|
||||||
|
import Box from "@mui/material/Box";
|
||||||
|
|
||||||
|
function Pointer({
|
||||||
|
direction,
|
||||||
|
size,
|
||||||
|
setSize,
|
||||||
|
position,
|
||||||
|
setPosition,
|
||||||
|
children,
|
||||||
|
minSize,
|
||||||
|
maxSize,
|
||||||
|
...props
|
||||||
|
}) {
|
||||||
|
const [origin, setOrigin] = useState(null);
|
||||||
|
|
||||||
|
function handlePointerDown(e) {
|
||||||
|
e.target.setPointerCapture(e.pointerId);
|
||||||
|
setOrigin({
|
||||||
|
x: position.x,
|
||||||
|
y: position.y,
|
||||||
|
w: size.w,
|
||||||
|
h: size.h,
|
||||||
|
clientX: e.clientX,
|
||||||
|
clientY: e.clientY,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function handlePointerMove(e) {
|
||||||
|
if (origin) {
|
||||||
|
const dx = e.clientX - origin.clientX;
|
||||||
|
const dy = e.clientY - origin.clientY;
|
||||||
|
let x = position.x;
|
||||||
|
let y = position.y;
|
||||||
|
let w = size.w;
|
||||||
|
let h = size.h;
|
||||||
|
|
||||||
|
switch (direction) {
|
||||||
|
case "Header":
|
||||||
|
x = origin.x + dx;
|
||||||
|
y = origin.y + dy;
|
||||||
|
break;
|
||||||
|
case "TopLeft":
|
||||||
|
x = origin.x + dx;
|
||||||
|
y = origin.y + dy;
|
||||||
|
w = origin.w - dx;
|
||||||
|
h = origin.h - dy;
|
||||||
|
break;
|
||||||
|
case "Top":
|
||||||
|
y = origin.y + dy;
|
||||||
|
h = origin.h - dy;
|
||||||
|
break;
|
||||||
|
case "TopRight":
|
||||||
|
y = origin.y + dy;
|
||||||
|
w = origin.w + dx;
|
||||||
|
h = origin.h - dy;
|
||||||
|
break;
|
||||||
|
case "Left":
|
||||||
|
x = origin.x + dx;
|
||||||
|
w = origin.w - dx;
|
||||||
|
break;
|
||||||
|
case "Right":
|
||||||
|
w = origin.w + dx;
|
||||||
|
break;
|
||||||
|
case "BottomLeft":
|
||||||
|
x = origin.x + dx;
|
||||||
|
w = origin.w - dx;
|
||||||
|
h = origin.h + dy;
|
||||||
|
break;
|
||||||
|
case "Bottom":
|
||||||
|
h = origin.h + dy;
|
||||||
|
break;
|
||||||
|
case "BottomRight":
|
||||||
|
w = origin.w + dx;
|
||||||
|
h = origin.h + dy;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
|
||||||
|
if (w < minSize.w) {
|
||||||
|
w = minSize.w;
|
||||||
|
x = position.x;
|
||||||
|
}
|
||||||
|
if (w > maxSize.w) {
|
||||||
|
w = maxSize.w;
|
||||||
|
x = position.x;
|
||||||
|
}
|
||||||
|
if (h < minSize.h) {
|
||||||
|
h = minSize.h;
|
||||||
|
y = position.y;
|
||||||
|
}
|
||||||
|
if (h > maxSize.h) {
|
||||||
|
h = maxSize.h;
|
||||||
|
y = position.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
setPosition({ x, y });
|
||||||
|
setSize({ w, h });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function handlePointerUp(e) {
|
||||||
|
setOrigin(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
{...props}
|
||||||
|
onPointerDown={handlePointerDown}
|
||||||
|
onPointerMove={handlePointerMove}
|
||||||
|
onPointerUp={handlePointerUp}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function DraggableResizable({
|
||||||
|
header,
|
||||||
|
children,
|
||||||
|
defaultPosition = {
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
},
|
||||||
|
defaultSize = {
|
||||||
|
w: 600,
|
||||||
|
h: 400,
|
||||||
|
},
|
||||||
|
minSize = {
|
||||||
|
w: 300,
|
||||||
|
h: 200,
|
||||||
|
},
|
||||||
|
maxSize = {
|
||||||
|
w: 1200,
|
||||||
|
h: 1200,
|
||||||
|
},
|
||||||
|
onChangeSize,
|
||||||
|
onChangePosition,
|
||||||
|
}) {
|
||||||
|
const lineWidth = 4;
|
||||||
|
const [position, setPosition] = useState(defaultPosition);
|
||||||
|
const [size, setSize] = useState(defaultSize);
|
||||||
|
|
||||||
|
const opts = {
|
||||||
|
size,
|
||||||
|
setSize,
|
||||||
|
position,
|
||||||
|
setPosition,
|
||||||
|
minSize,
|
||||||
|
maxSize,
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
onChangeSize && onChangeSize(size);
|
||||||
|
}, [size, onChangeSize]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
onChangePosition && onChangePosition(position);
|
||||||
|
}, [position, onChangePosition]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box
|
||||||
|
style={{
|
||||||
|
position: "fixed",
|
||||||
|
left: position.x,
|
||||||
|
top: position.y,
|
||||||
|
display: "grid",
|
||||||
|
gridTemplateColumns: `${lineWidth * 2}px auto ${lineWidth * 2}px`,
|
||||||
|
gridTemplateRows: `${lineWidth * 2}px auto ${lineWidth * 2}px`,
|
||||||
|
zIndex: 2147483647,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Pointer
|
||||||
|
direction="TopLeft"
|
||||||
|
style={{
|
||||||
|
transform: `translate(${lineWidth}px, ${lineWidth}px)`,
|
||||||
|
cursor: "nw-resize",
|
||||||
|
}}
|
||||||
|
{...opts}
|
||||||
|
/>
|
||||||
|
<Pointer
|
||||||
|
direction="Top"
|
||||||
|
style={{
|
||||||
|
margin: `0 ${lineWidth}px`,
|
||||||
|
transform: `translate(0px, ${lineWidth}px)`,
|
||||||
|
cursor: "row-resize",
|
||||||
|
}}
|
||||||
|
{...opts}
|
||||||
|
/>
|
||||||
|
<Pointer
|
||||||
|
direction="TopRight"
|
||||||
|
style={{
|
||||||
|
transform: `translate(-${lineWidth}px, ${lineWidth}px)`,
|
||||||
|
cursor: "ne-resize",
|
||||||
|
}}
|
||||||
|
{...opts}
|
||||||
|
/>
|
||||||
|
<Pointer
|
||||||
|
direction="Left"
|
||||||
|
style={{
|
||||||
|
margin: `${lineWidth}px 0`,
|
||||||
|
transform: `translate(${lineWidth}px, 0px)`,
|
||||||
|
cursor: "col-resize",
|
||||||
|
}}
|
||||||
|
{...opts}
|
||||||
|
/>
|
||||||
|
<Paper elevation={4}>
|
||||||
|
<Pointer direction="Header" style={{ cursor: "move" }} {...opts}>
|
||||||
|
{header}
|
||||||
|
</Pointer>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
width: size.w,
|
||||||
|
height: size.h,
|
||||||
|
overflow: "hidden auto",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
</Paper>
|
||||||
|
<Pointer
|
||||||
|
direction="Right"
|
||||||
|
style={{
|
||||||
|
margin: `${lineWidth}px 0`,
|
||||||
|
transform: `translate(-${lineWidth}px, 0px)`,
|
||||||
|
cursor: "col-resize",
|
||||||
|
}}
|
||||||
|
{...opts}
|
||||||
|
/>
|
||||||
|
<Pointer
|
||||||
|
direction="BottomLeft"
|
||||||
|
style={{
|
||||||
|
transform: `translate(${lineWidth}px, -${lineWidth}px)`,
|
||||||
|
cursor: "ne-resize",
|
||||||
|
}}
|
||||||
|
{...opts}
|
||||||
|
/>
|
||||||
|
<Pointer
|
||||||
|
direction="Bottom"
|
||||||
|
style={{
|
||||||
|
margin: `0 ${lineWidth}px`,
|
||||||
|
transform: `translate(0px, -${lineWidth}px)`,
|
||||||
|
cursor: "row-resize",
|
||||||
|
}}
|
||||||
|
{...opts}
|
||||||
|
/>
|
||||||
|
<Pointer
|
||||||
|
direction="BottomRight"
|
||||||
|
style={{
|
||||||
|
transform: `translate(-${lineWidth}px, -${lineWidth}px)`,
|
||||||
|
cursor: "nw-resize",
|
||||||
|
}}
|
||||||
|
{...opts}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}
|
||||||
31
src/views/Selection/FavBtn.js
Normal file
31
src/views/Selection/FavBtn.js
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
import IconButton from "@mui/material/IconButton";
|
||||||
|
import FavoriteIcon from "@mui/icons-material/Favorite";
|
||||||
|
import FavoriteBorderIcon from "@mui/icons-material/FavoriteBorder";
|
||||||
|
import { useState } from "react";
|
||||||
|
import { useFavWords } from "../../hooks/FavWords";
|
||||||
|
|
||||||
|
export default function FavBtn({ word }) {
|
||||||
|
const { favWords, toggleFav } = useFavWords();
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
|
const handleClick = async () => {
|
||||||
|
try {
|
||||||
|
setLoading(true);
|
||||||
|
await toggleFav(word);
|
||||||
|
} catch (err) {
|
||||||
|
console.log("[set fav]", err);
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<IconButton disabled={loading} size="small" onClick={handleClick}>
|
||||||
|
{favWords[word] ? (
|
||||||
|
<FavoriteIcon fontSize="inherit" />
|
||||||
|
) : (
|
||||||
|
<FavoriteBorderIcon fontSize="inherit" />
|
||||||
|
)}
|
||||||
|
</IconButton>
|
||||||
|
);
|
||||||
|
}
|
||||||
195
src/views/Selection/TranBox.js
Normal file
195
src/views/Selection/TranBox.js
Normal file
@@ -0,0 +1,195 @@
|
|||||||
|
import { SettingProvider } from "../../hooks/Setting";
|
||||||
|
import ThemeProvider from "../../hooks/Theme";
|
||||||
|
import DraggableResizable from "./DraggableResizable";
|
||||||
|
import Header from "../Popup/Header";
|
||||||
|
import Stack from "@mui/material/Stack";
|
||||||
|
import TextField from "@mui/material/TextField";
|
||||||
|
import MenuItem from "@mui/material/MenuItem";
|
||||||
|
import Grid from "@mui/material/Grid";
|
||||||
|
import Box from "@mui/material/Box";
|
||||||
|
import Divider from "@mui/material/Divider";
|
||||||
|
import IconButton from "@mui/material/IconButton";
|
||||||
|
import DoneIcon from "@mui/icons-material/Done";
|
||||||
|
import { useI18n } from "../../hooks/I18n";
|
||||||
|
import { OPT_TRANS_ALL, OPT_LANGS_FROM, OPT_LANGS_TO } from "../../config";
|
||||||
|
import { useState, useRef } from "react";
|
||||||
|
import TranCont from "./TranCont";
|
||||||
|
import CopyBtn from "./CopyBtn";
|
||||||
|
|
||||||
|
function TranForm({ text, setText, tranboxSetting, transApis }) {
|
||||||
|
const i18n = useI18n();
|
||||||
|
|
||||||
|
const [editMode, setEditMode] = useState(false);
|
||||||
|
const [editText, setEditText] = useState("");
|
||||||
|
const [translator, setTranslator] = useState(tranboxSetting.translator);
|
||||||
|
const [fromLang, setFromLang] = useState(tranboxSetting.fromLang);
|
||||||
|
const [toLang, setToLang] = useState(tranboxSetting.toLang);
|
||||||
|
const [toLang2, setToLang2] = useState(tranboxSetting.toLang2);
|
||||||
|
const inputRef = useRef(null);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Stack sx={{ p: 2 }} spacing={2}>
|
||||||
|
<Box>
|
||||||
|
<Grid container spacing={2} columns={12}>
|
||||||
|
<Grid item xs={4} sm={4} md={4} lg={4}>
|
||||||
|
<TextField
|
||||||
|
select
|
||||||
|
SelectProps={{ MenuProps: { disablePortal: true } }}
|
||||||
|
fullWidth
|
||||||
|
size="small"
|
||||||
|
name="fromLang"
|
||||||
|
value={fromLang}
|
||||||
|
label={i18n("from_lang")}
|
||||||
|
onChange={(e) => {
|
||||||
|
setFromLang(e.target.value);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{OPT_LANGS_FROM.map(([lang, name]) => (
|
||||||
|
<MenuItem key={lang} value={lang}>
|
||||||
|
{name}
|
||||||
|
</MenuItem>
|
||||||
|
))}
|
||||||
|
</TextField>
|
||||||
|
</Grid>
|
||||||
|
<Grid item xs={4} sm={4} md={4} lg={4}>
|
||||||
|
<TextField
|
||||||
|
select
|
||||||
|
SelectProps={{ MenuProps: { disablePortal: true } }}
|
||||||
|
fullWidth
|
||||||
|
size="small"
|
||||||
|
name="toLang"
|
||||||
|
value={toLang}
|
||||||
|
label={i18n("to_lang")}
|
||||||
|
onChange={(e) => {
|
||||||
|
setToLang(e.target.value);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{OPT_LANGS_TO.map(([lang, name]) => (
|
||||||
|
<MenuItem key={lang} value={lang}>
|
||||||
|
{name}
|
||||||
|
</MenuItem>
|
||||||
|
))}
|
||||||
|
</TextField>
|
||||||
|
</Grid>
|
||||||
|
<Grid item xs={4} sm={4} md={4} lg={4}>
|
||||||
|
<TextField
|
||||||
|
select
|
||||||
|
SelectProps={{ MenuProps: { disablePortal: true } }}
|
||||||
|
fullWidth
|
||||||
|
size="small"
|
||||||
|
value={translator}
|
||||||
|
name="translator"
|
||||||
|
label={i18n("translate_service")}
|
||||||
|
onChange={(e) => {
|
||||||
|
setTranslator(e.target.value);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{OPT_TRANS_ALL.map((item) => (
|
||||||
|
<MenuItem key={item} value={item}>
|
||||||
|
{item}
|
||||||
|
</MenuItem>
|
||||||
|
))}
|
||||||
|
</TextField>
|
||||||
|
</Grid>
|
||||||
|
</Grid>
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
<Box>
|
||||||
|
<TextField
|
||||||
|
size="small"
|
||||||
|
label={i18n("original_text")}
|
||||||
|
inputRef={inputRef}
|
||||||
|
fullWidth
|
||||||
|
multiline
|
||||||
|
value={editMode ? editText : text}
|
||||||
|
disabled={!editMode}
|
||||||
|
onChange={(e) => {
|
||||||
|
setEditText(e.target.value);
|
||||||
|
}}
|
||||||
|
onClick={() => {
|
||||||
|
setEditMode(true);
|
||||||
|
setEditText(text);
|
||||||
|
const timer = setTimeout(() => {
|
||||||
|
clearTimeout(timer);
|
||||||
|
inputRef.current?.focus();
|
||||||
|
}, 100);
|
||||||
|
}}
|
||||||
|
onBlur={() => {
|
||||||
|
setEditMode(false);
|
||||||
|
setText(editText.trim());
|
||||||
|
}}
|
||||||
|
InputProps={{
|
||||||
|
endAdornment: (
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
sx={{
|
||||||
|
position: "absolute",
|
||||||
|
right: 0,
|
||||||
|
top: 0,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{editMode ? (
|
||||||
|
<IconButton
|
||||||
|
size="small"
|
||||||
|
onClick={(e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<DoneIcon fontSize="inherit" />
|
||||||
|
</IconButton>
|
||||||
|
) : (
|
||||||
|
<CopyBtn text={text} />
|
||||||
|
)}
|
||||||
|
</Stack>
|
||||||
|
),
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
<TranCont
|
||||||
|
text={text}
|
||||||
|
translator={translator}
|
||||||
|
fromLang={fromLang}
|
||||||
|
toLang={toLang}
|
||||||
|
toLang2={toLang2}
|
||||||
|
setToLang={setToLang}
|
||||||
|
setToLang2={setToLang2}
|
||||||
|
transApis={transApis}
|
||||||
|
/>
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function TranBox({
|
||||||
|
text,
|
||||||
|
setText,
|
||||||
|
setShowBox,
|
||||||
|
tranboxSetting,
|
||||||
|
transApis,
|
||||||
|
boxSize,
|
||||||
|
setBoxSize,
|
||||||
|
boxPosition,
|
||||||
|
setBoxPosition,
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<SettingProvider>
|
||||||
|
<ThemeProvider>
|
||||||
|
<DraggableResizable
|
||||||
|
defaultPosition={boxPosition}
|
||||||
|
defaultSize={boxSize}
|
||||||
|
header={<Header setShowPopup={setShowBox} />}
|
||||||
|
onChangeSize={setBoxSize}
|
||||||
|
onChangePosition={setBoxPosition}
|
||||||
|
>
|
||||||
|
<Divider />
|
||||||
|
<TranForm
|
||||||
|
text={text}
|
||||||
|
setText={setText}
|
||||||
|
tranboxSetting={tranboxSetting}
|
||||||
|
transApis={transApis}
|
||||||
|
/>
|
||||||
|
</DraggableResizable>
|
||||||
|
</ThemeProvider>
|
||||||
|
</SettingProvider>
|
||||||
|
);
|
||||||
|
}
|
||||||
36
src/views/Selection/TranBtn.js
Normal file
36
src/views/Selection/TranBtn.js
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
export default function TranBtn({ onClick, position, tranboxSetting }) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
cursor: "pointer",
|
||||||
|
position: "absolute",
|
||||||
|
left: position.x + tranboxSetting.btnOffsetX,
|
||||||
|
top: position.y + tranboxSetting.btnOffsetY,
|
||||||
|
zIndex: 2147483647,
|
||||||
|
}}
|
||||||
|
onClick={onClick}
|
||||||
|
onMouseUp={(e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
width="20"
|
||||||
|
height="20"
|
||||||
|
viewBox="0 0 32 32"
|
||||||
|
version="1.1"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
d="M0 0 C10.56 0 21.12 0 32 0 C32 10.56 32 21.12 32 32 C21.44 32 10.88 32 0 32 C0 21.44 0 10.88 0 0 Z "
|
||||||
|
fill="#209CEE"
|
||||||
|
transform="translate(0,0)"
|
||||||
|
/>
|
||||||
|
<path
|
||||||
|
d="M0 0 C0.66 0 1.32 0 2 0 C2 2.97 2 5.94 2 9 C2.969375 8.2575 3.93875 7.515 4.9375 6.75 C5.48277344 6.33234375 6.02804688 5.9146875 6.58984375 5.484375 C8.39053593 3.83283924 8.39053593 3.83283924 9 0 C13.95 0 18.9 0 24 0 C24 0.99 24 1.98 24 3 C22.68 3 21.36 3 20 3 C20 9.27 20 15.54 20 22 C19.01 22 18.02 22 17 22 C17 15.73 17 9.46 17 3 C15.35 3 13.7 3 12 3 C11.731875 3.598125 11.46375 4.19625 11.1875 4.8125 C10.01506533 6.97224808 8.80630718 8.35790256 7 10 C8.01790655 12.27071461 8.77442829 13.80784632 10.6875 15.4375 C11.120625 15.953125 11.55375 16.46875 12 17 C11.6875 19.6875 11.6875 19.6875 11 22 C10.34 22 9.68 22 9 22 C8.773125 21.236875 8.54625 20.47375 8.3125 19.6875 C6.73268318 16.45263699 5.16717283 15.58358642 2 14 C2 16.64 2 19.28 2 22 C1.34 22 0.68 22 0 22 C0 14.74 0 7.48 0 0 Z "
|
||||||
|
fill="#E9F5FD"
|
||||||
|
transform="translate(4,5)"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
122
src/views/Selection/TranCont.js
Normal file
122
src/views/Selection/TranCont.js
Normal file
@@ -0,0 +1,122 @@
|
|||||||
|
import TextField from "@mui/material/TextField";
|
||||||
|
import Box from "@mui/material/Box";
|
||||||
|
import Alert from "@mui/material/Alert";
|
||||||
|
import CircularProgress from "@mui/material/CircularProgress";
|
||||||
|
import Stack from "@mui/material/Stack";
|
||||||
|
import { useI18n } from "../../hooks/I18n";
|
||||||
|
import { DEFAULT_TRANS_APIS, OPT_TRANS_BAIDU } from "../../config";
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import { apiTranslate, apiBaiduLangdetect } from "../../apis";
|
||||||
|
import { isValidWord } from "../../libs/utils";
|
||||||
|
import CopyBtn from "./CopyBtn";
|
||||||
|
import DictCont from "./DictCont";
|
||||||
|
|
||||||
|
export default function TranCont({
|
||||||
|
text,
|
||||||
|
translator,
|
||||||
|
fromLang,
|
||||||
|
toLang,
|
||||||
|
toLang2 = "en",
|
||||||
|
setToLang,
|
||||||
|
setToLang2,
|
||||||
|
transApis,
|
||||||
|
}) {
|
||||||
|
const i18n = useI18n();
|
||||||
|
const [trText, setTrText] = useState("");
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [error, setError] = useState("");
|
||||||
|
const [dictResult, setDictResult] = useState(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
(async () => {
|
||||||
|
try {
|
||||||
|
setLoading(true);
|
||||||
|
setTrText("");
|
||||||
|
setError("");
|
||||||
|
setDictResult(null);
|
||||||
|
|
||||||
|
// 互译
|
||||||
|
if (toLang !== toLang2 && toLang2 !== "none") {
|
||||||
|
const detectLang = await apiBaiduLangdetect(text);
|
||||||
|
if (detectLang === toLang) {
|
||||||
|
setToLang(toLang2);
|
||||||
|
setToLang2(toLang);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const apiSetting =
|
||||||
|
transApis[translator] || DEFAULT_TRANS_APIS[translator];
|
||||||
|
const tranRes = await apiTranslate({
|
||||||
|
text,
|
||||||
|
translator,
|
||||||
|
fromLang,
|
||||||
|
toLang,
|
||||||
|
apiSetting,
|
||||||
|
});
|
||||||
|
setTrText(tranRes[0]);
|
||||||
|
|
||||||
|
// 词典
|
||||||
|
if (isValidWord(text) && toLang.startsWith("zh")) {
|
||||||
|
if (fromLang === "en" && translator === OPT_TRANS_BAIDU) {
|
||||||
|
setDictResult(tranRes[2].dict_result);
|
||||||
|
} else {
|
||||||
|
const dictRes = await apiTranslate({
|
||||||
|
text,
|
||||||
|
translator: OPT_TRANS_BAIDU,
|
||||||
|
fromLang: "en",
|
||||||
|
toLang: "zh-CN",
|
||||||
|
});
|
||||||
|
setDictResult(dictRes[2].dict_result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
setError(err.message);
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
}, [
|
||||||
|
text,
|
||||||
|
translator,
|
||||||
|
fromLang,
|
||||||
|
toLang,
|
||||||
|
toLang2,
|
||||||
|
setToLang,
|
||||||
|
setToLang2,
|
||||||
|
transApis,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Box>
|
||||||
|
<TextField
|
||||||
|
size="small"
|
||||||
|
label={i18n("translated_text")}
|
||||||
|
// disabled
|
||||||
|
fullWidth
|
||||||
|
multiline
|
||||||
|
value={trText}
|
||||||
|
InputProps={{
|
||||||
|
endAdornment: (
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
sx={{
|
||||||
|
position: "absolute",
|
||||||
|
right: 0,
|
||||||
|
top: 0,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<CopyBtn text={trText} />
|
||||||
|
</Stack>
|
||||||
|
),
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
{loading && <CircularProgress size={24} />}
|
||||||
|
{error && <Alert severity="error">{error}</Alert>}
|
||||||
|
{dictResult && <DictCont dictResult={dictResult} />}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
137
src/views/Selection/index.js
Normal file
137
src/views/Selection/index.js
Normal file
@@ -0,0 +1,137 @@
|
|||||||
|
import { useState, useEffect, useCallback } from "react";
|
||||||
|
import TranBtn from "./TranBtn";
|
||||||
|
import TranBox from "./TranBox";
|
||||||
|
import { shortcutRegister } from "../../libs/shortcut";
|
||||||
|
import { sleep } from "../../libs/utils";
|
||||||
|
import { isGm } from "../../libs/client";
|
||||||
|
import { MSG_OPEN_TRANBOX, DEFAULT_TRANBOX_SHORTCUT } from "../../config";
|
||||||
|
|
||||||
|
export default function Slection({ contextMenus, tranboxSetting, transApis }) {
|
||||||
|
const [showBox, setShowBox] = useState(false);
|
||||||
|
const [showBtn, setShowBtn] = useState(false);
|
||||||
|
const [selectedText, setSelText] = useState("");
|
||||||
|
const [text, setText] = useState("");
|
||||||
|
const [position, setPosition] = useState({ x: 0, y: 0 });
|
||||||
|
const [boxSize, setBoxSize] = useState({ w: 600, h: 400 });
|
||||||
|
const [boxPosition, setBoxPosition] = useState({
|
||||||
|
x: (window.innerWidth - 600) / 2,
|
||||||
|
y: (window.innerHeight - 400) / 2,
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleClick = (e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
|
||||||
|
setShowBtn(false);
|
||||||
|
setText(selectedText);
|
||||||
|
setShowBox(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleTranbox = useCallback(() => {
|
||||||
|
setShowBtn(false);
|
||||||
|
|
||||||
|
const selectedText = window.getSelection()?.toString()?.trim() || "";
|
||||||
|
if (!selectedText) {
|
||||||
|
setShowBox((pre) => !pre);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setSelText(selectedText);
|
||||||
|
setText(selectedText);
|
||||||
|
setShowBox(true);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
async function handleMouseup(e) {
|
||||||
|
await sleep(10);
|
||||||
|
|
||||||
|
const selectedText = window.getSelection()?.toString()?.trim() || "";
|
||||||
|
setSelText(selectedText);
|
||||||
|
if (!selectedText) {
|
||||||
|
setShowBtn(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
!tranboxSetting.hideTranBtn && setShowBtn(true);
|
||||||
|
// setPosition({ x: e.clientX, y: e.clientY });
|
||||||
|
setPosition({ x: e.pageX, y: e.pageY });
|
||||||
|
}
|
||||||
|
|
||||||
|
window.addEventListener("mouseup", handleMouseup);
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener("mouseup", handleMouseup);
|
||||||
|
};
|
||||||
|
}, [tranboxSetting.hideTranBtn]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const clearShortcut = shortcutRegister(
|
||||||
|
tranboxSetting.tranboxShortcut || DEFAULT_TRANBOX_SHORTCUT,
|
||||||
|
handleTranbox
|
||||||
|
);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
clearShortcut();
|
||||||
|
};
|
||||||
|
}, [tranboxSetting.tranboxShortcut, handleTranbox]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
window.addEventListener(MSG_OPEN_TRANBOX, handleTranbox);
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener(MSG_OPEN_TRANBOX, handleTranbox);
|
||||||
|
};
|
||||||
|
}, [handleTranbox]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!isGm) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 注册菜单
|
||||||
|
try {
|
||||||
|
const menuCommandIds = [];
|
||||||
|
contextMenus &&
|
||||||
|
menuCommandIds.push(
|
||||||
|
GM.registerMenuCommand(
|
||||||
|
"Translate Selected Text (Alt+S)",
|
||||||
|
(event) => {
|
||||||
|
handleTranbox();
|
||||||
|
},
|
||||||
|
"S"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
menuCommandIds.forEach((id) => {
|
||||||
|
GM.unregisterMenuCommand(id);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
} catch (err) {
|
||||||
|
console.log("[registerMenuCommand]", err);
|
||||||
|
}
|
||||||
|
}, [handleTranbox, contextMenus]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{showBox && (
|
||||||
|
<TranBox
|
||||||
|
text={text}
|
||||||
|
setText={setText}
|
||||||
|
boxSize={boxSize}
|
||||||
|
setBoxSize={setBoxSize}
|
||||||
|
boxPosition={boxPosition}
|
||||||
|
setBoxPosition={setBoxPosition}
|
||||||
|
tranboxSetting={tranboxSetting}
|
||||||
|
transApis={transApis}
|
||||||
|
setShowBox={setShowBox}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{showBtn && (
|
||||||
|
<TranBtn
|
||||||
|
position={position}
|
||||||
|
tranboxSetting={tranboxSetting}
|
||||||
|
onClick={handleClick}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user