【科学上网】在Clash Verge中达成Clash for Windows的Parsers功能

写在前面

在 Clash for Windows 删库跑路后，Clash Verge 成为了大众的主流选择（不代表 Clash for Windows 不能用了，只是没有后续更新而已）。我在转到这个软件后，发现它居然没有 **Parsers 功能**，这让我感到十分遗憾。

于是我找到了一个解决方案，通过 Clash Verge 的配置文件，将类似 Parsers 功能添加到 Clash Verge 中。

配置文件（个人修改版，仅实现简单功能）

Script 部分

Copy
// Define the `main` function

// function main(params) {
// return params;
// }

// Define the `main` function

function main(params) {
// 所有地区
const allRegex = /自动|故障|流量|官网|套餐|机场|订阅/;
const allProxies = params.proxies
.filter((e) => !allRegex.test(e.name))
.map((e) => e.name);

// 节点选择
const Proxy = {
name: "Proxy",
type: "select",
proxies: allProxies.length > 0 ? allProxies : ["DIRECT"]
};
// 故障转移
const Speedtest = {
name: "Speedtest",
type: "select",
proxies: allProxies.length > 0 ? allProxies : ["DIRECT"]
};

const groups = params["proxy-groups"] = [];
// 规则
const rules = [
"AND,(AND,(DST-PORT,443),(NETWORK,UDP)),(NOT,((GEOIP,CN))),REJECT",// quic
// "GEOSITE,Category-ads-all,REJECT", // 可能导致某些网站无法访问
"GEOSITE,sogou,REJECT",
"GEOSITE,qihoo360,REJECT",
"DOMAIN,b23.tv,REJECT",
"DOMAIN-SUFFIX,db.laomoe.com,Speedtest",
"GEOSITE,speedtest,Speedtest",
"GEOSITE,category-scholar-!cn,Proxy",
"GEOSITE,youtube,Proxy",
"GEOSITE,google,Proxy",
"GEOSITE,bilibili@!cn,Proxy",
"GEOSITE,cn,DIRECT",
"GEOSITE,private,DIRECT",
"GEOSITE,steam@cn,DIRECT",
"GEOSITE,category-games@cn,DIRECT",
"GEOSITE,geolocation-!cn,Proxy",
"GEOSITE,private,DIRECT",
"GEOSITE,telegram,Proxy",
"GEOIP,private,DIRECT,no-resolve",
"GEOIP,telegram,Proxy,no-resolve",
"GEOIP,CN,DIRECT",
"DOMAIN-SUFFIX,.cn,DIRECT",
"MATCH,Proxy"
];

// 插入分组
groups.unshift(Proxy, Speedtest)
// 插入规则
params.rules = rules;

return params;
}

Merge 部分

Copy
# Merge Template for clash verge
# The `Merge` format used to enhance profile
mode: rule # 规则模式：rule（规则） / global（全局代理）/ direct（全局直连）/ script (脚本)
ipv6: true # 开启 IPv6 总开关，关闭阻断所有 IPv6 链接和屏蔽 DNS 请求 AAAA 记录
log-level: info # 设置日志输出级别 (5 个级别：silent / error / warning / info / debug）
mixed-port: 20810 # 混合端口，HTTP和SOCKS5用一个端口
unified-delay: true # 统一延迟，更换延迟计算方式，去除握手等额外延迟
tcp-concurrent: true # 【Meta专属】TCP 并发连接所有 IP, 将使用最快握手的 TCP
keep-alive-interval: 15 # TCP keep alive interval

geodata-mode: true # 【Meta专属】使用geoip.dat数据库(默认：false使用mmdb数据库)
geox-url: # 自定义 geodata url, 需要有代理的前提才能下载geoip和geosite
geoip: "https://gcore.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@release/geoip.dat"
geosite: "https://gcore.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@release/geosite.dat"
mmdb: "https://gcore.jsdelivr.net/gh/Hackl0us/GeoIP2-CN@release/Country.mmdb"

find-process-mode: strict # 匹配所有进程（always/strict/off）
global-client-fingerprint: chrome # 全局 TLS 指纹，优先低于 proxy 内的 client-fingerprint
# 可选： "chrome","firefox","safari","ios","random","none" options.

profile:
store-selected: true # 存储 select 选择记录
store-fake-ip: true # 持久化 fake-ip

sniffer: # 嗅探域名 可选配置
enable: true
parse-pure-ip: true # 是否使用嗅探结果作为实际访问，默认 true
sniff:
TLS: # TLS 默认嗅探 443
ports: [443, 8443]
HTTP:
ports: [80, 8080-8880]
override-destination: true
force-domain: [] # 强制对此域名进行嗅探

