跳到主要内容

ClashMixin规则

module.exports.parse = async ({ content, name, url }, { yaml, axios, notify }) => {
// content: 原始文本内容(对象)
// name: 文件名(字符串)
// url: 文件链接(字符串)
// yaml: yaml解析器
// axios: http请求库
// notify: 通知函数

const proxyName = "🚀 节点选择" // 可以根据需要修改或从外部传入

const extendedRules = {
direct: {
processes: [
//"steam.exe",
"MAA.exe",
"RayLinkService.exe",
"wireguard.exe",
"firefox.exe",
"syncthing.exe",
"tailscaled.exe", // Tailscale
"tailscale-ipn.exe",
"EpicWebHelper.exe", // Epic Games
"EpicGamesLauncher.exe",
],
domainSuffixes: [
"steamcontent.com",
"cpu-monkey.com",
"rec.114514.plus",
"test-ipv6.com",
"ipv6-test.com",
],
ips: [
"111.123.56.92/32",
],
},

reject: {
processes: [
"xshell.exe",
],
domainSuffixes: [
"activity.windows.com", // 微软
"server.events.data.microsoft.com",
"assets.msn.cn",
"applicationinsights.azure.com",
"aeventlog.beacon.qq.com",
"amplitude.com", // 分析
"mcdn.bilivideo.cn", // B站PCDN
],
domains: [
"otheve.beacon.qq.com", // 腾讯
"oth.eve.mdt.qq.com",
"mumu.nie.netease.com", // 网易
],
keywords: [
"tpstelemetry", // 腾讯
"galileotelemetry",
"log-upload.mihoyo.com", // 米哈游
"h5collector.mihoyo.com",
"google-analytics", // 谷歌分析
],
},

proxy: {
domainSuffixes: [
"notion.site",
"claude.ai",
"hfyrw.com",
"jsdelivr.net",
],
domains: [
"challenges.cloudflare.com",
"www.k8dm.com",
"hfyrw.com",
],
},
}

// 规则类[processes, domainSuffixes, domains, ips, keywords]
const ruleTypes = {
processes: "PROCESS-NAME",
domainSuffixes: "DOMAIN-SUFFIX",
domains: "DOMAIN",
ips: "IP-CIDR",
keywords: "DOMAIN-KEYWORD",
}

// 生成规则
const rules = []
// direct,除了ip不用加no-resolve,其他都要加
for (const [type, values] of Object.entries(extendedRules.direct)) {
for (const value of values) {
rules.push(`${ruleTypes[type]},${value},${type === "ips" ? "DIRECT" : "DIRECT,no-resolve"}`)
}
}
// reject
for (const [type, values] of Object.entries(extendedRules.reject)) {
for (const value of values) {
rules.push(`${ruleTypes[type]},${value},REJECT`)
}
}
// proxy
for (const [type, values] of Object.entries(extendedRules.proxy)) {
for (const value of values) {
rules.push(`${ruleTypes[type]},${value},${proxyName}`)
}
}

// 添加规则到content['rules']
content['rules'] = rules.concat(content['rules'])

return content;
}