From 8cf0aab2b2de72092c9845dd9ab8686b66413506 Mon Sep 17 00:00:00 2001 From: jjaw Date: Mon, 17 Jun 2024 19:26:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=8Fbug=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/proxy/bingPorxyWorker.ts | 68 +++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 32 deletions(-) diff --git a/src/proxy/bingPorxyWorker.ts b/src/proxy/bingPorxyWorker.ts index 8719f6b..64ae801 100644 --- a/src/proxy/bingPorxyWorker.ts +++ b/src/proxy/bingPorxyWorker.ts @@ -283,39 +283,43 @@ const bingProxyLink = newProxyLinkHttp({ {//txt文本替换 const resHeaders = config.init.headers as Headers; const contentType = res.headers.get("Content-Type"); - if (!contentType || (!contentType.startsWith("text/") && !contentType.startsWith("application/javascript") && !contentType.startsWith("application/json"))) { - return config; - } - resHeaders.delete("Content-Md5"); - let retBody = await res.text(); - const resUrl = new URL(res.url); - - retBody = retBody.replace(/https?:\/\/sydney\.bing\.com(:[0-9]{1,6})?/g, `${reqUrl.origin}`); - retBody = retBody.replace(/https?:\/\/login\.live\.com(:[0-9]{1,6})?/g, `${reqUrl.origin}`); - retBody = retBody.replace(/https?:\/\/account\.live\.com(:[0-9]{1,6})?/g, `${reqUrl.origin}`); - retBody = retBody.replace(/https?:\/\/copilot\.microsoft\.com(:[0-9]{1,6})?/g, `${reqUrl.origin}`); - retBody = retBody.replace(/https?:\/\/www\.bing\.com(:[0-9]{1,6})?/g, `${reqUrl.origin}`); - retBody = retBody.replace(/https?:\/\/storage\.live\.com(:[0-9]{1,6})?/g, `${reqUrl.origin}`); - - //特定页面注入脚本 - if (resUrl.pathname == "/") { - retBody = injectionHtmlToHead(retBody, CopilotInjection); - } - //音乐页面脚本注入 - if (resUrl.pathname == "/videos/music") { - retBody = injectionHtmlToHead(retBody, MusicInJection); - } - //图片生成注入 - if ( - resUrl.pathname == "/images/create" || - (resUrl.pathname.startsWith("/images/create/") && !resUrl.pathname.startsWith("/images/create/async/")) - ) { - retBody = injectionHtmlToHead(retBody, ImagesCreateInJection); - } - if (resUrl.pathname == "/login.srf") { - retBody = injectionHtmlToBody(retBody, LoginInJectionBody); + if( contentType && ( + contentType.startsWith("text/") || + contentType.startsWith("application/javascript") || + contentType.startsWith("application/json") + ) + ){ + resHeaders.delete("Content-Md5"); + let retBody = await res.text(); + const resUrl = new URL(res.url); + + retBody = retBody.replace(/https?:\/\/sydney\.bing\.com(:[0-9]{1,6})?/g, `${reqUrl.origin}`); + retBody = retBody.replace(/https?:\/\/login\.live\.com(:[0-9]{1,6})?/g, `${reqUrl.origin}`); + retBody = retBody.replace(/https?:\/\/account\.live\.com(:[0-9]{1,6})?/g, `${reqUrl.origin}`); + retBody = retBody.replace(/https?:\/\/copilot\.microsoft\.com(:[0-9]{1,6})?/g, `${reqUrl.origin}`); + retBody = retBody.replace(/https?:\/\/www\.bing\.com(:[0-9]{1,6})?/g, `${reqUrl.origin}`); + retBody = retBody.replace(/https?:\/\/storage\.live\.com(:[0-9]{1,6})?/g, `${reqUrl.origin}`); + + //特定页面注入脚本 + if (resUrl.pathname == "/") { + retBody = injectionHtmlToHead(retBody, CopilotInjection); + } + //音乐页面脚本注入 + if (resUrl.pathname == "/videos/music") { + retBody = injectionHtmlToHead(retBody, MusicInJection); + } + //图片生成注入 + if ( + resUrl.pathname == "/images/create" || + (resUrl.pathname.startsWith("/images/create/") && !resUrl.pathname.startsWith("/images/create/async/")) + ) { + retBody = injectionHtmlToHead(retBody, ImagesCreateInJection); + } + if (resUrl.pathname == "/login.srf") { + retBody = injectionHtmlToBody(retBody, LoginInJectionBody); + } + config.body = retBody; } - config.body = retBody; } //重定向转换