dns:
enable: true # 关闭将使用系统 DNS
prefer-h3: true # 是否开启 DOH 的 http/3
ipv6: true # IPV6解析开关；如果为false，将返回ipv6结果为空
enhanced-mode: fake-ip # 模式：redir-host或fake-ip
listen: 0.0.0.0:1053 # DNS 监听地址
use-hosts: true # 是否查询系统 hosts
fake-ip-range: 198.18.0.1/16 # fakeip 下的 IP 段设置，tun 网卡的默认 ip 也使用此值
fake-ip-filter: ['+.lan', '+.msftncsi.com', 'msftconnecttest.com', '+.msftconnecttest.com', '*.msftncsi.com', '*.msftconnecttest.com']
# Fake-ip 过滤，列表中的域名返回真实IP
default-nameserver: [223.5.5.5, 119.29.29.29]
# 解析非IP的dns用的dns服务器，只支持纯IP，（Meta可为其加密）
nameserver: [tcp://208.67.222.222#Proxy, tcp://8.8.8.8#Proxy]
# 默认DNS服务器，支持udp/tcp/dot/doh/doq
proxy-server-nameserver: [https://223.5.5.5/dns-query, https://1.12.12.12/dns-query]
# 代理DNS服务器，支持udp/tcp/dot/doh/doq
nameserver-policy:
"geosite:cn,private,geolocation-!cn@cn,bytedance,steam@cn,epicgames,microsoft@cn,apple@cn": [223.5.5.5#DIRECT, 119.29.29.29#DIRECT]
"geosite:steam": [tcp://1.1.1.1#Proxy]
# 指定域名查询的解析服务器，可使用 geosite, 优先于 nameserver/fallback 查询

大佬原版配置文件（实现多地区多平台分流）

Script 部分

Copy
// Define the `main` function

// function main(params) {
// return params;
// }

// Define the `main` function

function main(params) {

// 香港地区
const hongKongRegex = /香港|HK|Hong|🇭🇰/;
const hongKongProxies = params.proxies
.filter((e) => hongKongRegex.test(e.name))
.map((e) => e.name);
// 台湾地区
const taiwanRegex = /台湾|TW|Taiwan|Wan|🇨🇳|🇹🇼/;
const taiwanProxies = params.proxies
.filter((e) => taiwanRegex.test(e.name))
.map((e) => e.name);
// 狮城地区
const singaporeRegex = /新加坡|狮城|SG|Singapore|🇸🇬/;
const singaporeProxies = params.proxies
.filter((e) => singaporeRegex.test(e.name))
.map((e) => e.name);
// 日本地区
const japanRegex = /日本|JP|Japan|🇯🇵/;
const japanProxies = params.proxies
.filter((e) => japanRegex.test(e.name))
.map((e) => e.name);
// 美国地区
const americaRegex = /美国|US|United States|America|🇺🇸/;
const americaProxies = params.proxies
.filter((e) => americaRegex.test(e.name))
.map((e) => e.name);
// 其他地区
const othersRegex = /香港|HK|Hong|🇭🇰|台湾|TW|Taiwan|Wan|🇨🇳|🇹🇼|新加坡|SG|Singapore|狮城|🇸🇬|日本|JP|Japan|🇯🇵|美国|US|States|America|🇺🇸|自动|故障|流量|官网|套餐|机场|订阅/;
const othersProxies = params.proxies
.filter((e) => !othersRegex.test(e.name))
.map((e) => e.name);
// 所有地区
const allRegex = /自动|故障|流量|官网|套餐|机场|订阅/;
const allProxies = params.proxies
.filter((e) => !allRegex.test(e.name))
.map((e) => e.name);

// 香港
const HongKong = {
name: "HongKong",
type: "url-test",
url: "http://www.gstatic.com/generate_204",
interval: 300,
tolerance: 20,
lazy: true,
proxies: hongKongProxies.length > 0 ? hongKongProxies : ["DIRECT"]
};
// 台湾
const TaiWan = {
name: "TaiWan",
type: "url-test",
url: "http://www.gstatic.com/generate_204",
interval: 300,
tolerance: 20,
lazy: true,
proxies: taiwanProxies.length > 0 ? taiwanProxies : ["DIRECT"]
};
// 狮城
const Singapore = {
name: "Singapore",
type: "url-test",
url: "http://www.gstatic.com/generate_204",
interval: 300,
tolerance: 20,
lazy: true,
proxies: singaporeProxies.length > 0 ? singaporeProxies : ["DIRECT"]
};
// 日本
const Japan = {
name: "Japan",
type: "url-test",
url: "http://www.gstatic.com/generate_204",
interval: 300,
tolerance: 20,
lazy: true,
proxies: japanProxies.length > 0 ? japanProxies : ["DIRECT"]
};
// 美国
const America = {
name: "America",
type: "url-test",
url: "http://www.gstatic.com/generate_204",
interval: 300,
tolerance: 20,
lazy: true,
proxies: americaProxies.length > 0 ? americaProxies : ["DIRECT"]
};
// 其他
const Others = {
name: "Others",
type: "url-test",
url: "http://www.gstatic.com/generate_204",
interval: 300,
tolerance: 20,
lazy: true,
proxies: othersProxies.length > 0 ? othersProxies : ["DIRECT"]
};
// 自动
const Auto = {
name: "Auto",
type: "url-test",
url: "http://www.gstatic.com/generate_204",
interval: 300,
tolerance: 20,
lazy: true,
proxies: allProxies.length > 0 ? allProxies : ["DIRECT"]
};
// 负载均衡
const Balance = {
name: "Balance",
type: "load-balance",
url: "http://www.gstatic.com/generate_204",
interval: 300,
strategy: "consistent-hashing",
lazy: true,
proxies: allProxies.length > 0 ? allProxies : ["DIRECT"]
};
// 故障转移
const Fallback = {
name: "Fallback",
type: "fallback",
url: "http://www.gstatic.com/generate_204",
interval: 300,
lazy: true,
proxies: allProxies.length > 0 ? allProxies : ["DIRECT"]
};

// 国外分组
const G = ["Proxy", "Auto", "Balance", "Fallback", "HongKong", "TaiWan", "Singapore", "Japan", "America", "Others"];
// 国内分组
const M = ["DIRECT", "Proxy", "Auto", "Balance", "Fallback", "HongKong", "TaiWan", "Singapore", "Japan", "America", "Others"];
// AI分组
const AI = ["Proxy", "America", "Japan", "Singapore", "TaiWan", "HongKong", "Others"];

// 漏网之鱼
const Final = { name: "Final", type: "select", proxies: ["DIRECT", "Global", "Proxy"] };
// 手动选择
const Proxy = { name: "Proxy", type: "select", proxies: allProxies.length > 0 ? allProxies : ["DIRECT"] };
// 国外网站
const Global = { name: "Global", type: "select", proxies: G };
// 国内网站
const Mainland = { name: "Mainland", type: "select", proxies: M };
// 人工智能
const ArtIntel = { name: "ArtIntel", type: "select", proxies: AI };
// 油管视频
const YouTube = { name: "YouTube", type: "select", proxies: G };
// 哔哩哔哩
const BiliBili = { name: "BiliBili", type: "select", proxies: ["DIRECT", "HongKong", "TaiWan"] };
// 国际媒体
const Streaming = { name: "Streaming", type: "select", proxies: G };
// 电报信息
const Telegram = { name: "Telegram", type: "select", proxies: G };
// 谷歌服务
const Google = { name: "Google", type: "select", proxies: G };
// 游戏平台
const Games = { name: "Games", type: "select", proxies: G };

const groups = params["proxy-groups"] = [];
// 规则
const rules = [
"AND,(AND,(DST-PORT,443),(NETWORK,UDP)),(NOT,((GEOIP,CN))),REJECT",// quic
// "GEOSITE,Category-ads-all,REJECT", // 可能导致某些网站无法访问
"GEOSITE,Private,DIRECT",
"GEOSITE,Category-games@cn,Mainland",
"GEOSITE,Microsoft@cn,Mainland",
"GEOSITE,Apple@cn,Mainland",
"GEOSITE,Bing,ArtIntel",
"GEOSITE,Openai,ArtIntel",
"GEOSITE,Category-games,Games",
"GEOSITE,Github,Global",
"GEOSITE,Telegram,Telegram",
"GEOSITE,Youtube,YouTube",
"GEOSITE,Disney,Streaming",
"GEOSITE,Netflix,Streaming",
"GEOSITE,HBO,Streaming",
"GEOSITE,Primevideo,Streaming",
"GEOSITE,Bilibili,BiliBili",
"GEOSITE,Google,Google",
"GEOSITE,Geolocation-!cn,Global",
"GEOIP,CN,Mainland,no-resolve",
"MATCH,Final"
];

// 插入分组
groups.unshift(HongKong, TaiWan, Japan, Singapore, America, Others, Auto, Balance, Fallback);
groups.unshift(Final, Proxy, Global, Mainland, ArtIntel, YouTube, BiliBili, Streaming, Telegram, Google, Games);
// 插入规则
params.rules = rules;

return params;
}