Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f463f3ce08 | ||
|
|
c0872db98c | ||
|
|
d3a5d91f01 | ||
|
|
3e9338be0e | ||
|
|
ef7f1ad638 | ||
|
|
1f10ebe404 | ||
|
|
f4a8251c61 |
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.5.1
|
REACT_APP_VERSION=1.5.3
|
||||||
REACT_APP_HOMEPAGE=https://github.com/fishjar/kiss-translator
|
REACT_APP_HOMEPAGE=https://github.com/fishjar/kiss-translator
|
||||||
REACT_APP_OPTIONSPAGE=https://kiss-translator.rayjar.com/options
|
REACT_APP_OPTIONSPAGE=https://kiss-translator.rayjar.com/options
|
||||||
REACT_APP_OPTIONSPAGE2=https://fishjar.github.io/kiss-translator/options.html
|
REACT_APP_OPTIONSPAGE2=https://fishjar.github.io/kiss-translator/options.html
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ const userscriptWebpack = (config, env) => {
|
|||||||
// @grant GM.setValue
|
// @grant GM.setValue
|
||||||
// @grant GM.getValue
|
// @grant GM.getValue
|
||||||
// @grant GM.deleteValue
|
// @grant GM.deleteValue
|
||||||
|
// @grant GM.info
|
||||||
// @grant unsafeWindow
|
// @grant unsafeWindow
|
||||||
// @connect translate.googleapis.com
|
// @connect translate.googleapis.com
|
||||||
// @connect api-edge.cognitive.microsofttranslator.com
|
// @connect api-edge.cognitive.microsofttranslator.com
|
||||||
@@ -98,6 +99,7 @@ const userscriptWebpack = (config, env) => {
|
|||||||
// @connect github.io
|
// @connect github.io
|
||||||
// @connect githubusercontent.com
|
// @connect githubusercontent.com
|
||||||
// @connect kiss-translator.rayjar.com
|
// @connect kiss-translator.rayjar.com
|
||||||
|
// @connect ghproxy.com
|
||||||
// @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.5.1",
|
"version": "1.5.3",
|
||||||
"author": "Gabe<yugang2002@gmail.com>",
|
"author": "Gabe<yugang2002@gmail.com>",
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@@ -7,5 +7,8 @@
|
|||||||
},
|
},
|
||||||
"toggle_translate": {
|
"toggle_translate": {
|
||||||
"message": "Toggle Translate"
|
"message": "Toggle Translate"
|
||||||
|
},
|
||||||
|
"toggle_style": {
|
||||||
|
"message": "Toggle Style"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,5 +7,8 @@
|
|||||||
},
|
},
|
||||||
"toggle_translate": {
|
"toggle_translate": {
|
||||||
"message": "切换翻译"
|
"message": "切换翻译"
|
||||||
|
},
|
||||||
|
"toggle_style": {
|
||||||
|
"message": "切换样式"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.5.1",
|
"version": "1.5.3",
|
||||||
"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",
|
||||||
@@ -21,6 +21,12 @@
|
|||||||
"default": "Alt+Q"
|
"default": "Alt+Q"
|
||||||
},
|
},
|
||||||
"description": "__MSG_toggle_translate__"
|
"description": "__MSG_toggle_translate__"
|
||||||
|
},
|
||||||
|
"toggleStyle": {
|
||||||
|
"suggested_key": {
|
||||||
|
"default": "Alt+C"
|
||||||
|
},
|
||||||
|
"description": "__MSG_toggle_style__"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"permissions": ["<all_urls>", "storage"],
|
"permissions": ["<all_urls>", "storage"],
|
||||||
|
|||||||
@@ -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.5.1",
|
"version": "1.5.3",
|
||||||
"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",
|
||||||
@@ -22,6 +22,12 @@
|
|||||||
"default": "Alt+Q"
|
"default": "Alt+Q"
|
||||||
},
|
},
|
||||||
"description": "__MSG_toggle_translate__"
|
"description": "__MSG_toggle_translate__"
|
||||||
|
},
|
||||||
|
"toggleStyle": {
|
||||||
|
"suggested_key": {
|
||||||
|
"default": "Alt+C"
|
||||||
|
},
|
||||||
|
"description": "__MSG_toggle_style__"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"permissions": ["storage"],
|
"permissions": ["storage"],
|
||||||
|
|||||||
@@ -21,18 +21,14 @@ import { sha256 } from "../libs/utils";
|
|||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export const apiSyncData = async (url, key, data) =>
|
export const apiSyncData = async (url, key, data) =>
|
||||||
fetchPolyfill(
|
fetchPolyfill(url, {
|
||||||
url,
|
|
||||||
{
|
|
||||||
headers: {
|
headers: {
|
||||||
"Content-type": "application/json",
|
"Content-type": "application/json",
|
||||||
Authorization: `Bearer ${await sha256(key, KV_SALT_SYNC)}`,
|
Authorization: `Bearer ${await sha256(key, KV_SALT_SYNC)}`,
|
||||||
},
|
},
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: JSON.stringify(data),
|
body: JSON.stringify(data),
|
||||||
},
|
});
|
||||||
{ useUnsafe: true }
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 谷歌翻译
|
* 谷歌翻译
|
||||||
|
|||||||
@@ -4,7 +4,9 @@ import {
|
|||||||
MSG_FETCH_LIMIT,
|
MSG_FETCH_LIMIT,
|
||||||
MSG_FETCH_CLEAR,
|
MSG_FETCH_CLEAR,
|
||||||
MSG_TRANS_TOGGLE,
|
MSG_TRANS_TOGGLE,
|
||||||
|
MSG_TRANS_TOGGLE_STYLE,
|
||||||
CMD_TOGGLE_TRANSLATE,
|
CMD_TOGGLE_TRANSLATE,
|
||||||
|
CMD_TOGGLE_STYLE,
|
||||||
DEFAULT_SETTING,
|
DEFAULT_SETTING,
|
||||||
DEFAULT_RULES,
|
DEFAULT_RULES,
|
||||||
DEFAULT_SYNC,
|
DEFAULT_SYNC,
|
||||||
@@ -87,6 +89,9 @@ browser.commands.onCommand.addListener((command) => {
|
|||||||
case CMD_TOGGLE_TRANSLATE:
|
case CMD_TOGGLE_TRANSLATE:
|
||||||
sendTabMsg(MSG_TRANS_TOGGLE);
|
sendTabMsg(MSG_TRANS_TOGGLE);
|
||||||
break;
|
break;
|
||||||
|
case CMD_TOGGLE_STYLE:
|
||||||
|
sendTabMsg(MSG_TRANS_TOGGLE_STYLE);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ export const STOKEY_FAB = `${APP_NAME}_fab`;
|
|||||||
export const STOKEY_RULESCACHE_PREFIX = `${APP_NAME}_rulescache_`;
|
export const STOKEY_RULESCACHE_PREFIX = `${APP_NAME}_rulescache_`;
|
||||||
|
|
||||||
export const CMD_TOGGLE_TRANSLATE = "toggleTranslate";
|
export const CMD_TOGGLE_TRANSLATE = "toggleTranslate";
|
||||||
|
export const CMD_TOGGLE_STYLE = "toggleStyle";
|
||||||
|
|
||||||
export const CLIENT_WEB = "web";
|
export const CLIENT_WEB = "web";
|
||||||
export const CLIENT_CHROME = "chrome";
|
export const CLIENT_CHROME = "chrome";
|
||||||
@@ -39,6 +40,7 @@ export const MSG_FETCH = "fetch";
|
|||||||
export const MSG_FETCH_LIMIT = "fetch_limit";
|
export const MSG_FETCH_LIMIT = "fetch_limit";
|
||||||
export const MSG_FETCH_CLEAR = "fetch_clear";
|
export const MSG_FETCH_CLEAR = "fetch_clear";
|
||||||
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_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";
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { browser } from "./libs/browser";
|
import { browser } from "./libs/browser";
|
||||||
import {
|
import {
|
||||||
MSG_TRANS_TOGGLE,
|
MSG_TRANS_TOGGLE,
|
||||||
|
MSG_TRANS_TOGGLE_STYLE,
|
||||||
MSG_TRANS_GETRULE,
|
MSG_TRANS_GETRULE,
|
||||||
MSG_TRANS_PUTRULE,
|
MSG_TRANS_PUTRULE,
|
||||||
} from "./config";
|
} from "./config";
|
||||||
@@ -22,6 +23,9 @@ import { Translator } from "./libs/translator";
|
|||||||
case MSG_TRANS_TOGGLE:
|
case MSG_TRANS_TOGGLE:
|
||||||
translator.toggle();
|
translator.toggle();
|
||||||
break;
|
break;
|
||||||
|
case MSG_TRANS_TOGGLE_STYLE:
|
||||||
|
translator.toggleStyle();
|
||||||
|
break;
|
||||||
case MSG_TRANS_GETRULE:
|
case MSG_TRANS_GETRULE:
|
||||||
break;
|
break;
|
||||||
case MSG_TRANS_PUTRULE:
|
case MSG_TRANS_PUTRULE:
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ const newCacheReq = async (request) => {
|
|||||||
* @param {*} param0
|
* @param {*} param0
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
const fetchApi = async ({ input, init, useUnsafe, translator, token }) => {
|
const fetchApi = async ({ input, init, translator, token }) => {
|
||||||
if (translator === OPT_TRANS_MICROSOFT) {
|
if (translator === OPT_TRANS_MICROSOFT) {
|
||||||
init.headers["Authorization"] = `Bearer ${token}`;
|
init.headers["Authorization"] = `Bearer ${token}`;
|
||||||
} else if (translator === OPT_TRANS_OPENAI) {
|
} else if (translator === OPT_TRANS_OPENAI) {
|
||||||
@@ -73,9 +73,14 @@ const fetchApi = async ({ input, init, useUnsafe, translator, token }) => {
|
|||||||
init.headers["api-key"] = token; // Azure OpenAI
|
init.headers["api-key"] = token; // Azure OpenAI
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isGm && !useUnsafe) {
|
if (isGm) {
|
||||||
|
const connects = GM?.info?.script?.connects || [];
|
||||||
|
const url = new URL(input);
|
||||||
|
const isSafe = connects.find((item) => url.hostname.endsWith(item));
|
||||||
|
if (isSafe) {
|
||||||
return fetchGM(input, init);
|
return fetchGM(input, init);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return fetch(input, init);
|
return fetch(input, init);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -105,7 +110,7 @@ export const fetchPool = taskPool(
|
|||||||
export const fetchData = async (
|
export const fetchData = async (
|
||||||
input,
|
input,
|
||||||
init,
|
init,
|
||||||
{ useCache, usePool, translator, useUnsafe, token } = {}
|
{ useCache, usePool, translator, token } = {}
|
||||||
) => {
|
) => {
|
||||||
const cacheReq = await newCacheReq(new Request(input, init));
|
const cacheReq = await newCacheReq(new Request(input, init));
|
||||||
const cache = await caches.open(CACHE_NAME);
|
const cache = await caches.open(CACHE_NAME);
|
||||||
@@ -123,9 +128,9 @@ export const fetchData = async (
|
|||||||
if (!res) {
|
if (!res) {
|
||||||
// 发送请求
|
// 发送请求
|
||||||
if (usePool) {
|
if (usePool) {
|
||||||
res = await fetchPool.push({ input, init, useUnsafe, translator, token });
|
res = await fetchPool.push({ input, init, translator, token });
|
||||||
} else {
|
} else {
|
||||||
res = await fetchApi({ input, init, useUnsafe, translator, token });
|
res = await fetchApi({ input, init, translator, token });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!res?.ok) {
|
if (!res?.ok) {
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ export const syncRules = async () => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log("[sync rules]", err);
|
console.log("[sync user rules]", err);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import {
|
|||||||
TRANS_MAX_LENGTH,
|
TRANS_MAX_LENGTH,
|
||||||
EVENT_KISS,
|
EVENT_KISS,
|
||||||
MSG_TRANS_CURRULE,
|
MSG_TRANS_CURRULE,
|
||||||
|
OPT_STYLE_DASHLINE,
|
||||||
|
OPT_STYLE_FUZZY,
|
||||||
} from "../config";
|
} from "../config";
|
||||||
import { queryEls } from ".";
|
import { queryEls } from ".";
|
||||||
import Content from "../views/Content";
|
import Content from "../views/Content";
|
||||||
@@ -86,6 +88,14 @@ export class Translator {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
toggleStyle = () => {
|
||||||
|
const textStyle =
|
||||||
|
this.rule.textStyle === OPT_STYLE_FUZZY
|
||||||
|
? OPT_STYLE_DASHLINE
|
||||||
|
: OPT_STYLE_FUZZY;
|
||||||
|
this.rule = { ...this.rule, textStyle };
|
||||||
|
};
|
||||||
|
|
||||||
_register = () => {
|
_register = () => {
|
||||||
// 监听节点变化
|
// 监听节点变化
|
||||||
this._mutaObserver.observe(document, {
|
this._mutaObserver.observe(document, {
|
||||||
|
|||||||
@@ -59,9 +59,15 @@ import { Translator } from "./libs/translator";
|
|||||||
GM.registerMenuCommand(
|
GM.registerMenuCommand(
|
||||||
"Toggle Translate",
|
"Toggle Translate",
|
||||||
(event) => {
|
(event) => {
|
||||||
// console.log("Menu item selected", event);
|
|
||||||
translator.toggle();
|
translator.toggle();
|
||||||
},
|
},
|
||||||
"Q"
|
"Q"
|
||||||
);
|
);
|
||||||
|
GM.registerMenuCommand(
|
||||||
|
"Toggle Style",
|
||||||
|
(event) => {
|
||||||
|
translator.toggleStyle();
|
||||||
|
},
|
||||||
|
"C"
|
||||||
|
);
|
||||||
})();
|
})();
|
||||||
|
|||||||
@@ -548,7 +548,7 @@ function SubRulesItem({ index, url, selectedUrl, subrules, setRules }) {
|
|||||||
setRules(rules);
|
setRules(rules);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log("[sync rules]", err);
|
console.log("[sync sub rules]", err);
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user