feat: support builtin AI

This commit is contained in:
Gabe
2025-10-04 21:25:54 +08:00
parent c353c88db8
commit 7b2b48f0d1
23 changed files with 558 additions and 243 deletions

View File

@@ -13,7 +13,7 @@ export const INPUT_PLACE_TEXT = "{{text}}"; // 占位符
export const INPUT_PLACE_KEY = "{{key}}"; // 占位符
export const INPUT_PLACE_MODEL = "{{model}}"; // 占位符
export const OPT_DICT_BAIDU = "Baidu";
// export const OPT_DICT_BAIDU = "Baidu";
export const OPT_DICT_BING = "Bing";
export const OPT_DICT_YOUDAO = "Youdao";
export const OPT_DICT_ALL = [OPT_DICT_BING, OPT_DICT_YOUDAO];
@@ -24,6 +24,7 @@ export const OPT_SUG_YOUDAO = "Youdao";
export const OPT_SUG_ALL = [OPT_SUG_BAIDU, OPT_SUG_YOUDAO];
export const OPT_SUG_MAP = new Set(OPT_SUG_ALL);
export const OPT_TRANS_BUILTINAI = "BuiltinAI";
export const OPT_TRANS_GOOGLE = "Google";
export const OPT_TRANS_GOOGLE_2 = "Google2";
export const OPT_TRANS_MICROSOFT = "Microsoft";
@@ -45,10 +46,11 @@ export const OPT_TRANS_CUSTOMIZE = "Custom";
// 内置支持的翻译引擎
export const OPT_ALL_TYPES = [
OPT_TRANS_BUILTINAI,
OPT_TRANS_GOOGLE,
OPT_TRANS_GOOGLE_2,
OPT_TRANS_MICROSOFT,
OPT_TRANS_BAIDU,
// OPT_TRANS_BAIDU,
OPT_TRANS_TENCENT,
OPT_TRANS_VOLCENGINE,
OPT_TRANS_DEEPL,
@@ -66,12 +68,15 @@ export const OPT_ALL_TYPES = [
];
export const OPT_LANGDETECTOR_ALL = [
OPT_TRANS_BUILTINAI,
OPT_TRANS_GOOGLE,
OPT_TRANS_MICROSOFT,
OPT_TRANS_BAIDU,
OPT_TRANS_TENCENT,
];
export const OPT_LANGDETECTOR_MAP = new Set(OPT_LANGDETECTOR_ALL);
// 翻译引擎特殊集合
export const API_SPE_TYPES = {
// 内置翻译
@@ -130,7 +135,6 @@ export const API_SPE_TYPES = {
OPT_TRANS_OPENROUTER,
OPT_TRANS_CUSTOMIZE,
]),
detector: new Set(OPT_LANGDETECTOR_ALL),
};
export const BUILTIN_STONES = [
@@ -205,6 +209,11 @@ export const OPT_LANGS_SPEC_DEFAULT_UC = new Map(
OPT_LANGS_FROM.map(([key]) => [key, key.toUpperCase()])
);
export const OPT_LANGS_TO_SPEC = {
[OPT_TRANS_BUILTINAI]: new Map([
...OPT_LANGS_SPEC_DEFAULT,
["zh-CN", "zh"],
["zh-TW", "zh"],
]),
[OPT_TRANS_GOOGLE]: OPT_LANGS_SPEC_DEFAULT,
[OPT_TRANS_GOOGLE_2]: OPT_LANGS_SPEC_DEFAULT,
[OPT_TRANS_MICROSOFT]: new Map([
@@ -392,6 +401,7 @@ const defaultApi = {
};
const defaultApiOpts = {
[OPT_TRANS_BUILTINAI]: defaultApi,
[OPT_TRANS_GOOGLE]: {
...defaultApi,
url: "https://translate.googleapis.com/translate_a/single",

View File

@@ -525,9 +525,14 @@ export const I18N = {
zh_TW: `自建 kiss-wroker 資料同步服務`,
},
about_api: {
zh: `暂未列出的接口,理论上都可以通过自定义接口的形式支持。`,
en: `Interfaces that have not yet been launched can theoretically be supported through custom interfaces.`,
zh_TW: `暫未列出的介面,理論上都可透過自訂介面的形式支援。`,
zh: `1、其中 BuiltinAI 为浏览器内置AI翻译目前仅 Chrome 138 及以上版本得到支持。`,
en: `1. BuiltinAI is the browser's built-in AI translation, which is currently only supported by Chrome 138 and above.`,
zh_TW: `1.其中 BuiltinAI 為瀏覽器內建AI翻譯目前僅 Chrome 138 以上版本支援。`,
},
about_api_2: {
zh: `2、暂未列出的接口理论上都可以通过自定义接口的形式支持。`,
en: `2. Interfaces that have not yet been launched can theoretically be supported through custom interfaces.`,
zh_TW: `2、暫未列出的介面理論上都可透過自訂介面的形式支援。`,
},
about_api_proxy: {
zh: `查看自建一个翻译接口代理`,

View File

@@ -22,3 +22,5 @@ export const MSG_COMMAND_SHORTCUTS = "command_shortcuts";
export const MSG_INJECT_JS = "inject_js";
export const MSG_INJECT_CSS = "inject_css";
export const MSG_UPDATE_CSP = "update_csp";
export const MSG_BUILTINAI_DETECT = "builtinai_detect";
export const MSG_BUILTINAI_TRANSLATE = "builtinai_translte";

View File

@@ -25,8 +25,8 @@ export const OPT_STYLE_ALL = [
OPT_STYLE_LINE,
OPT_STYLE_DOTLINE,
OPT_STYLE_DASHLINE,
OPT_STYLE_DASHBOX,
OPT_STYLE_WAVYLINE,
OPT_STYLE_DASHBOX,
OPT_STYLE_FUZZY,
OPT_STYLE_HIGHLIGHT,
OPT_STYLE_BLOCKQUOTE,

View File

@@ -1,6 +1,6 @@
import {
OPT_DICT_BAIDU,
OPT_SUG_BAIDU,
OPT_DICT_BING,
OPT_SUG_YOUDAO,
DEFAULT_HTTP_TIMEOUT,
OPT_TRANS_MICROSOFT,
DEFAULT_API_LIST,
@@ -91,8 +91,8 @@ export const DEFAULT_TRANBOX_SETTING = {
followSelection: false, // 翻译框是否跟随选中文本
triggerMode: OPT_TRANBOX_TRIGGER_CLICK, // 触发翻译方式
// extStyles: "", // 附加样式
enDict: OPT_DICT_BAIDU, // 英文词典
enSug: OPT_SUG_BAIDU, // 英文建议
enDict: OPT_DICT_BING, // 英文词典
enSug: OPT_SUG_YOUDAO, // 英文建议
};
// 订阅列表