-
Notifications
You must be signed in to change notification settings - Fork 1
/
singbox.js
53 lines (46 loc) · 1.53 KB
/
singbox.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
const { type, name } = $arguments;
const compatible_outbound = {
tag: 'COMPATIBLE',
type: 'block',
};
let compatible;
let config = JSON.parse($files[0]);
let proxies = await produceArtifact({
name,
type: /^1$|col/i.test(type) ? 'collection' : 'subscription',
platform: 'sing-box',
produceType: 'internal',
});
// console.log(config.outbounds);
config.outbounds.map(i => {
if ("outbounds" in i && i.outbounds.includes("{all}") && "filter" in i) {
i.outbounds = i.outbounds.filter(item => item != "{all}" && item != "block");
const p = getTags(proxies, i.filter[0].keywords[0]);
if (i.filter[0].action == "include") {
i.outbounds.push(...p);
} else if (i.filter[0].action == "exclude") {
i.outbounds.push(...(getTags(proxies).filter(item => !p.includes(item))));
}
delete i.filter;
} else if ("outbounds" in i && i.outbounds.includes("{all}") && !("filter" in i)) {
i.outbounds = i.outbounds.filter(item => item != "{all}");
i.outbounds.push(...getTags(proxies));
}
});
config.outbounds.push(...proxies);
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);
}
});
$content = JSON.stringify(config, null, 2);
function getTags(proxies, regex) {
if (regex) {
regex = new RegExp(regex);
}
return (regex ? proxies.filter(p => regex.test(p.tag)) : proxies).map(p => p.tag);
}