From 1d924219600c723abecfd9c599fa77e0f59408f9 Mon Sep 17 00:00:00 2001 From: mcz Date: Tue, 29 Apr 2025 19:49:14 +0800 Subject: [PATCH 1/3] Remove the tags in qwen3 too. --- src/apis/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/apis/index.js b/src/apis/index.js index ed222fa..a35e726 100644 --- a/src/apis/index.js +++ b/src/apis/index.js @@ -323,7 +323,8 @@ export const apiTranslate = async ({ case OPT_TRANS_OLLAMA: case OPT_TRANS_OLLAMA_2: case OPT_TRANS_OLLAMA_3: - if (res?.model.startsWith('deepseek-r1')) { + const deepModels = ['deepseek-r1', 'qwen3']; + if (deepModels.some(model => res?.model?.startsWith(model))) { trText = res?.response.replace(/[\s\S]*<\/think>/i, ''); }else{ trText = res?.response; From 7a772d2459d43da130f33f00cba48aad22e321fc Mon Sep 17 00:00:00 2001 From: mcz Date: Thu, 1 May 2025 20:04:58 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=9C=A8=E5=9F=BA=E6=9C=AC=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E9=A1=B5=E9=9D=A2=E5=A2=9E=E5=8A=A0=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E8=B6=85=E6=97=B6=E6=97=B6=E9=97=B4=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config/i18n.js | 4 ++++ src/config/index.js | 2 ++ src/libs/fetch.js | 15 ++++++++++++--- src/views/Options/Setting.js | 14 +++++++++++++- 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/config/i18n.js b/src/config/i18n.js index 03ba335..908e9e0 100644 --- a/src/config/i18n.js +++ b/src/config/i18n.js @@ -194,6 +194,10 @@ export const I18N = { zh: `重新翻译间隔时间 (100-5000ms)`, en: `Retranslation Interval (100-5000ms)`, }, + http_timeout: { + zh: `请求超时时间 (5000-30000ms)`, + en: `Request Timeout Time (5000-30000ms)`, + }, min_translate_length: { zh: `最小翻译字符数 (1-100)`, en: `Minimum number Of Translated Characters (1-100)`, diff --git a/src/config/index.js b/src/config/index.js index 11bbf36..2d65bef 100644 --- a/src/config/index.js +++ b/src/config/index.js @@ -641,6 +641,7 @@ export const DEFAULT_SHORTCUTS = { export const TRANS_MIN_LENGTH = 5; // 最短翻译长度 export const TRANS_MAX_LENGTH = 5000; // 最长翻译长度 export const TRANS_NEWLINE_LENGTH = 20; // 换行字符数 +export const HTTP_TIMEOUT = 5000; // 调用超时时间 export const DEFAULT_BLACKLIST = [ "https://fishjar.github.io/kiss-translator/options.html", "https://translate.google.com", @@ -658,6 +659,7 @@ export const DEFAULT_SETTING = { minLength: TRANS_MIN_LENGTH, maxLength: TRANS_MAX_LENGTH, newlineLength: TRANS_NEWLINE_LENGTH, + httpTimeout: HTTP_TIMEOUT, clearCache: false, // 是否在浏览器下次启动时清除缓存 injectRules: true, // 是否注入订阅规则 // injectWebfix: true, // 是否注入修复补丁(作废) diff --git a/src/libs/fetch.js b/src/libs/fetch.js index f2227a8..e5b5b83 100644 --- a/src/libs/fetch.js +++ b/src/libs/fetch.js @@ -1,19 +1,23 @@ import { isExt, isGm } from "./client"; import { sendBgMsg } from "./msg"; import { taskPool } from "./pool"; +import { storage,getSettingWithDefault } from "./storage"; + + import { MSG_FETCH, MSG_GET_HTTPCACHE, CACHE_NAME, DEFAULT_FETCH_INTERVAL, DEFAULT_FETCH_LIMIT, + HTTP_TIMEOUT, } from "../config"; import { isBg } from "./browser"; import { genTransReq } from "../apis/trans"; import { kissLog } from "./log"; import { blobToBase64 } from "./utils"; -const TIMEOUT = 5000; +let TIMEOUT = HTTP_TIMEOUT; /** * 构造缓存 request @@ -39,7 +43,8 @@ const newCacheReq = async (input, init) => { * @param {*} init * @returns */ -export const fetchGM = async (input, { method = "GET", headers, body } = {}) => +export const fetchGM = async (input, { method = "GET", headers, body } = {}) =>{ + TIMEOUT = (await getSettingWithDefault()).httpTimeout; new Promise((resolve, reject) => { GM.xmlHttpRequest({ method, @@ -66,7 +71,7 @@ export const fetchGM = async (input, { method = "GET", headers, body } = {}) => onerror: reject, }); }); - +} /** * 发起请求 * @param {*} param0 @@ -108,6 +113,10 @@ export const fetchPatcher = async (input, init, transOpts, apiSetting) => { } } + //const kiss_setting = await storage.get("KISS-Translator_setting"); + //TIMEOUT = JSON.parse(kiss_setting)?.httpTimeout || TIMEOUT; + TIMEOUT = (await getSettingWithDefault()).httpTimeout; + console.log("TIMEOUT", TIMEOUT); if (AbortSignal?.timeout && !init.signal) { Object.assign(init, { signal: AbortSignal.timeout(TIMEOUT) }); } diff --git a/src/views/Options/Setting.js b/src/views/Options/Setting.js index b916e4c..440f405 100644 --- a/src/views/Options/Setting.js +++ b/src/views/Options/Setting.js @@ -27,6 +27,7 @@ import { DEFAULT_CSPLIST, MSG_CONTEXT_MENUS, MSG_UPDATE_CSP, + HTTP_TIMEOUT, } from "../../config"; import { useShortcut } from "../../hooks/Shortcut"; import ShortcutInput from "./ShortcutInput"; @@ -71,6 +72,9 @@ export default function Settings() { case "newlineLength": value = limitNumber(value, 1, 1000); break; + case "httpTimeout": + value = limitNumber(value, 5000, 30000); + break; case "touchTranslate": value = limitNumber(value, 0, 4); break; @@ -110,6 +114,7 @@ export default function Settings() { maxLength, clearCache, newlineLength = TRANS_NEWLINE_LENGTH, + httpTimeout = HTTP_TIMEOUT, contextMenuType = 1, touchTranslate = 2, blacklist = DEFAULT_BLACKLIST.join(",\n"), @@ -188,7 +193,14 @@ export default function Settings() { defaultValue={transInterval} onChange={handleChange} /> - + {i18n("touch_translate_shortcut")}