From 6cc3a5fdaae19fe394b61ac2a41849fa0b006dcd Mon Sep 17 00:00:00 2001 From: windingwind <33902321+windingwind@users.noreply.github.com> Date: Wed, 16 Oct 2024 10:34:25 +0200 Subject: [PATCH] resolve: #955 --- addon/locale/en-US/addon.ftl | 7 ++++++ addon/locale/it-IT/addon.ftl | 7 ++++++ addon/locale/zh-CN/addon.ftl | 7 ++++++ addon/prefs.js | 1 + src/modules/services/deeplx.ts | 4 +++- src/modules/settings/deeplx.ts | 43 ++++++++++++++++++++++++++++++++++ src/modules/settings/index.ts | 8 +++++++ 7 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 src/modules/settings/deeplx.ts diff --git a/addon/locale/en-US/addon.ftl b/addon/locale/en-US/addon.ftl index 2ad80bd3..501d01e1 100644 --- a/addon/locale/en-US/addon.ftl +++ b/addon/locale/en-US/addon.ftl @@ -55,6 +55,13 @@ service-niutranspro-dialog-close=Close service-deeplcustom-secret-pass=Docs service-deeplcustom-secret-fail=Docs +service-deeplx-secret-pass=Config +service-deeplx-secret-fail=Config +service-deeplx-dialog-title=DeepLX Config +service-deeplx-dialog-endPoint=EndPoint +service-deeplx-dialog-save=Save +service-deeplx-dialog-close=Close + service-chatgpt-secret-pass=Config service-chatgpt-secret-fail=Config service-chatgpt-dialog-title=ChatGPT Config diff --git a/addon/locale/it-IT/addon.ftl b/addon/locale/it-IT/addon.ftl index 3f9f68d1..669cedcf 100644 --- a/addon/locale/it-IT/addon.ftl +++ b/addon/locale/it-IT/addon.ftl @@ -54,6 +54,13 @@ service-niutranspro-dialog-close=Chiudi service-deeplcustom-secret-pass=Docs service-deeplcustom-secret-fail=Docs +service-deeplx-secret-pass=Configura +service-deeplx-secret-fail=Configura +service-deeplx-dialog-title=Configura DeepLX +service-deeplx-dialog-endPoint=API +service-deeplx-dialog-save=Salva +service-deeplx-dialog-close=Chiudi + service-chatgpt-secret-pass=Configura service-chatgpt-secret-fail=Configura service-chatgpt-dialog-title=Configura ChatGPT diff --git a/addon/locale/zh-CN/addon.ftl b/addon/locale/zh-CN/addon.ftl index ffdf95ec..81c47af7 100644 --- a/addon/locale/zh-CN/addon.ftl +++ b/addon/locale/zh-CN/addon.ftl @@ -54,6 +54,13 @@ service-niutranspro-dialog-close=关闭 service-deeplcustom-secret-pass=文档 service-deeplcustom-secret-fail=文档 +service-deeplx-secret-pass=配置 +service-deeplx-secret-fail=配置 +service-deeplx-dialog-title=DeepLX 配置 +service-deeplx-dialog-endPoint=接口 +service-deeplx-dialog-save=保存 +service-deeplx-dialog-close=关闭 + service-chatgpt-secret-pass=配置 service-chatgpt-secret-fail=配置 service-chatgpt-dialog-title=ChatGPT 配置项 diff --git a/addon/prefs.js b/addon/prefs.js index 90404c4f..74bca52b 100644 --- a/addon/prefs.js +++ b/addon/prefs.js @@ -75,3 +75,4 @@ pref( ); pref("__prefsPrefix__.cnkiSplitSecond", 1); pref("__prefsPrefix__.cnkiUseSplit", false); +pref("__prefsPrefix__.deeplx.endpoint", "https://www2.deepl.com/jsonrpc"); diff --git a/src/modules/services/deeplx.ts b/src/modules/services/deeplx.ts index 3dc3b800..d8a5cd86 100644 --- a/src/modules/services/deeplx.ts +++ b/src/modules/services/deeplx.ts @@ -1,7 +1,9 @@ +import { getPref } from "../../utils/prefs"; import { TranslateTaskProcessor } from "../../utils/task"; export default async function (data) { const id = 1000 * (Math.floor(Math.random() * 99999) + 8300000) + 1; - const url = "https://www2.deepl.com/jsonrpc"; + const url = + (getPref("deeplx.endpoint") as string) || "https://www2.deepl.com/jsonrpc"; const t = data.raw; const ICounts = (t.match(/i/g) || []).length + 1; const ts = Date.now(); diff --git a/src/modules/settings/deeplx.ts b/src/modules/settings/deeplx.ts new file mode 100644 index 00000000..d23ec7d6 --- /dev/null +++ b/src/modules/settings/deeplx.ts @@ -0,0 +1,43 @@ +import { getString } from "../../utils/locale"; +import { getPref, setPref } from "../../utils/prefs"; + +export async function deeplxStatusCallback(status: boolean) { + const dialog = new ztoolkit.Dialog(4, 1); + const dialogData: { [key: string | number]: any } = { + endpoint: getPref("deeplx.endpoint"), + }; + dialog + .setDialogData(dialogData) + .addCell(0, 0, { + tag: "label", + namespace: "html", + attributes: { + for: "endpoint", + }, + properties: { + innerHTML: getString("service-deeplx-dialog-endPoint"), + }, + }) + .addCell(1, 0, { + tag: "input", + id: "endpoint", + attributes: { + "data-bind": "endpoint", + "data-prop": "value", + }, + }) + .addButton(getString("service-deeplx-dialog-save"), "save") + .addButton(getString("service-deeplx-dialog-close"), "close") + .open(getString("service-deeplx-dialog-title")); + + await dialogData.unloadLock?.promise; + switch (dialogData._lastButtonId) { + case "save": + { + setPref("deeplx.endpoint", dialogData.endpoint); + } + break; + default: + break; + } +} diff --git a/src/modules/settings/index.ts b/src/modules/settings/index.ts index 23b903f5..0d2bd61b 100644 --- a/src/modules/settings/index.ts +++ b/src/modules/settings/index.ts @@ -2,6 +2,7 @@ import { cnkiStatusCallback } from "./cnki"; import { chatGPTStatusCallback, azureGPTStatusCallback } from "./gpt"; import { geminiStatusCallback } from "./gemini"; import { niutransStatusCallback } from "./niutrans"; +import { deeplxStatusCallback } from "./deeplx"; export const secretStatusButtonData: { [key: string]: { @@ -27,6 +28,13 @@ export const secretStatusButtonData: { ); }, }, + deeplx: { + labels: { + pass: "service-deeplx-secret-pass", + fail: "service-deeplx-secret-fail", + }, + callback: deeplxStatusCallback, + }, chatgpt: { labels: { pass: "service-chatgpt-secret-pass",