mihomo(Clash Verge) 节点筛选脚本

前言

  • 节点数量过多, 导致软件开启会卡几秒, 因此做了个筛选脚本

使用方法

  • 打开 Clash Verge
  • 侧边栏选择 订阅
  • 找到需要筛选的节点右键选择 扩展脚本
  • 把脚本复制进去, 按需修改变量, 保存

脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
* Clash 配置文件预处理脚本
*
* @param {Object} config - 原始配置对象
* @param {string} profileName - 配置文件名称
* @returns {Object} 处理后的配置对象
*/
function main(config, profileName) {
const BUILTIN_IN_GROUP = new Set(["DIRECT", "REJECT", "REJECT-DROP", "PASS", "COMPATIBLE"]);

// 任一项设为 null / undefined / '' 即关闭;关闭 include = 全保留,关闭 exclude = 不排除
const includeFilters = /SG|JP|HK|3x US/i;
const excludeFilters = /5x|10x/i;

function toRegExp(pattern) {
if (pattern == null || pattern === "") return null;
if (pattern instanceof RegExp) return pattern;
try {
return new RegExp(String(pattern));
} catch {
return null;
}
}

/** @param {RegExp | string | null | undefined} pattern */
function passesInclude(name, pattern) {
const re = toRegExp(pattern);
if (!re || re.source === "") return true;
try {
return re.test(name);
} catch {
return true;
}
}

/** @param {RegExp | string | null | undefined} pattern */
function hitsExclude(name, pattern) {
const re = toRegExp(pattern);
if (!re || re.source === "") return false;
try {
return re.test(name);
} catch {
return false;
}
}

const filteredProxies = config.proxies.filter((proxy) => {
return passesInclude(proxy.name, includeFilters) && !hitsExclude(proxy.name, excludeFilters);
});

const filteredProxyNames = new Set(filteredProxies.map((p) => p.name));

config.proxies = filteredProxies;

if (config["proxy-groups"]) {
const groupNames = new Set(config["proxy-groups"].map((g) => g.name));

config["proxy-groups"].forEach((group) => {
if (group.proxies) {
group.proxies = group.proxies.filter((pName) => {
if (BUILTIN_IN_GROUP.has(pName)) return true;
const isAnotherGroup = groupNames.has(pName);
const isExistingProxy = filteredProxyNames.has(pName);
return isAnotherGroup || isExistingProxy;
});

if (group.proxies.length === 0) {
group.proxies.push("DIRECT");
}
}
});
}

return config;
}

mihomo(Clash Verge) 节点筛选脚本
http://pure-white-ice-cream.github.io/2026/05/15/mihomo-Clash-Verge-节点筛选脚本/
作者
纯白色冰淇淋
发布于
2026年5月15日
许可协议