-
Notifications
You must be signed in to change notification settings - Fork 1
/
sing-box-old.js
84 lines (76 loc) · 2.5 KB
/
sing-box-old.js
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
const {
type,
name
} = $arguments
const compatible_outbound = {
tag: 'COMPATIBLE',
type: '🍬 direct',
}
let compatible
let config = JSON.parse($files[0])
let originProxies = await produceArtifact({
name,
type: /^1$|col/i.test(type) ? 'collection' : 'subscription',
platform: 'sing-box',
produceType: 'internal',
})
// 提取和去除包含流量信息的节点
let nodeInfoTag = getTags(originProxies,/GB/i)[0];
let proxies = removeProxiesByRegex(originProxies,/GB/i)
// proxy 节点 tag 命令规则 🇸🇬 Singapore 01,执行操作后对应策略组tag命名规则 🇸🇬 Singapore
let countries = new Set();
proxies.map(obj => {
// 除去节点标号作为对应策略组的tag, eg:🇸🇬 Singapore
countries.add(obj.tag.split(' ').slice(0, -1).join(' '));
});
policyTagList = ["🍀 all", "🛍️ proxy", "🍬 direct", "🧬 auto", "🇨🇳 Taiwan"];
function Policy(tag, type) {
this.tag = tag;
this.type = type;
this.outbounds = [];
}
//===========================================
let proxy = new Policy("🛍️ proxy", "selector");
let auto = new Policy("🧬 auto", "urltest");
let openai = new Policy("openai", "urltest");
//===========================================
proxy.outbounds.push("auto", ...countries);
auto.outbounds.push(...getTags(proxies));
// 删除节点
openai.outbounds.push(...getOtherTags(proxies, /(taiwan|hong kong)/i));
//===========================================
config.outbounds.push(proxy, auto, openai);
countries.forEach(j => {
let country = new Policy(j, "urltest")
//
config.outbounds.push(country);
//
config.outbounds.map(i => {
if (j == i.tag) {
let regexPattern = i.tag;
let regex = new RegExp(regexPattern, 'i');
i.outbounds.push(...getTags(proxies, regex));
}
})
});
//===========================================
config.outbounds.forEach(outbound => {
if (Array.isArray(outbound.outbounds) && outbound.outbounds.length === 0) {
if (!compatible) {
config.outbounds.push(compatible_outbound)
compatible = true
}
outbound.outbounds.push(compatible_outbound.tag);
}
});
config.outbounds.push(...proxies)
$content = JSON.stringify(config, null, 2)
function removeProxiesByRegex(proxies, regex) {
return proxies.filter(proxy => !regex.test(proxy.tag));
}
function getOtherTags(proxies, regex) {
return (regex ? proxies.filter(p => !regex.test(p.tag)) : proxies).map(p => p.tag)
}
function getTags(proxies, regex) {
return (regex ? proxies.filter(p => regex.test(p.tag)) : proxies).map(p => p.tag)
}