Compare commits

...

6 Commits

Author SHA1 Message Date
Gabe
7eb64a463b Update version number: 2.0.7 2025-11-05 23:26:12 +08:00
Gabe
8971a28abc fix: html font size (#378) 2025-11-05 23:15:40 +08:00
Gabe
2ff989429f doc: i18n 2025-11-05 22:08:44 +08:00
Gabe
24369e2581 fix: Some element tagnames are lowercase. (#377) 2025-11-05 21:41:18 +08:00
Gabe
2bb8a5182c fix: Some element tagnames are lowercase. (#377) 2025-11-05 20:48:12 +08:00
Gabe
629bf9461a fix: AI language code 2025-11-05 01:03:44 +08:00
13 changed files with 50 additions and 29 deletions

2
.env
View File

@@ -2,7 +2,7 @@ GENERATE_SOURCEMAP=false
REACT_APP_NAME=KISS Translator
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

View File

@@ -99,7 +99,7 @@ async (args) => {
{
role: "user",
content: JSON.stringify({
targetLanguage: args.to,
targetLanguage: args.toLang,
segments: args.texts.map((text, id) => ({ id, text })),
glossary: {},
}),
@@ -132,7 +132,7 @@ async (args) => {
{
role: "user",
content: JSON.stringify({
targetLanguage: args.to,
targetLanguage: args.toLang,
segments: args.texts.map((text, id) => ({ id, text })),
glossary: {},
}),

View File

@@ -1,7 +1,7 @@
{
"name": "kiss-translator",
"description": "A minimalist bilingual translation Extension & Greasemonkey Script",
"version": "2.0.6",
"version": "2.0.7",
"author": "Gabe<yugang2002@gmail.com>",
"private": true,
"dependencies": {

View File

@@ -2,7 +2,7 @@
"manifest_version": 2,
"name": "__MSG_app_name__",
"description": "__MSG_app_description__",
"version": "2.0.6",
"version": "2.0.7",
"default_locale": "en",
"author": "Gabe<yugang2002@gmail.com>",
"homepage_url": "https://github.com/fishjar/kiss-translator",

View File

@@ -2,7 +2,7 @@
"manifest_version": 3,
"name": "__MSG_app_name__",
"description": "__MSG_app_description__",
"version": "2.0.6",
"version": "2.0.7",
"default_locale": "en",
"author": "Gabe<yugang2002@gmail.com>",
"homepage_url": "https://github.com/fishjar/kiss-translator",

View File

@@ -2,7 +2,7 @@
"manifest_version": 2,
"name": "__MSG_app_name__",
"description": "__MSG_app_description__",
"version": "2.0.6",
"version": "2.0.7",
"default_locale": "en",
"author": "Gabe<yugang2002@gmail.com>",
"homepage_url": "https://github.com/fishjar/kiss-translator",

View File

@@ -74,12 +74,13 @@ const genUserPrompt = ({
glossary = {},
from,
to,
toLang,
texts,
docInfo,
}) => {
if (useBatchFetch) {
return JSON.stringify({
targetLanguage: to,
targetLanguage: toLang,
title: docInfo.title,
description: docInfo.description,
segments: texts.map((text, i) => ({ id: i, text })),
@@ -557,8 +558,8 @@ const genCloudflareAI = ({ texts, from, to, url, key }) => {
return { url, body, headers };
};
const genCustom = ({ texts, from, to, url, key }) => {
const body = { texts, from, to };
const genCustom = ({ texts, fromLang, toLang, url, key }) => {
const body = { texts, from: fromLang, to: toLang };
const headers = {
"Content-type": "application/json",
Authorization: `Bearer ${key}`,
@@ -638,6 +639,8 @@ export const genTransReq = async ({ reqHook, ...args }) => {
useBatchFetch,
from,
to,
fromLang,
toLang,
texts,
docInfo,
glossary,
@@ -667,6 +670,8 @@ export const genTransReq = async ({ reqHook, ...args }) => {
useBatchFetch,
from,
to,
fromLang,
toLang,
texts,
docInfo,
glossary,

View File

@@ -118,6 +118,13 @@ async function getFavWords(rule) {
*/
export async function run(isUserscript = false) {
try {
// if (document?.documentElement?.tagName?.toUpperCase() !== "HTML") {
// return;
// }
if (!document?.contentType?.includes("html")) {
return;
}
// 读取设置信息
const setting = await getSettingWithDefault();

View File

@@ -312,14 +312,14 @@ export const OPT_LANGS_TO_SPEC = {
["id", "id"],
["vi", "vi"],
]),
[OPT_TRANS_OPENAI]: OPT_LANGS_SPEC_DEFAULT,
[OPT_TRANS_GEMINI]: OPT_LANGS_SPEC_DEFAULT,
[OPT_TRANS_GEMINI_2]: OPT_LANGS_SPEC_DEFAULT,
[OPT_TRANS_CLAUDE]: OPT_LANGS_SPEC_DEFAULT,
[OPT_TRANS_OLLAMA]: OPT_LANGS_SPEC_DEFAULT,
[OPT_TRANS_OPENROUTER]: OPT_LANGS_SPEC_DEFAULT,
[OPT_TRANS_CLOUDFLAREAI]: OPT_LANGS_SPEC_DEFAULT,
[OPT_TRANS_CUSTOMIZE]: OPT_LANGS_SPEC_DEFAULT,
[OPT_TRANS_OPENAI]: OPT_LANGS_SPEC_NAME,
[OPT_TRANS_GEMINI]: OPT_LANGS_SPEC_NAME,
[OPT_TRANS_GEMINI_2]: OPT_LANGS_SPEC_NAME,
[OPT_TRANS_CLAUDE]: OPT_LANGS_SPEC_NAME,
[OPT_TRANS_OLLAMA]: OPT_LANGS_SPEC_NAME,
[OPT_TRANS_OPENROUTER]: OPT_LANGS_SPEC_NAME,
[OPT_TRANS_CLOUDFLAREAI]: OPT_LANGS_SPEC_NAME,
[OPT_TRANS_CUSTOMIZE]: OPT_LANGS_SPEC_NAME,
};
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 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.

View File

@@ -1069,9 +1069,9 @@ export const I18N = {
zh_TW: `隱藏`,
},
save_rule: {
zh: `保存规则`,
en: `Save Rule`,
zh_TW: `儲存規則`,
zh: `保存本站规则`,
en: `Save this site rule`,
zh_TW: `保存本站規則`,
},
global_rule: {
zh: `全局规则`,
@@ -1660,7 +1660,7 @@ export const I18N = {
},
subtitle_translate: {
zh: `字幕翻译`,
en: `Subtitle translation`,
en: `Subtitle Translation`,
zh_TW: `字幕翻譯`,
},
toggle_subtitle_translate: {

View File

@@ -1,5 +1,3 @@
import { run } from "./common";
if (document.documentElement && document.documentElement.tagName === "HTML") {
run();
}
run();

View File

@@ -27,6 +27,14 @@ export default function Theme({ children, options = {}, styles = {} }) {
}, []);
const theme = useMemo(() => {
let htmlFontSize = 16;
try {
const s = window.getComputedStyle(document.documentElement).fontSize;
htmlFontSize = parseInt(s.replace("px", ""));
} catch (err) {
//
}
const isDarkMode =
darkMode === "dark" || (darkMode === "auto" && systemMode === THEME_DARK);
@@ -35,7 +43,7 @@ export default function Theme({ children, options = {}, styles = {} }) {
mode: isDarkMode ? THEME_DARK : THEME_LIGHT,
},
typography: {
htmlFontSize: document.documentElement.style.fontSize ? "16px" : 16,
htmlFontSize,
},
...options,
});

View File

@@ -1322,7 +1322,10 @@ export class Translator {
// node.matches(this.#ignoreSelector) ||
!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.height = `${node.offsetHeight}px`;
}
@@ -1336,7 +1339,7 @@ export class Translator {
if (
this.#rule.hasRichText === "true" &&
Translator.TAGS.WARP.has(node.tagName)
Translator.TAGS.WARP.has(node.tagName?.toUpperCase())
) {
wrapCounter++;
const startPlaceholder = `<${this.#placeholder.tagName}${wrapCounter}>`;