-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlocal.pac
More file actions
85 lines (77 loc) · 1.89 KB
/
Copy pathlocal.pac
File metadata and controls
85 lines (77 loc) · 1.89 KB
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
function FindProxyForURL(url, host) {
const servers = [
{
"ip": "127.0.0.1",
"port": 20001,
"domains": []
},
{
"ip": "127.0.0.1",
"port": 20002,
"domains": []
},
{
"ip": "127.0.0.1",
"port": 20003,
"domains": []
},
{
"ip": "127.0.0.1",
"port": 20004,
"domains": [
"youtu.be",
"yuotube.com",
"googlevideo.com"
]
},
{
"ip": "127.0.0.1",
"port": 20005,
"domains": []
},
{
"ip": "127.0.0.1",
"port": 20006,
"domains": []
},
{
"ip": "127.0.0.1",
"port": 20007,
"domains": []
},
{
"ip": "127.0.0.1",
"port": 20008,
"domains": []
}
];
if (servers.length === 0) {
return "DIRECT";
}
const exactMap = new Map();
const suffixRules = [];
for (const [serverIndex, server] of servers.entries()) {
if (server.domains.length === 0) continue;
for (const domain of server.domains) {
const lowerDomain = domain.toLowerCase();
exactMap.set(lowerDomain, serverIndex);
suffixRules.push({
domain: `.${lowerDomain}`,
serverIndex: serverIndex
});
}
}
suffixRules.sort((a, b) => b.domain.length - a.domain.length);
const lowerHost = host.toLowerCase();
if (exactMap.has(lowerHost)) {
const server = servers[exactMap.get(lowerHost)];
return `SOCKS5 ${server.ip}:${server.port}`;
}
for (const {domain, serverIndex} of suffixRules) {
if (dnsDomainIs(lowerHost, domain)) {
const server = servers[serverIndex];
return `SOCKS5 ${server.ip}:${server.port}`;
}
}
return "DIRECT";
}