寫在前面#
在 Clash for Windows 刪庫跑路後,Clash Verge 成為了大眾的主流選擇(不代表 Clash for Windows 不能用了,只是沒有後續更新而已)。我在轉到這個軟體後,發現它居然沒有 **Parsers 功能**,這讓我感到十分遺憾。
於是我找到了個解決方案,通過 Clash Verge 的配置文件,將類似 Parsers 功能添加到 Clash Verge 中。
配置文件(個人修改版,僅實現簡單功能)#
Script 部分#
// 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 部分#
# 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 部分#
// 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;
}