Skip to content

Commit 54705cd

Browse files
committed
fix: 优化优选订阅生成器URL构建逻辑,修正UUID格式并添加批量替换域名功能
1 parent d96bbaf commit 54705cd

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

_worker.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ export default {
267267
} else { // 优选订阅生成器
268268
let 优选订阅生成器HOST = url.searchParams.get('sub') || config_JSON.优选订阅生成.SUB;
269269
优选订阅生成器HOST = 优选订阅生成器HOST && !/^https?:\/\//i.test(优选订阅生成器HOST) ? `https://${优选订阅生成器HOST}` : 优选订阅生成器HOST;
270-
const 优选订阅生成器URL = `${优选订阅生成器HOST}/sub?host=example.com&${协议类型 === ('v' + 'le' + 'ss') ? 'uuid' : 'pw'}=00000000-0000-4000-0000-000000000000&path=${encodeURIComponent(config_JSON.随机路径 ? 随机路径() + 节点路径 : 节点路径) + TLS分片参数}&type=${config_JSON.传输协议}`;
270+
const 优选订阅生成器URL = `${优选订阅生成器HOST}/sub?host=example.com&${协议类型 === ('v' + 'le' + 'ss') ? 'uuid' : 'pw'}=00000000-0000-4000-8000-000000000000&path=${encodeURIComponent(config_JSON.随机路径 ? 随机路径() + 节点路径 : 节点路径) + TLS分片参数}&type=${config_JSON.传输协议}`;
271271
try {
272272
const response = await fetch(优选订阅生成器URL, { headers: { 'User-Agent': 'v2rayN/edge' + 'tunnel (https://github.com/cmliu/edge' + 'tunnel)' } });
273273
if (response.ok) 订阅内容 = btoa(其他节点LINK + atob(await response.text()));
@@ -289,9 +289,9 @@ export default {
289289
}
290290
}
291291
if (订阅类型 === 'mixed') {
292-
订阅内容 = atob(订阅内容).replace(/example.com/g, config_JSON.HOST).replace(/00000000-0000-4000-0000-000000000000/g, config_JSON.UUID);
292+
订阅内容 = 批量替换域名(atob(订阅内容).replace(/00000000-0000-4000-8000-000000000000/g, config_JSON.UUID), host);
293293
if (!ua.includes('mozilla')) 订阅内容 = btoa(订阅内容);
294-
} else 订阅内容 = 订阅内容.replace(/example.com/g, config_JSON.HOST).replace(/00000000-0000-4000-0000-000000000000/g, config_JSON.UUID);
294+
} else 订阅内容 = 批量替换域名(订阅内容.replace(/00000000-0000-4000-8000-000000000000/g, config_JSON.UUID), host);
295295
if (订阅类型 === 'singbox') {
296296
订阅内容 = JSON.stringify(JSON.parse(订阅内容), null, 2);
297297
responseHeaders["content-type"] = 'application/json; charset=utf-8';
@@ -835,6 +835,15 @@ function 随机替换通配符(h) {
835835
});
836836
}
837837

838+
function 批量替换域名(内容, host, 每组数量 = 2) {
839+
let count = 0, currentRandomHost = null;
840+
return 内容.replace(/example\.com/g, () => {
841+
if (count % 每组数量 === 0) currentRandomHost = 随机替换通配符(host);
842+
count++;
843+
return currentRandomHost;
844+
});
845+
}
846+
838847
async function 读取config_JSON(env, hostname, userID, 重置配置 = false) {
839848
const host = 随机替换通配符(hostname);
840849
const 初始化开始时间 = performance.now();

0 commit comments

Comments
 (0)