1. DNS 配置脚本

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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
function main(content) {
const isObject = (value) => {
return value !== null && typeof value === 'object'
}

const mergeConfig = (existingConfig, newConfig) => {
if (!isObject(existingConfig)) {
existingConfig = {}
}
if (!isObject(newConfig)) {
return existingConfig
}
return { ...existingConfig, ...newConfig }
}

const cnDnsList = [
'192.168.1.113',
'https://223.5.5.5/dns-query',
'https://223.6.6.6/dns-query',
]
const trustDnsList = [
'192.168.1.113',
'quic://dns.cooluc.com',
'https://doh.apad.pro/dns-query',
'https://1.0.0.1/dns-query',
]
const notionDns = 'tls://dns.jerryw.cn'
const notionUrls = [
'http-inputs-notion.splunkcloud.com',
'+.notion-static.com',
'+.notion.com',
'+.notion.new',
'+.notion.site',
'+.notion.so',
]
const combinedUrls = notionUrls.join(',');
const dnsOptions = {
'enable': true,
'prefer-h3': true, // 如果DNS服务器支持DoH3会优先使用h3
'default-nameserver': cnDnsList, // 用于解析其他DNS服务器、和节点的域名, 必须为IP, 可为加密DNS。注意这个只用来解析节点和其他的dns,其他网络请求不归他管
'nameserver': trustDnsList, // 其他网络请求都归他管

// 这个用于覆盖上面的 nameserver
'nameserver-policy': {
[combinedUrls]: notionDns,
'geosite:geolocation-!cn': trustDnsList,
// 如果你有一些内网使用的DNS,应该定义在这里,多个域名用英文逗号分割
// '+.公司域名.com, www.4399.com, +.baidu.com': '10.0.0.1'
},
}

// GitHub加速前缀
const githubPrefix = 'https://fastgh.lainbo.com/'

// GEO数据GitHub资源原始下载地址
const rawGeoxURLs = {
geoip: 'https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geoip-lite.dat',
geosite: 'https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geosite.dat',
mmdb: 'https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/country-lite.mmdb',
}

// 生成带有加速前缀的GEO数据资源对象
const accelURLs = Object.fromEntries(
Object.entries(rawGeoxURLs).map(([key, githubUrl]) => [key, `${githubPrefix}${githubUrl}`]),
)

const otherOptions = {
'unified-delay': false,
'tcp-concurrent': true,
'profile': {
'store-selected': true,
'store-fake-ip': true,
},
'sniffer': {
enable: true,
sniff: {
TLS: {
ports: [443, 8443],
},
HTTP: {
'ports': [80, '8080-8880'],
'override-destination': true,
},
},
},
'geodata-mode': true,
'geox-url': accelURLs,
}
content.dns = mergeConfig(content.dns, dnsOptions)
return { ...content, ...otherOptions }
}

