Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7379ff8d15 | ||
|
|
18ebec350d | ||
|
|
3b0cbc53aa | ||
|
|
f00e8ffa4d | ||
|
|
d6f7aad1c3 | ||
|
|
092ea6e836 | ||
|
|
d565e2464a |
10
.env
10
.env
@@ -2,26 +2,18 @@ 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.8.5
|
REACT_APP_VERSION=1.8.6
|
||||||
|
|
||||||
REACT_APP_HOMEPAGE=https://github.com/fishjar/kiss-translator
|
REACT_APP_HOMEPAGE=https://github.com/fishjar/kiss-translator
|
||||||
|
|
||||||
REACT_APP_OPTIONSPAGE=https://fishjar.github.io/kiss-translator/options.html
|
REACT_APP_OPTIONSPAGE=https://fishjar.github.io/kiss-translator/options.html
|
||||||
REACT_APP_OPTIONSPAGE2=https://kiss-translator.rayjar.com/options
|
|
||||||
REACT_APP_OPTIONSPAGE_DEV=http://localhost:3000/options.html
|
REACT_APP_OPTIONSPAGE_DEV=http://localhost:3000/options.html
|
||||||
|
|
||||||
REACT_APP_LOGOURL=https://fishjar.github.io/kiss-translator/images/logo192.png
|
REACT_APP_LOGOURL=https://fishjar.github.io/kiss-translator/images/logo192.png
|
||||||
REACT_APP_LOGOURL2=https://kiss-translator.rayjar.com/images/logo192.png
|
|
||||||
|
|
||||||
REACT_APP_RULESURL=https://fishjar.github.io/kiss-rules/kiss-rules.json
|
REACT_APP_RULESURL=https://fishjar.github.io/kiss-rules/kiss-rules.json
|
||||||
REACT_APP_RULESURL_ON=https://fishjar.github.io/kiss-rules/kiss-rules-on.json
|
REACT_APP_RULESURL_ON=https://fishjar.github.io/kiss-rules/kiss-rules-on.json
|
||||||
REACT_APP_RULESURL_OFF=https://fishjar.github.io/kiss-rules/kiss-rules-off.json
|
REACT_APP_RULESURL_OFF=https://fishjar.github.io/kiss-rules/kiss-rules-off.json
|
||||||
|
|
||||||
REACT_APP_VERSIONFILE=https://fishjar.github.io/kiss-translator/version.txt
|
|
||||||
REACT_APP_VERSIONFILE2=https://kiss-translator.rayjar.com/version.txt
|
|
||||||
|
|
||||||
REACT_APP_USERSCRIPT_DOWNLOADURL=https://fishjar.github.io/kiss-translator/kiss-translator.user.js
|
REACT_APP_USERSCRIPT_DOWNLOADURL=https://fishjar.github.io/kiss-translator/kiss-translator.user.js
|
||||||
REACT_APP_USERSCRIPT_DOWNLOADURL2=https://kiss-translator.rayjar.com/kiss-translator.user.js
|
|
||||||
|
|
||||||
REACT_APP_USERSCRIPT_IOS_DOWNLOADURL=https://fishjar.github.io/kiss-translator/kiss-translator-ios-safari.user.js
|
REACT_APP_USERSCRIPT_IOS_DOWNLOADURL=https://fishjar.github.io/kiss-translator/kiss-translator-ios-safari.user.js
|
||||||
REACT_APP_USERSCRIPT_IOS_DOWNLOADURL2=https://kiss-translator.rayjar.com/kiss-translator-ios-safari.user.js
|
|
||||||
|
|||||||
@@ -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.8.5",
|
"version": "1.8.6",
|
||||||
"author": "Gabe<yugang2002@gmail.com>",
|
"author": "Gabe<yugang2002@gmail.com>",
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@@ -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.8.5",
|
"version": "1.8.6",
|
||||||
"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",
|
||||||
|
|||||||
@@ -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.8.5",
|
"version": "1.8.6",
|
||||||
"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",
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import {
|
|||||||
URL_BAIDU_WEB,
|
URL_BAIDU_WEB,
|
||||||
URL_BAIDU_TRANSAPI_V2,
|
URL_BAIDU_TRANSAPI_V2,
|
||||||
URL_BAIDU_TRANSAPI,
|
URL_BAIDU_TRANSAPI,
|
||||||
|
DEFAULT_USER_AGENT,
|
||||||
} from "../config";
|
} from "../config";
|
||||||
import { fetchApi } from "../libs/fetch";
|
import { fetchApi } from "../libs/fetch";
|
||||||
|
|
||||||
@@ -248,7 +249,9 @@ export const genBaidu = async ({ text, from, to }) => {
|
|||||||
|
|
||||||
const init = {
|
const init = {
|
||||||
headers: {
|
headers: {
|
||||||
|
// Origin: "https://fanyi.baidu.com",
|
||||||
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
|
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
|
||||||
|
"User-Agent": DEFAULT_USER_AGENT,
|
||||||
},
|
},
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: queryString.stringify(data),
|
body: queryString.stringify(data),
|
||||||
|
|||||||
@@ -6,12 +6,17 @@ import {
|
|||||||
OPT_TRANS_DEEPL,
|
OPT_TRANS_DEEPL,
|
||||||
OPT_TRANS_DEEPLFREE,
|
OPT_TRANS_DEEPLFREE,
|
||||||
OPT_TRANS_DEEPLX,
|
OPT_TRANS_DEEPLX,
|
||||||
|
OPT_TRANS_NIUTRANS,
|
||||||
OPT_TRANS_BAIDU,
|
OPT_TRANS_BAIDU,
|
||||||
OPT_TRANS_TENCENT,
|
OPT_TRANS_TENCENT,
|
||||||
OPT_TRANS_OPENAI,
|
OPT_TRANS_OPENAI,
|
||||||
OPT_TRANS_GEMINI,
|
OPT_TRANS_GEMINI,
|
||||||
OPT_TRANS_CLOUDFLAREAI,
|
OPT_TRANS_CLOUDFLAREAI,
|
||||||
OPT_TRANS_CUSTOMIZE,
|
OPT_TRANS_CUSTOMIZE,
|
||||||
|
OPT_TRANS_CUSTOMIZE_2,
|
||||||
|
OPT_TRANS_CUSTOMIZE_3,
|
||||||
|
OPT_TRANS_CUSTOMIZE_4,
|
||||||
|
OPT_TRANS_CUSTOMIZE_5,
|
||||||
URL_CACHE_TRAN,
|
URL_CACHE_TRAN,
|
||||||
KV_SALT_SYNC,
|
KV_SALT_SYNC,
|
||||||
URL_BAIDU_LANGDETECT,
|
URL_BAIDU_LANGDETECT,
|
||||||
@@ -215,6 +220,14 @@ export const apiTranslate = async ({
|
|||||||
trText = res.data;
|
trText = res.data;
|
||||||
isSame = to === res.source_lang;
|
isSame = to === res.source_lang;
|
||||||
break;
|
break;
|
||||||
|
case OPT_TRANS_NIUTRANS:
|
||||||
|
const json = JSON.parse(res);
|
||||||
|
if (json.error_msg) {
|
||||||
|
throw new Error(json.error_msg);
|
||||||
|
}
|
||||||
|
trText = json.tgt_text;
|
||||||
|
isSame = to === json.from;
|
||||||
|
break;
|
||||||
case OPT_TRANS_BAIDU:
|
case OPT_TRANS_BAIDU:
|
||||||
// trText = res.trans_result?.data.map((item) => item.dst).join(" ");
|
// trText = res.trans_result?.data.map((item) => item.dst).join(" ");
|
||||||
// isSame = res.trans_result?.to === res.trans_result?.from;
|
// isSame = res.trans_result?.to === res.trans_result?.from;
|
||||||
@@ -245,6 +258,10 @@ export const apiTranslate = async ({
|
|||||||
isSame = text === trText;
|
isSame = text === trText;
|
||||||
break;
|
break;
|
||||||
case OPT_TRANS_CUSTOMIZE:
|
case OPT_TRANS_CUSTOMIZE:
|
||||||
|
case OPT_TRANS_CUSTOMIZE_2:
|
||||||
|
case OPT_TRANS_CUSTOMIZE_3:
|
||||||
|
case OPT_TRANS_CUSTOMIZE_4:
|
||||||
|
case OPT_TRANS_CUSTOMIZE_5:
|
||||||
trText = res.text;
|
trText = res.text;
|
||||||
isSame = to === res.from;
|
isSame = to === res.from;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -213,8 +213,7 @@ export async function run(isUserscript = false) {
|
|||||||
if (
|
if (
|
||||||
isUserscript &&
|
isUserscript &&
|
||||||
(href.includes(process.env.REACT_APP_OPTIONSPAGE_DEV) ||
|
(href.includes(process.env.REACT_APP_OPTIONSPAGE_DEV) ||
|
||||||
href.includes(process.env.REACT_APP_OPTIONSPAGE) ||
|
href.includes(process.env.REACT_APP_OPTIONSPAGE))
|
||||||
href.includes(process.env.REACT_APP_OPTIONSPAGE2))
|
|
||||||
) {
|
) {
|
||||||
runSettingPage();
|
runSettingPage();
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -819,4 +819,8 @@ export const I18N = {
|
|||||||
zh: `网页修复选择器`,
|
zh: `网页修复选择器`,
|
||||||
en: `Fixer Selector`,
|
en: `Fixer Selector`,
|
||||||
},
|
},
|
||||||
|
reg_niutrans: {
|
||||||
|
zh: `获取小牛翻译密钥`,
|
||||||
|
en: `Get NiuTrans APIKey`,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -90,12 +90,18 @@ export const URL_BAIDU_TRANSAPI = "https://fanyi.baidu.com/transapi";
|
|||||||
export const URL_BAIDU_TRANSAPI_V2 = "https://fanyi.baidu.com/v2transapi";
|
export const URL_BAIDU_TRANSAPI_V2 = "https://fanyi.baidu.com/v2transapi";
|
||||||
export const URL_DEEPLFREE_TRAN = "https://www2.deepl.com/jsonrpc";
|
export const URL_DEEPLFREE_TRAN = "https://www2.deepl.com/jsonrpc";
|
||||||
export const URL_TENCENT_TRANSMART = "https://transmart.qq.com/api/imt";
|
export const URL_TENCENT_TRANSMART = "https://transmart.qq.com/api/imt";
|
||||||
|
export const URL_NIUTRANS_REG =
|
||||||
|
"https://niutrans.com/login?active=3&userSource=kiss-translator";
|
||||||
|
|
||||||
|
export const DEFAULT_USER_AGENT =
|
||||||
|
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36";
|
||||||
|
|
||||||
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_DEEPLX = "DeepLX";
|
||||||
export const OPT_TRANS_DEEPLFREE = "DeepLFree";
|
export const OPT_TRANS_DEEPLFREE = "DeepLFree";
|
||||||
|
export const OPT_TRANS_NIUTRANS = "NiuTrans";
|
||||||
export const OPT_TRANS_BAIDU = "Baidu";
|
export const OPT_TRANS_BAIDU = "Baidu";
|
||||||
export const OPT_TRANS_TENCENT = "Tencent";
|
export const OPT_TRANS_TENCENT = "Tencent";
|
||||||
export const OPT_TRANS_OPENAI = "OpenAI";
|
export const OPT_TRANS_OPENAI = "OpenAI";
|
||||||
@@ -114,6 +120,7 @@ export const OPT_TRANS_ALL = [
|
|||||||
OPT_TRANS_DEEPL,
|
OPT_TRANS_DEEPL,
|
||||||
OPT_TRANS_DEEPLFREE,
|
OPT_TRANS_DEEPLFREE,
|
||||||
OPT_TRANS_DEEPLX,
|
OPT_TRANS_DEEPLX,
|
||||||
|
OPT_TRANS_NIUTRANS,
|
||||||
OPT_TRANS_OPENAI,
|
OPT_TRANS_OPENAI,
|
||||||
OPT_TRANS_GEMINI,
|
OPT_TRANS_GEMINI,
|
||||||
OPT_TRANS_CLOUDFLAREAI,
|
OPT_TRANS_CLOUDFLAREAI,
|
||||||
@@ -190,6 +197,12 @@ export const OPT_LANGS_SPECIAL = {
|
|||||||
["zh-CN", "ZH"],
|
["zh-CN", "ZH"],
|
||||||
["zh-TW", "ZH"],
|
["zh-TW", "ZH"],
|
||||||
]),
|
]),
|
||||||
|
[OPT_TRANS_NIUTRANS]: new Map([
|
||||||
|
...OPT_LANGS_FROM.map(([key]) => [key, key]),
|
||||||
|
["auto", "auto"],
|
||||||
|
["zh-CN", "zh"],
|
||||||
|
["zh-TW", "cht"],
|
||||||
|
]),
|
||||||
[OPT_TRANS_BAIDU]: new Map([
|
[OPT_TRANS_BAIDU]: new Map([
|
||||||
...OPT_LANGS_FROM.map(([key]) => [key, key]),
|
...OPT_LANGS_FROM.map(([key]) => [key, key]),
|
||||||
["zh-CN", "zh"],
|
["zh-CN", "zh"],
|
||||||
@@ -263,6 +276,22 @@ export const OPT_LANGS_SPECIAL = {
|
|||||||
...OPT_LANGS_FROM.map(([key]) => [key, key]),
|
...OPT_LANGS_FROM.map(([key]) => [key, key]),
|
||||||
["auto", ""],
|
["auto", ""],
|
||||||
]),
|
]),
|
||||||
|
[OPT_TRANS_CUSTOMIZE_2]: new Map([
|
||||||
|
...OPT_LANGS_FROM.map(([key]) => [key, key]),
|
||||||
|
["auto", ""],
|
||||||
|
]),
|
||||||
|
[OPT_TRANS_CUSTOMIZE_3]: new Map([
|
||||||
|
...OPT_LANGS_FROM.map(([key]) => [key, key]),
|
||||||
|
["auto", ""],
|
||||||
|
]),
|
||||||
|
[OPT_TRANS_CUSTOMIZE_4]: new Map([
|
||||||
|
...OPT_LANGS_FROM.map(([key]) => [key, key]),
|
||||||
|
["auto", ""],
|
||||||
|
]),
|
||||||
|
[OPT_TRANS_CUSTOMIZE_5]: 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(
|
export const OPT_LANGS_BAIDU = new Map(
|
||||||
@@ -450,6 +479,14 @@ export const DEFAULT_TRANS_APIS = {
|
|||||||
fetchLimit: 1,
|
fetchLimit: 1,
|
||||||
fetchInterval: 500,
|
fetchInterval: 500,
|
||||||
},
|
},
|
||||||
|
[OPT_TRANS_NIUTRANS]: {
|
||||||
|
url: "https://api.niutrans.com/NiuTransServer/translation",
|
||||||
|
key: "",
|
||||||
|
dictNo: "",
|
||||||
|
memoryNo: "",
|
||||||
|
fetchLimit: DEFAULT_FETCH_LIMIT,
|
||||||
|
fetchInterval: DEFAULT_FETCH_INTERVAL,
|
||||||
|
},
|
||||||
[OPT_TRANS_OPENAI]: {
|
[OPT_TRANS_OPENAI]: {
|
||||||
url: "https://api.openai.com/v1/chat/completions",
|
url: "https://api.openai.com/v1/chat/completions",
|
||||||
key: "",
|
key: "",
|
||||||
|
|||||||
@@ -8,7 +8,10 @@ export function useApi(translator) {
|
|||||||
|
|
||||||
const updateApi = useCallback(
|
const updateApi = useCallback(
|
||||||
async (obj) => {
|
async (obj) => {
|
||||||
const api = transApis[translator] || {};
|
const api = {
|
||||||
|
...DEFAULT_TRANS_APIS[translator],
|
||||||
|
...(transApis[translator] || {}),
|
||||||
|
};
|
||||||
Object.assign(transApis, { [translator]: { ...api, ...obj } });
|
Object.assign(transApis, { [translator]: { ...api, ...obj } });
|
||||||
await updateSetting({ transApis });
|
await updateSetting({ transApis });
|
||||||
},
|
},
|
||||||
@@ -20,5 +23,12 @@ export function useApi(translator) {
|
|||||||
await updateSetting({ transApis });
|
await updateSetting({ transApis });
|
||||||
}, [translator, transApis, updateSetting]);
|
}, [translator, transApis, updateSetting]);
|
||||||
|
|
||||||
return { api: transApis[translator] || {}, updateApi, resetApi };
|
return {
|
||||||
|
api: {
|
||||||
|
...DEFAULT_TRANS_APIS[translator],
|
||||||
|
...(transApis[translator] || {}),
|
||||||
|
},
|
||||||
|
updateApi,
|
||||||
|
resetApi,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,8 +39,10 @@ export function useTranslate(q, rule, setting) {
|
|||||||
text: q,
|
text: q,
|
||||||
fromLang,
|
fromLang,
|
||||||
toLang,
|
toLang,
|
||||||
apiSetting:
|
apiSetting: {
|
||||||
setting.transApis?.[translator] || DEFAULT_TRANS_APIS[translator],
|
...DEFAULT_TRANS_APIS[translator],
|
||||||
|
...(setting.transApis[translator] || {}),
|
||||||
|
},
|
||||||
});
|
});
|
||||||
setText(trText);
|
setText(trText);
|
||||||
setSamelang(isSame);
|
setSamelang(isSame);
|
||||||
|
|||||||
@@ -36,19 +36,10 @@ function App() {
|
|||||||
<Link href={process.env.REACT_APP_USERSCRIPT_DOWNLOADURL}>
|
<Link href={process.env.REACT_APP_USERSCRIPT_DOWNLOADURL}>
|
||||||
Install/Update Userscript for Tampermonkey/Violentmonkey
|
Install/Update Userscript for Tampermonkey/Violentmonkey
|
||||||
</Link>
|
</Link>
|
||||||
{/* <Link href={process.env.REACT_APP_USERSCRIPT_DOWNLOADURL2}>
|
|
||||||
Install/Update Userscript for Tampermonkey/Violentmonkey 2
|
|
||||||
</Link> */}
|
|
||||||
<Link href={process.env.REACT_APP_USERSCRIPT_IOS_DOWNLOADURL}>
|
<Link href={process.env.REACT_APP_USERSCRIPT_IOS_DOWNLOADURL}>
|
||||||
Install/Update Userscript for iOS Safari
|
Install/Update Userscript for iOS Safari
|
||||||
</Link>
|
</Link>
|
||||||
{/* <Link href={process.env.REACT_APP_USERSCRIPT_IOS_DOWNLOADURL2}>
|
|
||||||
Install/Update Userscript for iOS Safari 2
|
|
||||||
</Link> */}
|
|
||||||
<Link href={process.env.REACT_APP_OPTIONSPAGE}>Open Options Page</Link>
|
<Link href={process.env.REACT_APP_OPTIONSPAGE}>Open Options Page</Link>
|
||||||
{/* <Link href={process.env.REACT_APP_OPTIONSPAGE2}>
|
|
||||||
Open Options Page 2
|
|
||||||
</Link> */}
|
|
||||||
</Stack>
|
</Stack>
|
||||||
|
|
||||||
{loading ? (
|
{loading ? (
|
||||||
|
|||||||
@@ -139,9 +139,11 @@ export const fetchData = async (
|
|||||||
res = await fetchApi({ input, init, transOpts, apiSetting });
|
res = await fetchApi({ input, init, transOpts, apiSetting });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!res?.ok) {
|
if (!res) {
|
||||||
|
throw new Error("Unknow error");
|
||||||
|
} else if (!res.ok) {
|
||||||
const msg = {
|
const msg = {
|
||||||
url: input,
|
url: res.url,
|
||||||
status: res.status,
|
status: res.status,
|
||||||
};
|
};
|
||||||
if (res.headers.get("Content-Type")?.includes("json")) {
|
if (res.headers.get("Content-Type")?.includes("json")) {
|
||||||
|
|||||||
@@ -5,12 +5,17 @@ import {
|
|||||||
OPT_TRANS_DEEPL,
|
OPT_TRANS_DEEPL,
|
||||||
OPT_TRANS_DEEPLFREE,
|
OPT_TRANS_DEEPLFREE,
|
||||||
OPT_TRANS_DEEPLX,
|
OPT_TRANS_DEEPLX,
|
||||||
|
OPT_TRANS_NIUTRANS,
|
||||||
OPT_TRANS_BAIDU,
|
OPT_TRANS_BAIDU,
|
||||||
OPT_TRANS_TENCENT,
|
OPT_TRANS_TENCENT,
|
||||||
OPT_TRANS_OPENAI,
|
OPT_TRANS_OPENAI,
|
||||||
OPT_TRANS_GEMINI,
|
OPT_TRANS_GEMINI,
|
||||||
OPT_TRANS_CLOUDFLAREAI,
|
OPT_TRANS_CLOUDFLAREAI,
|
||||||
OPT_TRANS_CUSTOMIZE,
|
OPT_TRANS_CUSTOMIZE,
|
||||||
|
OPT_TRANS_CUSTOMIZE_2,
|
||||||
|
OPT_TRANS_CUSTOMIZE_3,
|
||||||
|
OPT_TRANS_CUSTOMIZE_4,
|
||||||
|
OPT_TRANS_CUSTOMIZE_5,
|
||||||
URL_MICROSOFT_TRAN,
|
URL_MICROSOFT_TRAN,
|
||||||
URL_TENCENT_TRANSMART,
|
URL_TENCENT_TRANSMART,
|
||||||
PROMPT_PLACE_FROM,
|
PROMPT_PLACE_FROM,
|
||||||
@@ -141,6 +146,27 @@ const genDeeplX = ({ text, from, to, url, key }) => {
|
|||||||
return [url, init];
|
return [url, init];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const genNiuTrans = ({ text, from, to, url, key, dictNo, memoryNo }) => {
|
||||||
|
const data = {
|
||||||
|
from,
|
||||||
|
to,
|
||||||
|
apikey: key,
|
||||||
|
src_text: text,
|
||||||
|
dictNo,
|
||||||
|
memoryNo,
|
||||||
|
};
|
||||||
|
|
||||||
|
const init = {
|
||||||
|
headers: {
|
||||||
|
"Content-type": "application/json",
|
||||||
|
},
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify(data),
|
||||||
|
};
|
||||||
|
|
||||||
|
return [url, init];
|
||||||
|
};
|
||||||
|
|
||||||
const genTencent = ({ text, from, to }) => {
|
const genTencent = ({ text, from, to }) => {
|
||||||
const data = {
|
const data = {
|
||||||
header: {
|
header: {
|
||||||
@@ -283,6 +309,7 @@ export const newTransReq = ({ translator, text, from, to }, apiSetting) => {
|
|||||||
case OPT_TRANS_OPENAI:
|
case OPT_TRANS_OPENAI:
|
||||||
case OPT_TRANS_GEMINI:
|
case OPT_TRANS_GEMINI:
|
||||||
case OPT_TRANS_CLOUDFLAREAI:
|
case OPT_TRANS_CLOUDFLAREAI:
|
||||||
|
case OPT_TRANS_NIUTRANS:
|
||||||
args.key = keyPick(translator, args.key);
|
args.key = keyPick(translator, args.key);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -299,6 +326,8 @@ export const newTransReq = ({ translator, text, from, to }, apiSetting) => {
|
|||||||
return genDeeplFree(args);
|
return genDeeplFree(args);
|
||||||
case OPT_TRANS_DEEPLX:
|
case OPT_TRANS_DEEPLX:
|
||||||
return genDeeplX(args);
|
return genDeeplX(args);
|
||||||
|
case OPT_TRANS_NIUTRANS:
|
||||||
|
return genNiuTrans(args);
|
||||||
case OPT_TRANS_BAIDU:
|
case OPT_TRANS_BAIDU:
|
||||||
return genBaidu(args);
|
return genBaidu(args);
|
||||||
case OPT_TRANS_TENCENT:
|
case OPT_TRANS_TENCENT:
|
||||||
@@ -310,6 +339,10 @@ export const newTransReq = ({ translator, text, from, to }, apiSetting) => {
|
|||||||
case OPT_TRANS_CLOUDFLAREAI:
|
case OPT_TRANS_CLOUDFLAREAI:
|
||||||
return genCloudflareAI(args);
|
return genCloudflareAI(args);
|
||||||
case OPT_TRANS_CUSTOMIZE:
|
case OPT_TRANS_CUSTOMIZE:
|
||||||
|
case OPT_TRANS_CUSTOMIZE_2:
|
||||||
|
case OPT_TRANS_CUSTOMIZE_3:
|
||||||
|
case OPT_TRANS_CUSTOMIZE_4:
|
||||||
|
case OPT_TRANS_CUSTOMIZE_5:
|
||||||
return genCustom(args);
|
return genCustom(args);
|
||||||
default:
|
default:
|
||||||
throw new Error(`[trans] translator: ${translator} not support`);
|
throw new Error(`[trans] translator: ${translator} not support`);
|
||||||
|
|||||||
@@ -202,26 +202,20 @@ export const removeEndchar = (s, c, count = 1) => {
|
|||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export const matchInputStr = (str, sign) => {
|
export const matchInputStr = (str, sign) => {
|
||||||
let reg = /\/([\w-]+)\s+([^]+)/;
|
|
||||||
switch (sign) {
|
switch (sign) {
|
||||||
case "//":
|
case "//":
|
||||||
reg = /\/\/([\w-]+)\s+([^]+)/;
|
return str.match(/\/\/([\w-]+)\s+([^]+)/);
|
||||||
break;
|
|
||||||
case "\\":
|
case "\\":
|
||||||
reg = /\\([\w-]+)\s+([^]+)/;
|
return str.match(/\\([\w-]+)\s+([^]+)/);
|
||||||
break;
|
|
||||||
case "\\\\":
|
case "\\\\":
|
||||||
reg = /\\\\([\w-]+)\s+([^]+)/;
|
return str.match(/\\\\([\w-]+)\s+([^]+)/);
|
||||||
break;
|
|
||||||
case ">":
|
case ">":
|
||||||
reg = />([\w-]+)\s+([^]+)/;
|
return str.match(/>([\w-]+)\s+([^]+)/);
|
||||||
break;
|
|
||||||
case ">>":
|
case ">>":
|
||||||
reg = />>([\w-]+)\s+([^]+)/;
|
return str.match(/>>([\w-]+)\s+([^]+)/);
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
return str.match(reg);
|
return str.match(/\/([\w-]+)\s+([^]+)/);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -13,7 +13,9 @@ import {
|
|||||||
OPT_TRANS_GEMINI,
|
OPT_TRANS_GEMINI,
|
||||||
OPT_TRANS_CLOUDFLAREAI,
|
OPT_TRANS_CLOUDFLAREAI,
|
||||||
OPT_TRANS_CUSTOMIZE,
|
OPT_TRANS_CUSTOMIZE,
|
||||||
|
OPT_TRANS_NIUTRANS,
|
||||||
URL_KISS_PROXY,
|
URL_KISS_PROXY,
|
||||||
|
URL_NIUTRANS_REG,
|
||||||
DEFAULT_FETCH_LIMIT,
|
DEFAULT_FETCH_LIMIT,
|
||||||
DEFAULT_FETCH_INTERVAL,
|
DEFAULT_FETCH_INTERVAL,
|
||||||
} from "../../config";
|
} from "../../config";
|
||||||
@@ -62,14 +64,24 @@ function TestButton({ translator, api }) {
|
|||||||
alert.error(
|
alert.error(
|
||||||
<>
|
<>
|
||||||
<div>{i18n("test_failed")}</div>
|
<div>{i18n("test_failed")}</div>
|
||||||
<pre
|
{msg === err.message ? (
|
||||||
style={{
|
<div
|
||||||
maxWidth: 400,
|
style={{
|
||||||
overflow: "auto",
|
maxWidth: 400,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{msg}
|
{msg}
|
||||||
</pre>
|
</div>
|
||||||
|
) : (
|
||||||
|
<pre
|
||||||
|
style={{
|
||||||
|
maxWidth: 400,
|
||||||
|
overflow: "auto",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{msg}
|
||||||
|
</pre>
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
} finally {
|
} finally {
|
||||||
@@ -98,6 +110,8 @@ function ApiFields({ translator }) {
|
|||||||
prompt = "",
|
prompt = "",
|
||||||
fetchLimit = DEFAULT_FETCH_LIMIT,
|
fetchLimit = DEFAULT_FETCH_LIMIT,
|
||||||
fetchInterval = DEFAULT_FETCH_INTERVAL,
|
fetchInterval = DEFAULT_FETCH_INTERVAL,
|
||||||
|
dictNo = "",
|
||||||
|
memoryNo = "",
|
||||||
} = api;
|
} = api;
|
||||||
|
|
||||||
const handleChange = (e) => {
|
const handleChange = (e) => {
|
||||||
@@ -128,8 +142,23 @@ function ApiFields({ translator }) {
|
|||||||
OPT_TRANS_OPENAI,
|
OPT_TRANS_OPENAI,
|
||||||
OPT_TRANS_GEMINI,
|
OPT_TRANS_GEMINI,
|
||||||
OPT_TRANS_CLOUDFLAREAI,
|
OPT_TRANS_CLOUDFLAREAI,
|
||||||
|
OPT_TRANS_NIUTRANS,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const keyHelper =
|
||||||
|
translator === OPT_TRANS_NIUTRANS ? (
|
||||||
|
<>
|
||||||
|
{i18n("mulkeys_help")}
|
||||||
|
<Link href={URL_NIUTRANS_REG} target="_blank">
|
||||||
|
{i18n("reg_niutrans")}
|
||||||
|
</Link>
|
||||||
|
</>
|
||||||
|
) : mulkeysTranslators.includes(translator) ? (
|
||||||
|
i18n("mulkeys_help")
|
||||||
|
) : (
|
||||||
|
""
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack spacing={3}>
|
<Stack spacing={3}>
|
||||||
{!buildinTranslators.includes(translator) && (
|
{!buildinTranslators.includes(translator) && (
|
||||||
@@ -148,11 +177,7 @@ function ApiFields({ translator }) {
|
|||||||
value={key}
|
value={key}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
multiline={mulkeysTranslators.includes(translator)}
|
multiline={mulkeysTranslators.includes(translator)}
|
||||||
helperText={
|
helperText={keyHelper}
|
||||||
mulkeysTranslators.includes(translator)
|
|
||||||
? i18n("mulkeys_help")
|
|
||||||
: ""
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
@@ -177,6 +202,25 @@ function ApiFields({ translator }) {
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{translator === OPT_TRANS_NIUTRANS && (
|
||||||
|
<>
|
||||||
|
<TextField
|
||||||
|
size="small"
|
||||||
|
label={"DictNo"}
|
||||||
|
name="dictNo"
|
||||||
|
value={dictNo}
|
||||||
|
onChange={handleChange}
|
||||||
|
/>
|
||||||
|
<TextField
|
||||||
|
size="small"
|
||||||
|
label={"MemoryNo"}
|
||||||
|
name="memoryNo"
|
||||||
|
value={memoryNo}
|
||||||
|
onChange={handleChange}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
<TextField
|
<TextField
|
||||||
size="small"
|
size="small"
|
||||||
label={i18n("fetch_limit")}
|
label={i18n("fetch_limit")}
|
||||||
|
|||||||
@@ -81,15 +81,9 @@ export default function Options() {
|
|||||||
<Link href={process.env.REACT_APP_USERSCRIPT_DOWNLOADURL}>
|
<Link href={process.env.REACT_APP_USERSCRIPT_DOWNLOADURL}>
|
||||||
Install/Update Userscript for Tampermonkey/Violentmonkey
|
Install/Update Userscript for Tampermonkey/Violentmonkey
|
||||||
</Link>
|
</Link>
|
||||||
{/* <Link href={process.env.REACT_APP_USERSCRIPT_DOWNLOADURL2}>
|
|
||||||
Install/Update Userscript for Tampermonkey/Violentmonkey 2
|
|
||||||
</Link> */}
|
|
||||||
<Link href={process.env.REACT_APP_USERSCRIPT_IOS_DOWNLOADURL}>
|
<Link href={process.env.REACT_APP_USERSCRIPT_IOS_DOWNLOADURL}>
|
||||||
Install/Update Userscript for iOS Safari
|
Install/Update Userscript for iOS Safari
|
||||||
</Link>
|
</Link>
|
||||||
{/* <Link href={process.env.REACT_APP_USERSCRIPT_IOS_DOWNLOADURL2}>
|
|
||||||
Install/Update Userscript for iOS Safari 2
|
|
||||||
</Link> */}
|
|
||||||
</Stack>
|
</Stack>
|
||||||
</center>
|
</center>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ export default function TranBtn({ onClick, position, tranboxSetting }) {
|
|||||||
>
|
>
|
||||||
<svg
|
<svg
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
width="20"
|
width={isMobile ? "32" : "20"}
|
||||||
height="20"
|
height={isMobile ? "32" : "20"}
|
||||||
viewBox="0 0 32 32"
|
viewBox="0 0 32 32"
|
||||||
version="1.1"
|
version="1.1"
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -71,8 +71,8 @@ export default function Slection({
|
|||||||
}
|
}
|
||||||
|
|
||||||
// todo: mobile support
|
// todo: mobile support
|
||||||
window.addEventListener("mouseup", handleMouseup);
|
// window.addEventListener("mouseup", handleMouseup);
|
||||||
// window.addEventListener(isMobile ? "touchend" : "mouseup", handleMouseup);
|
window.addEventListener(isMobile ? "touchend" : "mouseup", handleMouseup);
|
||||||
return () => {
|
return () => {
|
||||||
window.removeEventListener(
|
window.removeEventListener(
|
||||||
isMobile ? "touchend" : "mouseup",
|
isMobile ? "touchend" : "mouseup",
|
||||||
|
|||||||
Reference in New Issue
Block a user