Repository navigation
Expand file tree
/
Copy pathpac
More file actions
52 lines (48 loc) · 1.38 KB
/
Copy pathpac
File metadata and controls
52 lines (48 loc) · 1.38 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
var proxy = 'PROXY 127.0.0.1:10809;DIRECT;';
var rules = [
[
[],
[]
],
[
[
"ip138.com",
"youdao.com",
"zhongsou.com"
],
[
"ip.cn",
"zzux.com"
]
]
];
var lastRule = '';
function FindProxyForURL(url, host) {
for (var i = 0; i < rules.length; i++) {
ret = testHost(host, i);
if (ret != undefined)
return ret;
}
return 'DIRECT';
}
function testHost(host, index) {
for (var i = 0; i < rules[index].length; i++) {
for (var j = 0; j < rules[index][i].length; j++) {
lastRule = rules[index][i][j];
if (host == lastRule || host.endsWith('.' + lastRule))
return i % 2 == 0 ? 'DIRECT' : proxy;
}
}
lastRule = '';
}
if (!String.prototype.endsWith) {
String.prototype.endsWith = function(searchString, position) {
var subjectString = this.toString();
if (typeof position !== 'number' || !isFinite(position) || Math.floor(position) !== position || position > subjectString.length) {
position = subjectString.length;
}
position -= searchString.length;
var lastIndex = subjectString.indexOf(searchString, position);
return lastIndex !== -1 && lastIndex === position;
};
}