From fa87d870119966b855acd138a2318b601b687609 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=40=E5=88=98=E7=BE=A1=E9=B1=BC?= Date: Tue, 16 Sep 2025 08:44:07 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feat(sync):=20=E9=80=9A=E8=BF=87=20base64?= =?UTF-8?q?=20=E5=A4=8D=E5=88=B6=E7=B2=98=E8=B4=B4=E9=85=8D=E7=BD=AE=20(#3?= =?UTF-8?q?11)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit motivation: 同浏览器多个 profile 简化配置流程,通过同一个同步配置即可实现 --- src/config/setting.js | 1 + src/views/Options/SyncSetting.js | 73 +++++++++++++++++++++++++++++++- 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/src/config/setting.js b/src/config/setting.js index e214e32..da7bdda 100644 --- a/src/config/setting.js +++ b/src/config/setting.js @@ -33,6 +33,7 @@ export const DEFAULT_CSPLIST = ["https://github.com"]; // 禁用CSP名单 // 同步设置 export const OPT_SYNCTYPE_WORKER = "KISS-Worker"; export const OPT_SYNCTYPE_WEBDAV = "WebDAV"; +export const OPT_SYNCTOKEN_PERFIX = "kt_"; export const OPT_SYNCTYPE_ALL = [OPT_SYNCTYPE_WORKER, OPT_SYNCTYPE_WEBDAV]; export const DEFAULT_SYNC = { syncType: OPT_SYNCTYPE_WORKER, // 同步方式 diff --git a/src/views/Options/SyncSetting.js b/src/views/Options/SyncSetting.js index b896639..d260596 100644 --- a/src/views/Options/SyncSetting.js +++ b/src/views/Options/SyncSetting.js @@ -7,18 +7,22 @@ import Alert from "@mui/material/Alert"; import Link from "@mui/material/Link"; import MenuItem from "@mui/material/MenuItem"; import LoadingButton from "@mui/lab/LoadingButton"; +import Button from "@mui/material/Button"; import { URL_KISS_WORKER, OPT_SYNCTYPE_ALL, OPT_SYNCTYPE_WORKER, OPT_SYNCTYPE_WEBDAV, + OPT_SYNCTOKEN_PERFIX, } from "../../config"; import { useState } from "react"; import { syncSettingAndRules } from "../../libs/sync"; import { useAlert } from "../../hooks/Alert"; -import SyncIcon from "@mui/icons-material/Sync"; import { useSetting } from "../../hooks/Setting"; import { kissLog } from "../../libs/log"; +import SyncIcon from "@mui/icons-material/Sync"; +import ContentCopyIcon from '@mui/icons-material/ContentCopy'; +import ContentPasteIcon from '@mui/icons-material/ContentPaste'; export default function SyncSetting() { const i18n = useI18n(); @@ -50,6 +54,57 @@ export default function SyncSetting() { } }; + const handleGenerateShareString = async () => { + try { + const base64Config = btoa(JSON.stringify({ + syncType: syncType, + syncUrl: syncUrl, + syncUser: syncUser, + syncKey: syncKey, + })); + const shareString = `${OPT_SYNCTOKEN_PERFIX}${base64Config}`; + await navigator.clipboard.writeText(shareString); + console.debug("Share string copied to clipboard", shareString); + } catch (error) { + console.error("Failed to copy share string to clipboard", error); + } + }; + + const handleImportFromClipboard = async () => { + try { + const text = await navigator.clipboard.readText(); + console.debug('read_clipboard', text) + if (text.startsWith(OPT_SYNCTOKEN_PERFIX)) { + const base64Config = text.slice(OPT_SYNCTOKEN_PERFIX.length); + const jsonString = atob(base64Config); + const updatedConfig = JSON.parse(jsonString); + + if (!OPT_SYNCTYPE_ALL.includes(updatedConfig.syncType)) { + console.error('error syncType', updatedConfig.syncType) + return; + } + + if ( + updatedConfig.syncUrl + ) { + updateSync({ + syncType: updatedConfig.syncType, + syncUrl: updatedConfig.syncUrl, + syncUser: updatedConfig.syncUser, + syncKey: updatedConfig.syncKey, + }); + } else { + console.error("Invalid config structure"); + } + } else { + console.error("Invalid share string", text); + } + } catch (error) { + console.error("Failed to read from clipboard or parse JSON", error); + } + }; + + if (!sync) { return; } @@ -133,6 +188,22 @@ export default function SyncSetting() { > {i18n("sync_now")} + + From d39a016d5fe5de6f560f1a0ece50451aeb58decc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=AB=E6=88=91=E6=B2=88=E5=90=8C=E5=AD=A6?= <97521809+ClassmateShen@users.noreply.github.com> Date: Tue, 16 Sep 2025 08:47:36 +0800 Subject: [PATCH 2/3] macOS and iOS support (#312) * Update README.md * Update README.en.md --- README.en.md | 8 ++++---- README.md | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.en.md b/README.en.md index 6e12edd..625c3fa 100644 --- a/README.en.md +++ b/README.en.md @@ -15,8 +15,7 @@ A simple, open source [bilingual translation extension & Greasemonkey script](ht - [x] Firefox - [x] Kiwi (Android) - [x] Orion (iOS) - - [ ] Safari - - [x] Safari (Mac) + - [x] Safari - [x] Thunderbird - [x] Supports multiple translation services - [x] Google/Microsoft @@ -59,8 +58,9 @@ A simple, open source [bilingual translation extension & Greasemonkey script](ht - [x] Orion (iOS) - [x] Edge [Installation address](https://microsoftedge.microsoft.com/addons/detail/%E7%AE%80%E7%BA%A6%E7%BF%BB%E8%AF%91/jemckldkclkinpjighnoilpbldbdmmlh?hl=zh-CN) - [x] Firefox [Installation address](https://addons.mozilla.org/zh-CN/firefox/addon/kiss-translator/) - - [ ] Safari - - [x] Safari (Mac) Compiled by a third party, not verified, obtained by yourself: https://www.nodeloc.com/t/topic/54245 + - [x] Safari + - [x] Safari (Mac) + - [x] Safari (iOS) - [x] Thunderbird [Download address](https://github.com/fishjar/kiss-translator/releases) - [x] GreaseMonkey Script - [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) diff --git a/README.md b/README.md index f9af8da..f2d8b1e 100644 --- a/README.md +++ b/README.md @@ -15,8 +15,7 @@ - [x] Firefox - [x] Kiwi (Android) - [x] Orion (iOS) - - [ ] Safari - - [x] Safari (Mac) + - [x] Safari - [x] Thunderbird - [x] 支持多种翻译服务 - [x] Google/Microsoft @@ -59,8 +58,9 @@ - [x] Orion (iOS) - [x] Edge [安装地址](https://microsoftedge.microsoft.com/addons/detail/%E7%AE%80%E7%BA%A6%E7%BF%BB%E8%AF%91/jemckldkclkinpjighnoilpbldbdmmlh?hl=zh-CN) - [x] Firefox [安装地址](https://addons.mozilla.org/zh-CN/firefox/addon/kiss-translator/) - - [ ] Safari - - [x] Safari (Mac) 第三方编译,未作验证,自行获取: https://www.nodeloc.com/t/topic/54245 + - [x] Safari + - [x] Safari (Mac) + - [x] Safari (iOS) - [x] Thunderbird [下载地址](https://github.com/fishjar/kiss-translator/releases) - [x] 油猴脚本 - [x] Chrome/Edge/Firefox ([Tampermonkey](https://www.tampermonkey.net/)/[Violentmonkey](https://violentmonkey.github.io/)) [安装链接](https://fishjar.github.io/kiss-translator/kiss-translator.user.js) From 563242c5f138a60f4b1d8c7e3ab7f3371944a15c Mon Sep 17 00:00:00 2001 From: Zack C <62716651+zh1030283726@users.noreply.github.com> Date: Sun, 21 Sep 2025 00:50:39 +1000 Subject: [PATCH 3/3] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8F=AF=E4=BB=A5?= =?UTF-8?q?=E9=80=89=E6=8B=A9=E6=82=AC=E6=B5=AE=E6=8C=89=E9=92=AE=E5=8D=95?= =?UTF-8?q?=E5=87=BB=E6=93=8D=E4=BD=9C=E7=9A=84=E8=AE=BE=E7=BD=AE=E9=80=89?= =?UTF-8?q?=E9=A1=B9=20(#313)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add an option in Settings to provide choices for the FAB Single Click action. * Complete Translation --------- Co-authored-by: 1030283726 <1030283726@qq.com> --- src/config/i18n.js | 16 +++++++++++++++- src/config/setting.js | 1 + src/views/Action/index.js | 11 ++++++++++- src/views/Options/Setting.js | 15 ++++++++++++++- 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/config/i18n.js b/src/config/i18n.js index f867dce..08eaaac 100644 --- a/src/config/i18n.js +++ b/src/config/i18n.js @@ -847,7 +847,21 @@ export const I18N = { en: `Hide Fab Button`, zh_TW: `隱藏懸浮按鈕`, }, - + fab_click_action: { + zh: `单击悬浮按钮动作`, + en: `Single Click Fab Action`, + zh_TW: `單擊懸浮按钮動作`, + }, + fab_click_menu: { + zh: `弹出菜单`, + en: `Popup Menu`, + zh_TW: `彈出選單`, + }, + fab_click_translate: { + zh: `直接翻译`, + en: `Translate`, + zh_TW: `直接翻譯`, + }, hide_tran_button: { zh: `隐藏翻译按钮`, en: `Hide Translate Button`, diff --git a/src/config/setting.js b/src/config/setting.js index da7bdda..b1de363 100644 --- a/src/config/setting.js +++ b/src/config/setting.js @@ -120,6 +120,7 @@ export const DEFAULT_SETTING = { httpTimeout: DEFAULT_HTTP_TIMEOUT, clearCache: false, // 是否在浏览器下次启动时清除缓存 injectRules: true, // 是否注入订阅规则 + fabClickAction: 0, // 悬浮按钮点击行为 // injectWebfix: true, // 是否注入修复补丁(作废) // detectRemote: false, // 是否使用远程语言检测(移至rule,作废) // contextMenus: true, // 是否添加右键菜单(作废) diff --git a/src/views/Action/index.js b/src/views/Action/index.js index 5746daf..118080c 100644 --- a/src/views/Action/index.js +++ b/src/views/Action/index.js @@ -33,6 +33,8 @@ export default function Action({ translator, fab }) { }); const [moved, setMoved] = useState(false); + const { fabClickAction = 0 } = fab || {}; + const handleWindowResize = useMemo( () => debounce(() => { @@ -215,7 +217,14 @@ export default function Action({ translator, fab }) { color="primary" onClick={(e) => { if (!moved) { - setShowPopup((pre) => !pre); + if (fabClickAction === 1) { + translator.toggle(); + sendIframeMsg(MSG_TRANS_TOGGLE); + setShowPopup(false); + } + else { + setShowPopup((pre) => !pre); + } } }} > diff --git a/src/views/Options/Setting.js b/src/views/Options/Setting.js index 83beb09..3a7bdfb 100644 --- a/src/views/Options/Setting.js +++ b/src/views/Options/Setting.js @@ -122,7 +122,7 @@ export default function Settings() { transInterval = 500, langDetector = OPT_TRANS_MICROSOFT, } = setting; - const { isHide = false } = fab || {}; + const { isHide = false, fabClickAction = 0 } = fab || {}; return ( @@ -232,6 +232,19 @@ export default function Settings() { + + {i18n("fab_click_action")} + + + {i18n("context_menus")}