Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7eb64a463b | ||
|
|
8971a28abc | ||
|
|
2ff989429f | ||
|
|
24369e2581 | ||
|
|
2bb8a5182c | ||
|
|
629bf9461a |
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=2.0.6
|
REACT_APP_VERSION=2.0.7
|
||||||
|
|
||||||
REACT_APP_HOMEPAGE=https://github.com/fishjar/kiss-translator
|
REACT_APP_HOMEPAGE=https://github.com/fishjar/kiss-translator
|
||||||
|
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ async (args) => {
|
|||||||
{
|
{
|
||||||
role: "user",
|
role: "user",
|
||||||
content: JSON.stringify({
|
content: JSON.stringify({
|
||||||
targetLanguage: args.to,
|
targetLanguage: args.toLang,
|
||||||
segments: args.texts.map((text, id) => ({ id, text })),
|
segments: args.texts.map((text, id) => ({ id, text })),
|
||||||
glossary: {},
|
glossary: {},
|
||||||
}),
|
}),
|
||||||
@@ -132,7 +132,7 @@ async (args) => {
|
|||||||
{
|
{
|
||||||
role: "user",
|
role: "user",
|
||||||
content: JSON.stringify({
|
content: JSON.stringify({
|
||||||
targetLanguage: args.to,
|
targetLanguage: args.toLang,
|
||||||
segments: args.texts.map((text, id) => ({ id, text })),
|
segments: args.texts.map((text, id) => ({ id, text })),
|
||||||
glossary: {},
|
glossary: {},
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -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": "2.0.6",
|
"version": "2.0.7",
|
||||||
"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": "2.0.6",
|
"version": "2.0.7",
|
||||||
"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": "2.0.6",
|
"version": "2.0.7",
|
||||||
"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": 2,
|
"manifest_version": 2,
|
||||||
"name": "__MSG_app_name__",
|
"name": "__MSG_app_name__",
|
||||||
"description": "__MSG_app_description__",
|
"description": "__MSG_app_description__",
|
||||||
"version": "2.0.6",
|
"version": "2.0.7",
|
||||||
"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",
|
||||||
|
|||||||
@@ -74,12 +74,13 @@ const genUserPrompt = ({
|
|||||||
glossary = {},
|
glossary = {},
|
||||||
from,
|
from,
|
||||||
to,
|
to,
|
||||||
|
toLang,
|
||||||
texts,
|
texts,
|
||||||
docInfo,
|
docInfo,
|
||||||
}) => {
|
}) => {
|
||||||
if (useBatchFetch) {
|
if (useBatchFetch) {
|
||||||
return JSON.stringify({
|
return JSON.stringify({
|
||||||
targetLanguage: to,
|
targetLanguage: toLang,
|
||||||
title: docInfo.title,
|
title: docInfo.title,
|
||||||
description: docInfo.description,
|
description: docInfo.description,
|
||||||
segments: texts.map((text, i) => ({ id: i, text })),
|
segments: texts.map((text, i) => ({ id: i, text })),
|
||||||
@@ -557,8 +558,8 @@ const genCloudflareAI = ({ texts, from, to, url, key }) => {
|
|||||||
return { url, body, headers };
|
return { url, body, headers };
|
||||||
};
|
};
|
||||||
|
|
||||||
const genCustom = ({ texts, from, to, url, key }) => {
|
const genCustom = ({ texts, fromLang, toLang, url, key }) => {
|
||||||
const body = { texts, from, to };
|
const body = { texts, from: fromLang, to: toLang };
|
||||||
const headers = {
|
const headers = {
|
||||||
"Content-type": "application/json",
|
"Content-type": "application/json",
|
||||||
Authorization: `Bearer ${key}`,
|
Authorization: `Bearer ${key}`,
|
||||||
@@ -638,6 +639,8 @@ export const genTransReq = async ({ reqHook, ...args }) => {
|
|||||||
useBatchFetch,
|
useBatchFetch,
|
||||||
from,
|
from,
|
||||||
to,
|
to,
|
||||||
|
fromLang,
|
||||||
|
toLang,
|
||||||
texts,
|
texts,
|
||||||
docInfo,
|
docInfo,
|
||||||
glossary,
|
glossary,
|
||||||
@@ -667,6 +670,8 @@ export const genTransReq = async ({ reqHook, ...args }) => {
|
|||||||
useBatchFetch,
|
useBatchFetch,
|
||||||
from,
|
from,
|
||||||
to,
|
to,
|
||||||
|
fromLang,
|
||||||
|
toLang,
|
||||||
texts,
|
texts,
|
||||||
docInfo,
|
docInfo,
|
||||||
glossary,
|
glossary,
|
||||||
|
|||||||
@@ -118,6 +118,13 @@ async function getFavWords(rule) {
|
|||||||
*/
|
*/
|
||||||
export async function run(isUserscript = false) {
|
export async function run(isUserscript = false) {
|
||||||
try {
|
try {
|
||||||
|
// if (document?.documentElement?.tagName?.toUpperCase() !== "HTML") {
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
if (!document?.contentType?.includes("html")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// 读取设置信息
|
// 读取设置信息
|
||||||
const setting = await getSettingWithDefault();
|
const setting = await getSettingWithDefault();
|
||||||
|
|
||||||
|
|||||||
@@ -312,14 +312,14 @@ export const OPT_LANGS_TO_SPEC = {
|
|||||||
["id", "id"],
|
["id", "id"],
|
||||||
["vi", "vi"],
|
["vi", "vi"],
|
||||||
]),
|
]),
|
||||||
[OPT_TRANS_OPENAI]: OPT_LANGS_SPEC_DEFAULT,
|
[OPT_TRANS_OPENAI]: OPT_LANGS_SPEC_NAME,
|
||||||
[OPT_TRANS_GEMINI]: OPT_LANGS_SPEC_DEFAULT,
|
[OPT_TRANS_GEMINI]: OPT_LANGS_SPEC_NAME,
|
||||||
[OPT_TRANS_GEMINI_2]: OPT_LANGS_SPEC_DEFAULT,
|
[OPT_TRANS_GEMINI_2]: OPT_LANGS_SPEC_NAME,
|
||||||
[OPT_TRANS_CLAUDE]: OPT_LANGS_SPEC_DEFAULT,
|
[OPT_TRANS_CLAUDE]: OPT_LANGS_SPEC_NAME,
|
||||||
[OPT_TRANS_OLLAMA]: OPT_LANGS_SPEC_DEFAULT,
|
[OPT_TRANS_OLLAMA]: OPT_LANGS_SPEC_NAME,
|
||||||
[OPT_TRANS_OPENROUTER]: OPT_LANGS_SPEC_DEFAULT,
|
[OPT_TRANS_OPENROUTER]: OPT_LANGS_SPEC_NAME,
|
||||||
[OPT_TRANS_CLOUDFLAREAI]: OPT_LANGS_SPEC_DEFAULT,
|
[OPT_TRANS_CLOUDFLAREAI]: OPT_LANGS_SPEC_NAME,
|
||||||
[OPT_TRANS_CUSTOMIZE]: OPT_LANGS_SPEC_DEFAULT,
|
[OPT_TRANS_CUSTOMIZE]: OPT_LANGS_SPEC_NAME,
|
||||||
};
|
};
|
||||||
|
|
||||||
const specToCode = (m) =>
|
const specToCode = (m) =>
|
||||||
@@ -342,7 +342,7 @@ Object.entries(OPT_LANGS_TO_SPEC).forEach(([t, m]) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
export const defaultNobatchPrompt = `You are a professional, authentic machine translation engine.`;
|
export const defaultNobatchPrompt = `You are a professional, authentic machine translation engine.`;
|
||||||
export const defaultNobatchUserPrompt = `Translate the following source text from ${INPUT_PLACE_FROM} to ${INPUT_PLACE_TO}. Output translation directly without any additional text.\n\nSource Text: ${INPUT_PLACE_TEXT}\n\nTranslated Text:`;
|
export const defaultNobatchUserPrompt = `Translate the following source text to ${INPUT_PLACE_TO}. Output translation directly without any additional text.\n\nSource Text: ${INPUT_PLACE_TEXT}\n\nTranslated Text:`;
|
||||||
|
|
||||||
export const defaultSystemPrompt = `Act as a translation API. Output a single raw JSON object only. No extra text or fences.
|
export const defaultSystemPrompt = `Act as a translation API. Output a single raw JSON object only. No extra text or fences.
|
||||||
|
|
||||||
|
|||||||
@@ -1069,9 +1069,9 @@ export const I18N = {
|
|||||||
zh_TW: `隱藏`,
|
zh_TW: `隱藏`,
|
||||||
},
|
},
|
||||||
save_rule: {
|
save_rule: {
|
||||||
zh: `保存规则`,
|
zh: `保存本站规则`,
|
||||||
en: `Save Rule`,
|
en: `Save this site rule`,
|
||||||
zh_TW: `儲存規則`,
|
zh_TW: `保存本站規則`,
|
||||||
},
|
},
|
||||||
global_rule: {
|
global_rule: {
|
||||||
zh: `全局规则`,
|
zh: `全局规则`,
|
||||||
@@ -1660,7 +1660,7 @@ export const I18N = {
|
|||||||
},
|
},
|
||||||
subtitle_translate: {
|
subtitle_translate: {
|
||||||
zh: `字幕翻译`,
|
zh: `字幕翻译`,
|
||||||
en: `Subtitle translation`,
|
en: `Subtitle Translation`,
|
||||||
zh_TW: `字幕翻譯`,
|
zh_TW: `字幕翻譯`,
|
||||||
},
|
},
|
||||||
toggle_subtitle_translate: {
|
toggle_subtitle_translate: {
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
import { run } from "./common";
|
import { run } from "./common";
|
||||||
|
|
||||||
if (document.documentElement && document.documentElement.tagName === "HTML") {
|
|
||||||
run();
|
run();
|
||||||
}
|
|
||||||
|
|||||||
@@ -27,6 +27,14 @@ export default function Theme({ children, options = {}, styles = {} }) {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const theme = useMemo(() => {
|
const theme = useMemo(() => {
|
||||||
|
let htmlFontSize = 16;
|
||||||
|
try {
|
||||||
|
const s = window.getComputedStyle(document.documentElement).fontSize;
|
||||||
|
htmlFontSize = parseInt(s.replace("px", ""));
|
||||||
|
} catch (err) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
const isDarkMode =
|
const isDarkMode =
|
||||||
darkMode === "dark" || (darkMode === "auto" && systemMode === THEME_DARK);
|
darkMode === "dark" || (darkMode === "auto" && systemMode === THEME_DARK);
|
||||||
|
|
||||||
@@ -35,7 +43,7 @@ export default function Theme({ children, options = {}, styles = {} }) {
|
|||||||
mode: isDarkMode ? THEME_DARK : THEME_LIGHT,
|
mode: isDarkMode ? THEME_DARK : THEME_LIGHT,
|
||||||
},
|
},
|
||||||
typography: {
|
typography: {
|
||||||
htmlFontSize: document.documentElement.style.fontSize ? "16px" : 16,
|
htmlFontSize,
|
||||||
},
|
},
|
||||||
...options,
|
...options,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1322,7 +1322,10 @@ export class Translator {
|
|||||||
// node.matches(this.#ignoreSelector) ||
|
// node.matches(this.#ignoreSelector) ||
|
||||||
!node.textContent.trim()
|
!node.textContent.trim()
|
||||||
) {
|
) {
|
||||||
if (node.tagName === "IMG" || node.tagName === "SVG") {
|
if (
|
||||||
|
node.tagName?.toUpperCase() === "IMG" ||
|
||||||
|
node.tagName?.toUpperCase() === "SVG"
|
||||||
|
) {
|
||||||
node.style.width = `${node.offsetWidth}px`;
|
node.style.width = `${node.offsetWidth}px`;
|
||||||
node.style.height = `${node.offsetHeight}px`;
|
node.style.height = `${node.offsetHeight}px`;
|
||||||
}
|
}
|
||||||
@@ -1336,7 +1339,7 @@ export class Translator {
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
this.#rule.hasRichText === "true" &&
|
this.#rule.hasRichText === "true" &&
|
||||||
Translator.TAGS.WARP.has(node.tagName)
|
Translator.TAGS.WARP.has(node.tagName?.toUpperCase())
|
||||||
) {
|
) {
|
||||||
wrapCounter++;
|
wrapCounter++;
|
||||||
const startPlaceholder = `<${this.#placeholder.tagName}${wrapCounter}>`;
|
const startPlaceholder = `<${this.#placeholder.tagName}${wrapCounter}>`;
|
||||||
|
|||||||
Reference in New Issue
Block a user