Open lanceyliao opened 2 months ago
可以参考这个简化下代码,用...解包。另外弱弱地问下,为什么不用provider呢? https://clash-verge-rev.github.io/guide/script.html#_3
// 国内DNS服务器
const domesticNameservers = [
"https://dns.alidns.com/dns-query", // 阿里云公共DNS
"https://doh.pub/dns-query", // 腾讯DNSPod
"https://doh.360.cn/dns-query" // 360安全DNS
];
// 国外DNS服务器
const foreignNameservers = [
"https://1.1.1.1/dns-query", // Cloudflare(主)
"https://1.0.0.1/dns-query", // Cloudflare(备)
"https://208.67.222.222/dns-query", // OpenDNS(主)
"https://208.67.220.220/dns-query", // OpenDNS(备)
"https://194.242.2.2/dns-query", // Mullvad(主)
"https://194.242.2.3/dns-query" // Mullvad(备)
];
// DNS配置
const dnsConfig = {
"dns": true,
"listen": 1053,
"ipv6": true,
"use-system-hosts": false,
"cache-algorithm": "arc",
"enhanced-mode": "fake-ip",
"fake-ip-range": "198.18.0.1/16",
"fake-ip-filter": ["+.lan", "+.local", "+.msftconnecttest.com", "+.msftncsi.com"],
"default-nameserver": ["223.5.5.5", "114.114.114.114", "1.1.1.1", "8.8.8.8"],
"nameserver": [...domesticNameservers, ...foreignNameservers],
"proxy-server-nameserver": [...domesticNameservers, ...foreignNameservers],
"nameserver-policy": {
"geosite:private,cn,geolocation-cn": domesticNameservers,
"geosite:google,youtube,telegram,gfw,geolocation-!cn": foreignNameservers
}
};
// 规则集通用配置
const ruleProviderCommon = {
"type": "http",
"format": "yaml",
"interval": 86400
};
// 规则集配置
const ruleProviders = {
"reject": {
...ruleProviderCommon,
"behavior": "domain",
"url": "https://fastly.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/reject.txt",
"path": "./rulesets/loyalsoldier/reject.yaml"
},
"icloud": {
...ruleProviderCommon,
"behavior": "domain",
"url": "https://fastly.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/icloud.txt",
"path": "./rulesets/loyalsoldier/icloud.yaml"
},
"apple": {
...ruleProviderCommon,
"behavior": "domain",
"url": "https://fastly.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/apple.txt",
"path": "./rulesets/loyalsoldier/apple.yaml"
},
"google": {
...ruleProviderCommon,
"behavior": "domain",
"url": "https://fastly.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/google.txt",
"path": "./rulesets/loyalsoldier/google.yaml"
},
"proxy": {
...ruleProviderCommon,
"behavior": "domain",
"url": "https://fastly.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/proxy.txt",
"path": "./rulesets/loyalsoldier/proxy.yaml"
},
"direct": {
...ruleProviderCommon,
"behavior": "domain",
"url": "https://fastly.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/direct.txt",
"path": "./rulesets/loyalsoldier/direct.yaml"
},
"private": {
...ruleProviderCommon,
"behavior": "domain",
"url": "https://fastly.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/private.txt",
"path": "./rulesets/loyalsoldier/private.yaml"
},
"gfw": {
...ruleProviderCommon,
"behavior": "domain",
"url": "https://fastly.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/gfw.txt",
"path": "./rulesets/loyalsoldier/gfw.yaml"
},
"tld-not-cn": {
...ruleProviderCommon,
"behavior": "domain",
"url": "https://fastly.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/tld-not-cn.txt",
"path": "./rulesets/loyalsoldier/tld-not-cn.yaml"
},
"telegramcidr": {
...ruleProviderCommon,
"behavior": "ipcidr",
"url": "https://fastly.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/telegramcidr.txt",
"path": "./rulesets/loyalsoldier/telegramcidr.yaml"
},
"cncidr": {
...ruleProviderCommon,
"behavior": "ipcidr",
"url": "https://fastly.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/cncidr.txt",
"path": "./rulesets/loyalsoldier/cncidr.yaml"
},
"lancidr": {
...ruleProviderCommon,
"behavior": "ipcidr",
"url": "https://fastly.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/lancidr.txt",
"path": "./rulesets/loyalsoldier/lancidr.yaml"
},
"applications": {
...ruleProviderCommon,
"behavior": "classical",
"url": "https://fastly.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/applications.txt",
"path": "./rulesets/loyalsoldier/applications.yaml"
}
};
// 规则
const rules = [
// 自定义规则
"DOMAIN-SUFFIX,googleapis.cn,节点选择", // Google服务
"DOMAIN-SUFFIX,gstatic.com,节点选择", // Google静态资源
"DOMAIN-SUFFIX,xn--ngstr-lra8j.com,节点选择", // Google Play下载服务
"DOMAIN-SUFFIX,github.io,节点选择", // Github Pages
"DOMAIN,v2rayse.com,节点选择", // V2rayse节点工具
// Loyalsoldier 规则集
"RULE-SET,reject,广告过滤",
"RULE-SET,icloud,微软服务",
"RULE-SET,apple,苹果服务",
"RULE-SET,google,谷歌服务",
"RULE-SET,proxy,节点选择",
"RULE-SET,gfw,节点选择",
"RULE-SET,tld-not-cn,节点选择",
"RULE-SET,applications,全局直连",
"RULE-SET,private,全局直连",
"RULE-SET,direct,全局直连",
"RULE-SET,lancidr,全局直连,no-resolve",
"RULE-SET,cncidr,全局直连,no-resolve",
"RULE-SET,telegramcidr,电报消息,no-resolve",
// 其他规则
"GEOIP,LAN,全局直连,no-resolve",
"GEOIP,CN,全局直连,no-resolve",
"MATCH,漏网之鱼"
];
// 代理组通用配置
const groupBaseOption = {
"interval": 300,
"timeout": 3000,
"url": "https://www.google.com/generate_204",
"lazy": true,
"max-failed-times": 3,
"hidden": false
};
// 程序入口
function main(config) {
const proxyCount = config?.proxies?.length ?? 0;
const proxyProviderCount =
typeof config?.["proxy-providers"] === "object" ? Object.keys(config["proxy-providers"]).length : 0;
if (proxyCount === 0 && proxyProviderCount === 0) {
throw new Error("配置文件中未找到任何代理");
}
// 覆盖原配置中DNS配置
config["dns"] = dnsConfig;
// 覆盖原配置中的代理组
config["proxy-groups"] = [
{
...groupBaseOption,
"name": "节点选择",
"type": "select",
"proxies": ["延迟选优", "故障转移", "负载均衡(散列)", "负载均衡(轮询)"],
"include-all": true,
"icon": "https://fastly.jsdelivr.net/gh/clash-verge-rev/clash-verge-rev.github.io@main/docs/assets/icons/adjust.svg"
},
{
...groupBaseOption,
"name": "延迟选优",
"type": "url-test",
"tolerance": 100,
"include-all": true,
"icon": "https://fastly.jsdelivr.net/gh/clash-verge-rev/clash-verge-rev.github.io@main/docs/assets/icons/speed.svg"
},
{
...groupBaseOption,
"name": "故障转移",
"type": "fallback",
"include-all": true,
"icon": "https://fastly.jsdelivr.net/gh/clash-verge-rev/clash-verge-rev.github.io@main/docs/assets/icons/ambulance.svg"
},
{
...groupBaseOption,
"name": "负载均衡(散列)",
"type": "load-balance",
"strategy": "consistent-hashing",
"include-all": true,
"icon": "https://fastly.jsdelivr.net/gh/clash-verge-rev/clash-verge-rev.github.io@main/docs/assets/icons/merry_go.svg"
},
{
...groupBaseOption,
"name": "负载均衡(轮询)",
"type": "load-balance",
"strategy": "round-robin",
"include-all": true,
"icon": "https://fastly.jsdelivr.net/gh/clash-verge-rev/clash-verge-rev.github.io@main/docs/assets/icons/balance.svg"
},
{
...groupBaseOption,
"name": "谷歌服务",
"type": "select",
"proxies": ["节点选择", "延迟选优", "故障转移", "负载均衡(散列)", "负载均衡(轮询)", "全局直连"],
"include-all": true,
"icon": "https://fastly.jsdelivr.net/gh/clash-verge-rev/clash-verge-rev.github.io@main/docs/assets/icons/google.svg"
},
{
...groupBaseOption,
"name": "国外媒体",
"type": "select",
"proxies": ["节点选择", "延迟选优", "故障转移", "负载均衡(散列)", "负载均衡(轮询)", "全局直连"],
"include-all": true,
"icon": "https://fastly.jsdelivr.net/gh/clash-verge-rev/clash-verge-rev.github.io@main/docs/assets/icons/youtube.svg"
},
{
...groupBaseOption,
"name": "电报消息",
"type": "select",
"proxies": ["节点选择", "延迟选优", "故障转移", "负载均衡(散列)", "负载均衡(轮询)", "全局直连"],
"include-all": true,
"icon": "https://fastly.jsdelivr.net/gh/clash-verge-rev/clash-verge-rev.github.io@main/docs/assets/icons/telegram.svg"
},
{
...groupBaseOption,
"name": "微软服务",
"type": "select",
"proxies": ["全局直连", "节点选择", "延迟选优", "故障转移", "负载均衡(散列)", "负载均衡(轮询)"],
"include-all": true,
"icon": "https://fastly.jsdelivr.net/gh/clash-verge-rev/clash-verge-rev.github.io@main/docs/assets/icons/microsoft.svg"
},
{
...groupBaseOption,
"name": "苹果服务",
"type": "select",
"proxies": ["节点选择", "延迟选优", "故障转移", "负载均衡(散列)", "负载均衡(轮询)", "全局直连"],
"include-all": true,
"icon": "https://fastly.jsdelivr.net/gh/clash-verge-rev/clash-verge-rev.github.io@main/docs/assets/icons/apple.svg"
},
{
...groupBaseOption,
"name": "广告过滤",
"type": "select",
"proxies": ["REJECT", "DIRECT"],
"icon": "https://fastly.jsdelivr.net/gh/clash-verge-rev/clash-verge-rev.github.io@main/docs/assets/icons/bug.svg"
},
{
...groupBaseOption,
"name": "全局直连",
"type": "select",
"proxies": ["DIRECT", "节点选择", "延迟选优", "故障转移", "负载均衡(散列)", "负载均衡(轮询)"],
"include-all": true,
"icon": "https://fastly.jsdelivr.net/gh/clash-verge-rev/clash-verge-rev.github.io@main/docs/assets/icons/link.svg"
},
{
...groupBaseOption,
"name": "全局拦截",
"type": "select",
"proxies": ["REJECT", "DIRECT"],
"icon": "https://fastly.jsdelivr.net/gh/clash-verge-rev/clash-verge-rev.github.io@main/docs/assets/icons/block.svg"
},
{
...groupBaseOption,
"name": "漏网之鱼",
"type": "select",
"proxies": ["节点选择", "延迟选优", "故障转移", "负载均衡(散列)", "负载均衡(轮询)", "全局直连"],
"include-all": true,
"icon": "https://fastly.jsdelivr.net/gh/clash-verge-rev/clash-verge-rev.github.io@main/docs/assets/icons/fish.svg"
}
];
// 覆盖原配置中的规则
config["rule-providers"] = ruleProviders;
config["rules"] = rules;
// 返回修改后的配置
return config;
}
https://t.me/cumslut_channel/211
// 国内DNS服务器
const nameservers = [
"https://doh.pub/dns-query", // 腾讯DNSPod
"https://dns.alidns.com/dns-query" // 阿里云公共DNS
];
// 国外DNS服务器
const fallback_nameservers = [
'https://dns.google/dns-query',
'https://dns.cloudflare.com/dns-query',
'https://doh.dns.sb/dns-query'
];
// DNS配置
const dns = {
"dns": true,
"listen": 1053,
"ipv6": true,
"use-hosts": true,
"cache-algorithm": "arc",
"enhanced-mode": "fake-ip",
"fake-ip-range": "198.18.0.1/16",
"fake-ip-filter": ["+.lan", "+.local", "+.msftconnecttest.com", "+.msftncsi.com"],
"default-nameserver": ["119.29.29.29", "180.76.76.76", "223.5.5.5"],
"nameserver": nameservers,
"proxy-server-nameserver": nameservers,
"nameserver-policy": {
"geosite:private,cn": nameservers,
"geosite:google,youtube,telegram,gfw,geolocation-!cn": fallback_nameservers
}
};
// 规则集
const provider_common = {
"type": "http",
"behavior": "domain",
"format": "yaml",
"interval": 86400
};
const rule_providers = {
"reject": {
...provider_common,
"url": "https://fastly.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/reject.txt",
"path": "./rulesets/loyalsoldier/reject.yaml",
},
"icloud": {
...provider_common,
"url": "https://fastly.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/icloud.txt",
"path": "./rulesets/loyalsoldier/icloud.yaml"
},
"apple": {
...provider_common,
"url": "https://fastly.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/apple.txt",
"path": "./rulesets/loyalsoldier/apple.yaml"
},
"google": {
...provider_common,
"url": "https://fastly.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/google.txt",
"path": "./rulesets/loyalsoldier/google.yaml"
},
"proxy": {
...provider_common,
"url": "https://fastly.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/proxy.txt",
"path": "./rulesets/loyalsoldier/proxy.yaml"
},
"direct": {
...provider_common,
"url": "https://fastly.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/direct.txt",
"path": "./rulesets/loyalsoldier/direct.yaml"
},
"private": {
...provider_common,
"url": "https://fastly.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/private.txt",
"path": "./rulesets/loyalsoldier/private.yaml"
},
"gfw": {
...provider_common,
"url": "https://fastly.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/gfw.txt",
"path": "./rulesets/loyalsoldier/gfw.yaml"
},
"tld-not-cn": {
...provider_common,
"url": "https://fastly.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/tld-not-cn.txt",
"path": "./rulesets/loyalsoldier/tld-not-cn.yaml"
},
"telegramcidr": {
...provider_common,
"url": "https://fastly.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/telegramcidr.txt",
"path": "./rulesets/loyalsoldier/telegramcidr.yaml"
},
"cncidr": {
...provider_common,
"url": "https://fastly.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/cncidr.txt",
"path": "./rulesets/loyalsoldier/cncidr.yaml"
},
"lancidr": {
...provider_common,
"url": "https://fastly.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/lancidr.txt",
"path": "./rulesets/loyalsoldier/lancidr.yaml"
},
"applications": {
...provider_common,
"url": "https://fastly.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/applications.txt",
"path": "./rulesets/loyalsoldier/applications.yaml"
}
}
// 规则
const rules = [
// 自定义规则
"DOMAIN-SUFFIX,cumslut.site,全局直连",
"DOMAIN-SUFFIX,xn--ngstr-lra8j.com,节点选择",
"DOMAIN-SUFFIX,services.googleapis.cn,节点选择",
"DOMAIN-SUFFIX,googleapis.cn,节点选择",
"DOMAIN-SUFFIX,gstatic.com,节点选择",
"DOMAIN-SUFFIX,github.io,节点选择",
// Loyalsoldier 规则集
"RULE-SET,apple,苹果服务,no-resolve",
"RULE-SET,icloud,微软服务,no-resolve",
"RULE-SET,google,谷歌服务,no-resolve",
"RULE-SET,telegramcidr,电报消息,no-resolve",
"RULE-SET,gfw,节点选择,no-resolve",
"RULE-SET,proxy,节点选择,no-resolve",
"RULE-SET,tld-not-cn,节点选择,no-resolve",
"RULE-SET,direct,全局直连,no-resolve",
"RULE-SET,private,全局直连,no-resolve",
"RULE-SET,cncidr,全局直连,no-resolve",
"RULE-SET,lancidr,全局直连,no-resolve",
"RULE-SET,applications,全局直连,no-resolve",
"RULE-SET,reject,广告过滤,no-resolve",
// 其他规则
"GEOIP,LAN,全局直连,no-resolve",
"GEOIP,CN,全局直连,no-resolve",
"MATCH,漏网之鱼"
];
// 代理组通用配置
const group_base_option = {
"interval": 300,
"timeout": 3000,
"url": "https://www.google.com/generate_204",
"lazy": true,
"max-failed-times": 3,
"hidden": false
};
// 程序入口
function main(config) {
const proxy_count = config?.proxies?.length ?? 0;
const proxy_providers_count = typeof (config?.["proxy-providers"]) === 'object' ? Object.keys(config["proxy-providers"]).length : 0;
if (proxy_count === 0 && proxy_providers_count === 0) {
throw new Error("配置文件中未找到任何代理");
}
// 覆盖原配置中DNS配置
config["dns"] = dns;
// 覆盖原配置中的代理组
config["proxy-groups"] = [
{
...group_base_option,
"name": "节点选择",
"type": "select",
"proxies": ["延迟选优", "relay", "故障转移", "负载均衡(散列)", "负载均衡(轮询)"],
"include-all": true,
"icon": "https://mirror.ghproxy.com/https://raw.githubusercontent.com/dongchengjie/metaST/main/metaST/Resources/icons/adjust.svg"
},
{
...group_base_option,
"name": "入口节点",
"type": "select",
"proxies": [],
"include-all": true,
"icon": "https://mirror.ghproxy.com/https://raw.githubusercontent.com/dongchengjie/metaST/main/metaST/Resources/icons/adjust.svg"
},
{
...group_base_option,
"name": "出口节点",
"type": "select",
"proxies": [],
"include-all": true,
"icon": "https://mirror.ghproxy.com/https://raw.githubusercontent.com/dongchengjie/metaST/main/metaST/Resources/icons/adjust.svg"
},
{
...group_base_option,
"name": "延迟选优",
"type": "url-test",
"tolerance": 100,
"include-all": true,
"icon": "https://mirror.ghproxy.com/https://raw.githubusercontent.com/dongchengjie/metaST/main/metaST/Resources/icons/speed.svg"
},
{
...group_base_option,
"name": "故障转移",
"type": "fallback",
"include-all": true,
"icon": "https://mirror.ghproxy.com/https://raw.githubusercontent.com/dongchengjie/metaST/main/metaST/Resources/icons/ambulance.svg"
},
{
...group_base_option,
"name": "负载均衡(散列)",
"type": "load-balance",
"strategy": "consistent-hashing",
"include-all": true,
"icon": "https://mirror.ghproxy.com/https://raw.githubusercontent.com/dongchengjie/metaST/main/metaST/Resources/icons/merry_go.svg"
},
{
...group_base_option,
"name": "负载均衡(轮询)",
"type": "load-balance",
"strategy": "round-robin",
"include-all": true,
"icon": "https://mirror.ghproxy.com/https://raw.githubusercontent.com/dongchengjie/metaST/main/metaST/Resources/icons/balance.svg"
},
{
...group_base_option,
"name": "谷歌服务",
"type": "select",
"proxies": ["节点选择", "延迟选优", "故障转移", "负载均衡(散列)", "负载均衡(轮询)", "全局直连"],
"include-all": true,
"icon": "https://mirror.ghproxy.com/https://raw.githubusercontent.com/dongchengjie/metaST/main/metaST/Resources/icons/google.svg"
},
{
...group_base_option,
"name": "国外媒体",
"type": "select",
"proxies": ["节点选择", "延迟选优", "故障转移", "负载均衡(散列)", "负载均衡(轮询)", "全局直连"],
"include-all": true,
"icon": "https://mirror.ghproxy.com/https://raw.githubusercontent.com/dongchengjie/metaST/main/metaST/Resources/icons/youtube.svg"
},
{
...group_base_option,
"name": "电报消息",
"type": "select",
"proxies": ["节点选择", "延迟选优", "故障转移", "负载均衡(散列)", "负载均衡(轮询)", "全局直连"],
"include-all": true,
"icon": "https://mirror.ghproxy.com/https://raw.githubusercontent.com/dongchengjie/metaST/main/metaST/Resources/icons/telegram.svg"
},
{
...group_base_option,
"name": "微软服务",
"type": "select",
"proxies": ["全局直连", "节点选择", "延迟选优", "故障转移", "负载均衡(散列)", "负载均衡(轮询)"],
"include-all": true,
"icon": "https://mirror.ghproxy.com/https://raw.githubusercontent.com/dongchengjie/metaST/main/metaST/Resources/icons/microsoft.svg"
},
{
...group_base_option,
"name": "苹果服务",
"type": "select",
"proxies": ["节点选择", "延迟选优", "故障转移", "负载均衡(散列)", "负载均衡(轮询)", "全局直连"],
"include-all": true,
"icon": "https://mirror.ghproxy.com/https://raw.githubusercontent.com/dongchengjie/metaST/main/metaST/Resources/icons/apple.svg"
},
{
...group_base_option,
"name": "广告过滤",
"type": "select",
"proxies": ["REJECT", "DIRECT"],
"icon": "https://mirror.ghproxy.com/https://raw.githubusercontent.com/dongchengjie/metaST/main/metaST/Resources/icons/bug.svg"
},
{
...group_base_option,
"name": "全局直连",
"type": "select",
"proxies": ["DIRECT", "节点选择", "延迟选优", "故障转移", "负载均衡(散列)", "负载均衡(轮询)"],
"include-all": true,
"icon": "https://mirror.ghproxy.com/https://raw.githubusercontent.com/dongchengjie/metaST/main/metaST/Resources/icons/link.svg"
},
{
...group_base_option,
"name": "全局拦截",
"type": "select",
"proxies": ["REJECT", "DIRECT"],
"icon": "https://mirror.ghproxy.com/https://raw.githubusercontent.com/dongchengjie/metaST/main/metaST/Resources/icons/block.svg"
},
{
...group_base_option,
"name": "漏网之鱼",
"type": "select",
"proxies": ["节点选择", "延迟选优", "故障转移", "负载均衡(散列)", "负载均衡(轮询)", "全局直连"], "include-all": true,
"icon": "https://mirror.ghproxy.com/https://raw.githubusercontent.com/dongchengjie/metaST/main/metaST/Resources/icons/fish.svg"
},
{
...group_base_option,
"name": "relay",
"type": "relay",
"proxies": ["入口节点", "出口节点"],
"include-all": false,
"icon": "https://mirror.ghproxy.com/https://raw.githubusercontent.com/dongchengjie/metaST/main/metaST/Resources/icons/adjust.svg"
}
];
// 覆盖原配置中的规则
config["rule-providers"] = rule_providers;
config["rules"] = rules;
// 返回修改后的配置
return config;
}
楼主 你的这个代码可以改成让他自己筛选国家吗 我复制你项目里的代码提示错误,你在这里发的代码可以用但是国家分类没了
1.7.1更新后默认全局扩展配置多了个use-system-hosts:false,要加进去吗?
https://github.com/clash-verge-rev/clash-verge-rev/releases 修改 Merge 配置文件默认内容 https://github.com/clash-verge-rev/clash-verge-rev/pull/889