Skip to content

Commit 3e5d27d

Browse files
authored
Merge pull request cmliu#884 from cmliu/beta2.0
fix: 优化批量替换域名函数,随机化主机选择以提高多样性
2 parents f53dbb6 + e0fe2ce commit 3e5d27d

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

_worker.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -871,9 +871,10 @@ function 随机替换通配符(h) {
871871
}
872872

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

0 commit comments

Comments
 (0)