Skip to content

Commit

Permalink
resolve: #955
Browse files Browse the repository at this point in the history
  • Loading branch information
windingwind committed Oct 16, 2024
1 parent 93e3a78 commit 6cc3a5f
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 1 deletion.
7 changes: 7 additions & 0 deletions addon/locale/en-US/addon.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions addon/locale/it-IT/addon.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions addon/locale/zh-CN/addon.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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 配置项
Expand Down
1 change: 1 addition & 0 deletions addon/prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,4 @@ pref(
);
pref("__prefsPrefix__.cnkiSplitSecond", 1);
pref("__prefsPrefix__.cnkiUseSplit", false);
pref("__prefsPrefix__.deeplx.endpoint", "https://www2.deepl.com/jsonrpc");
4 changes: 3 additions & 1 deletion src/modules/services/deeplx.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { getPref } from "../../utils/prefs";
import { TranslateTaskProcessor } from "../../utils/task";
export default <TranslateTaskProcessor>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();
Expand Down
43 changes: 43 additions & 0 deletions src/modules/settings/deeplx.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}
8 changes: 8 additions & 0 deletions src/modules/settings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]: {
Expand All @@ -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",
Expand Down

0 comments on commit 6cc3a5f

Please sign in to comment.