fix: 优化批量替换域名函数,随机化主机选择以提高多样性

This commit is contained in:
cmliu
2025-12-18 19:41:19 +08:00
parent 48611baed0
commit e0fe2ce3cf

View File

@@ -870,9 +870,10 @@ function 随机替换通配符(h) {
}
function 批量替换域名(内容, hosts, 每组数量 = 2) {
const 打乱后数组 = [...hosts].sort(() => Math.random() - 0.5);
let count = 0, currentRandomHost = null;
return 内容.replace(/example\.com/g, () => {
if (count % 每组数量 === 0) currentRandomHost = 随机替换通配符(hosts[Math.floor(Math.random() * hosts.length)]);
if (count % 每组数量 === 0) currentRandomHost = 随机替换通配符(打乱后数组[count % 打乱后数组.length]);
count++;
return currentRandomHost;
});