Skip to content

Commit 5410a6e

Browse files
authored
Update 明文源吗
1 parent 03a9888 commit 5410a6e

1 file changed

Lines changed: 12 additions & 21 deletions

File tree

明文源吗

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,40 +1340,31 @@
13401340
// 处理单行格式的节点: - {name: ..., server: ..., ...}
13411341
// 需要正确处理嵌套的花括号(如 ws-opts: {path: "...", headers: {Host: ...}})
13421342
clashConfig = clashConfig.split('\n').map(line => {
1343-
// 检查是否是节点行(以 " - {" 开头)
1344-
if (/^\s*-\s*\{/.test(line)) {
1343+
// 检查是否是节点行(以 " - {" 开头,且包含 name: 和 server:
1344+
if (/^\s*-\s*\{/.test(line) && line.includes('name:') && line.includes('server:')) {
13451345
// 检查是否已经有 ech-opts
13461346
if (line.includes('ech-opts')) {
13471347
return line; // 已有 ech-opts,不修改
13481348
}
13491349
// 找到最后一个 } 的位置(从右往左查找,处理嵌套花括号)
13501350
const lastBraceIndex = line.lastIndexOf('}');
13511351
if (lastBraceIndex > 0) {
1352-
// 在最后一个 } 之前添加 , ech-opts: {enable: true}
1353-
return line.substring(0, lastBraceIndex) + ', ech-opts: {enable: true}' + line.substring(lastBraceIndex);
1352+
// 检查最后一个 } 之前是否有内容,确保格式正确
1353+
const beforeBrace = line.substring(0, lastBraceIndex).trim();
1354+
if (beforeBrace.length > 0) {
1355+
// 在最后一个 } 之前添加 , ech-opts: {enable: true}
1356+
// 确保在逗号前有空格
1357+
const needsComma = !beforeBrace.endsWith(',') && !beforeBrace.endsWith('{');
1358+
return line.substring(0, lastBraceIndex) + (needsComma ? ', ' : ' ') + 'ech-opts: {enable: true}' + line.substring(lastBraceIndex);
1359+
}
13541360
}
13551361
}
13561362
return line;
13571363
}).join('\n');
13581364

13591365
// 处理多行格式的节点(如果存在)
1360-
// 匹配格式:
1361-
// - name: ...
1362-
// server: ...
1363-
// type: ...
1364-
// ...
1365-
clashConfig = clashConfig.replace(/^(\s*-\s*name:[^\n]*(?:\n\s+[^\n-]+)*)/gm, (match) => {
1366-
// 检查是否已经有 ech-opts
1367-
if (match.includes('ech-opts')) {
1368-
return match; // 已有 ech-opts,不修改
1369-
}
1370-
// 获取缩进级别(通常是 2 或 4 个空格)
1371-
const indentMatch = match.match(/^(\s*)/);
1372-
const baseIndent = indentMatch ? indentMatch[1] : ' ';
1373-
const propIndent = baseIndent + ' ';
1374-
// 在节点末尾添加 ech-opts
1375-
return match + '\n' + baseIndent + 'ech-opts:\n' + propIndent + 'enable: true';
1376-
});
1366+
// 只处理单行格式,多行格式由订阅转换服务处理,不需要额外修改
1367+
// 如果订阅转换服务返回多行格式,通常已经是正确的格式
13771368
}
13781369

13791370
// 替换 DNS nameserver 为阿里的加密 DNS

0 commit comments

Comments
 (0)