From 06dd74f1954adcdfb0ff0804a4c261485ed03bb9 Mon Sep 17 00:00:00 2001 From: cmliu Date: Fri, 16 Jan 2026 04:47:24 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=9B=B4=E6=96=B0Clash=E8=AE=A2?= =?UTF-8?q?=E9=98=85=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E7=83=AD=E8=A1=A5?= =?UTF-8?q?=E4=B8=81=EF=BC=8C=E7=AE=80=E5=8C=96ECH=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E5=B9=B6=E4=BC=98=E5=8C=96=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _worker.js | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/_worker.js b/_worker.js index e3e508f..4b3dc17 100644 --- a/_worker.js +++ b/_worker.js @@ -324,7 +324,7 @@ export default { 订阅内容 = Singbox订阅配置文件热补丁(订阅内容, config_JSON.UUID, config_JSON.Fingerprint, config_JSON.ECH ? await getECH(host) : null); responseHeaders["content-type"] = 'application/json; charset=utf-8'; } else if (订阅类型 === 'clash') { - 订阅内容 = Clash订阅配置文件热补丁(订阅内容, config_JSON.UUID, config_JSON.ECH ? await getECH(host) : null); + 订阅内容 = Clash订阅配置文件热补丁(订阅内容, config_JSON.UUID, config_JSON.ECH); responseHeaders["content-type"] = 'application/x-yaml; charset=utf-8'; } return new Response(订阅内容, { status: 200, headers: responseHeaders }); @@ -785,15 +785,32 @@ async function httpConnect(targetHost, targetPort, initialData) { } } //////////////////////////////////////////////////功能性函数/////////////////////////////////////////////// -function Clash订阅配置文件热补丁(clash_yaml, uuid = null, ech_config = null) { - // 判断uuid字段是否为真 - if (!uuid) { - return clash_yaml; - } - - // 如果ech_config为null,直接返回 - if (!ech_config) return clash_yaml; +function Clash订阅配置文件热补丁(Clash_原始订阅内容, uuid = null, ECH启用 = false) { + const clash_yaml = `dns: + enable: true + default-nameserver: + - 223.5.5.5 + - 119.29.29.29 + - 114.114.114.114 + use-hosts: true + nameserver: + - https://sm2.doh.pub/dns-query + - https://dns.alidns.com/dns-query + fallback: + - 'https://dns.google/dns-query' + - 'https://1.1.1.1/dns-query' + fallback-filter: + geoip: true + ipcidr: + - 240.0.0.0/4 + - 0.0.0.0/32 + geoip-code: CN + proxy-server-nameserver: + - https://doh.cmliussss.com/CMLiussss + - https://doh.cmliussss.net/CMLiussss +` + Clash_原始订阅内容; + if (!uuid || !ECH启用) return clash_yaml; const lines = clash_yaml.split('\n'); const processedLines = []; let i = 0; @@ -830,7 +847,7 @@ function Clash订阅配置文件热补丁(clash_yaml, uuid = null, ech_config = if (credentialMatch && credentialMatch[1].trim() === uuid.trim()) { // 在最后一个}前添加ech-opts - fullNode = fullNode.replace(/\}(\s*)$/, `, ech-opts: {enable: true, config: "${ech_config}"}}$1`); + fullNode = fullNode.replace(/\}(\s*)$/, `, ech-opts: {enable: true}}$1`); } processedLines.push(fullNode); @@ -905,8 +922,7 @@ function Clash订阅配置文件热补丁(clash_yaml, uuid = null, ech_config = // 在节点末尾(最后一个属性块之后)插入 ech-opts 属性 nodeLines.splice(insertIndex + 1, 0, `${indent}ech-opts:`, - `${indent} enable: true`, - `${indent} config: "${ech_config}"` + `${indent} enable: true` ); } }