2. ChatGPT 配置脚本

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
function main(params) {
// 下方两个数组的每一项均为正则,忽略大小写
const mustHaveKeywords = ['美国', '日本', '台湾', '新加坡', 'US', 'JP', 'TW', 'SG'];
// 过滤掉美国节点中,包含以下关键字的节点(过滤低质量节点,要过滤哪些根据自己的订阅来)
const mustNotHaveKeywords = ['实验性', '香港'];

const regexParts = [];
mustHaveKeywords.forEach(keyword => {
const mustNotHavePart = mustNotHaveKeywords.map(k => `(?!.*${k})`).join('');
regexParts.push(`(?=.*${keyword}${mustNotHavePart}).*`);
});
const regex = new RegExp(`^(${regexParts.join('|')})$`, 'i');

const rules = [ 
"DOMAIN-KEYWORD,cloudfare,ChatGPT", 
"DOMAIN-KEYWORD,openai,ChatGPT", 
"DOMAIN-KEYWORD,sentry,ChatGPT", 
"DOMAIN-SUFFIX,ai.com,ChatGPT", 
"DOMAIN-SUFFIX,auth0.com,ChatGPT", 
"DOMAIN-SUFFIX,challenges.cloudflare.com,ChatGPT", 
"DOMAIN-SUFFIX,client-api.arkoselabs.com,ChatGPT", 
"DOMAIN-SUFFIX,events.statsigapi.net,ChatGPT", 
"DOMAIN-SUFFIX,featuregates.org,ChatGPT", 
"DOMAIN-SUFFIX,identrust.com,ChatGPT", 
"DOMAIN-SUFFIX,ingest.sentry.io,ChatGPT", 
"DOMAIN-SUFFIX,intercom.io,ChatGPT", 
"DOMAIN-SUFFIX,intercomcdn.com,ChatGPT", 
"DOMAIN-SUFFIX,openai.com,ChatGPT", 
"DOMAIN-SUFFIX,openaiapi-site.azureedge.net,ChatGPT", 
"DOMAIN-SUFFIX,stripe.com,ChatGPT"
];

const proxies = params.proxies
.filter(i => regex.test(i.name))
.map(e => e.name);

const groups = params["proxy-groups"];

const newGroup = {
name: "ChatGPT",
type: "url-test",
proxies,
};

if (groups.length > 1) {
groups.splice(1, 0, newGroup);
params.rules = rules.concat(params.rules);
}

return params;
}

3. 过滤节点脚本

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
// 需要剔除的关键字数组,便于后期扩展
const excludedKeywords = ["韩国", "kr", "seoul"];
const regexParts = [];
excludedKeywords.forEach(keyword => {
regexParts.push(`(?=.*${keyword}).*`);
});
const regex = new RegExp(`^(${regexParts.join('|')})$`, 'i');

function main(config) {
const removed = []; // 用于记录被剔除的代理名称
containsKeyword = true;

// 遍历代理组
config["proxy-groups"] = config["proxy-groups"].map(group => {
// 过滤代理组中的代理
group["proxies"] = (group["proxies"] ?? []).filter(proxy => {
// 检查代理名称是否包含需要剔除的关键字
return !regex.test(proxy);
});
if (group["proxies"]?.length > 0) {
return group;
}
// 如果代理组中的代理被全部剔除,则记录下来
removed.push(group.name);
}).filter(Boolean);

// 移除被剔除的代理在其他代理组和规则中的引用
if (removed.length > 0) {
// 移除代理组的引用
config["proxy-groups"].forEach(group => {group["proxies"] = group["proxies"].filter(proxy => !removed.includes(proxy));});
// 移除规则的引用
config["rules"] = (config["rules"] ?? []).filter(rule => rule && removed.every(name => !rule.endsWith(name) && !rule.endsWith(`${name},no-resolve`)));
}

return config;
}

4. 自定义rules规则

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
# Profile Enhancement Merge Template for Clash Verge

prepend-rules:
- PROCESS-NAME,leigod.exe,DIRECT
- PROCESS-NAME,leishenSdk.exe,DIRECT
- PROCESS-NAME,XDown.exe,DIRECT
- PROCESS-NAME,thunder.exe,DIRECT
- PROCESS-NAME,DownloadSDKServer.exe,DIRECT
- PROCESS-NAME,115chrome.exe,DIRECT
- PROCESS-NAME,gopeed.exe,DIRECT
- PROCESS-NAME,夸克网盘.exe,DIRECT
- PROCESS-NAME,QQ.exe,DIRECT
- PROCESS-NAME,WeChat.exe,DIRECT
#- PROCESS-NAME,nvcontainer.exe,DIRECT
#- PROCESS-NAME,svchost.exe,DIRECT
#- PROCESS-NAME,HipsDaemon.exe,DIRECT
#- PROCESS-NAME,EpicGamesLauncher.exe,DIRECT

prepend-proxies: []

prepend-proxy-groups: []

append-rules: []

append-proxies: []

append-proxy-groups: []

原始链接: Clash Verge系列使用最佳实践
Lainbo订阅转换: Lainbo订阅转换
肥羊订阅转换: 肥羊订阅转换