From 579d5cb0a33aa09f71109b805cbf360ce63ae5bd Mon Sep 17 00:00:00 2001 From: Gabe Date: Tue, 1 Jul 2025 17:55:57 +0800 Subject: [PATCH] fix: update userscript --- config-overrides.js | 8 ++----- src/libs/fetch.js | 55 ++++++++++++++++++++++++++++----------------- 2 files changed, 36 insertions(+), 27 deletions(-) diff --git a/config-overrides.js b/config-overrides.js index 654e556..ea3478d 100644 --- a/config-overrides.js +++ b/config-overrides.js @@ -111,12 +111,8 @@ const userscriptWebpack = (config, env) => { // @connect transmart.qq.com // @connect niutrans.com // @connect translate.volcengine.com -// @connect localhost:3000 -// @connect 127.0.0.1:3000 -// @connect localhost:1188 -// @connect 127.0.0.1:1188 -// @connect localhost:11434 -// @connect 127.0.0.1:11434 +// @connect localhost +// @connect 127.0.0.1 // @run-at document-end // ==/UserScript== diff --git a/src/libs/fetch.js b/src/libs/fetch.js index 67adcd5..27968db 100644 --- a/src/libs/fetch.js +++ b/src/libs/fetch.js @@ -95,33 +95,46 @@ export const fetchPatcher = async (input, init, transOpts, apiSetting) => { } if (isGm) { - let info; - if (window.KISS_GM) { - info = await window.KISS_GM.getInfo(); - } else { - info = GM.info; - } + // let info; + // if (window.KISS_GM) { + // info = await window.KISS_GM.getInfo(); + // } else { + // info = GM.info; + // } // Tampermonkey --> .connects // Violentmonkey --> .connect - const connects = info?.script?.connects || info?.script?.connect || []; - const url = new URL(input); - const isSafe = connects.find((item) => url.hostname.endsWith(item)); + // const connects = info?.script?.connects || info?.script?.connect || []; + // const url = new URL(input); + // const isSafe = connects.find((item) => url.hostname.endsWith(item)); - if (isSafe) { - // todo: 自定义接口 init 可能包含了 signal - Object.assign(init, { timeout }); + // if (isSafe) { + // // todo: 自定义接口 init 可能包含了 signal + // Object.assign(init, { timeout }); - const { body, headers, status, statusText } = window.KISS_GM - ? await window.KISS_GM.fetch(input, init) - : await fetchGM(input, init); + // const { body, headers, status, statusText } = window.KISS_GM + // ? await window.KISS_GM.fetch(input, init) + // : await fetchGM(input, init); - return new Response(body, { - headers: new Headers(headers), - status, - statusText, - }); - } + // return new Response(body, { + // headers: new Headers(headers), + // status, + // statusText, + // }); + // } + + // todo: 自定义接口 init 可能包含了 signal + Object.assign(init, { timeout }); + + const { body, headers, status, statusText } = window.KISS_GM + ? await window.KISS_GM.fetch(input, init) + : await fetchGM(input, init); + + return new Response(body, { + headers: new Headers(headers), + status, + statusText, + }); } if (AbortSignal?.timeout && !init.signal) {