-
Notifications
You must be signed in to change notification settings - Fork 35
/
template.pac
73 lines (70 loc) · 2.18 KB
/
template.pac
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
/******默认代理和自定义规则可以在下面两行中配置:******/
var px=typeof _px !="undefined"&&_px?_px:"SOCKS 127.0.0.1:7070; DIRECT";//自定义默认proxy:1. http代理->PROXY host:port 2. socks代理-> SOCKS host:port
var myHosts=["githubusercontent.com","assets-cdn.github.com","xda-developers.com","fastly.net","cdn.sstatic.net","google.com","stripe.com","google.com.hk","cdn.infoqstatic.com","blogspot.com"];//自定义规则.放在一个数组里。比如["a.com","b.com","-v2ex.com"]默认是append,如果以减号"-"开头就是从gfwlist中删除
var encodedHosts=typeof _encodedHosts !="undefined"?_encodedHosts:"W10=";
function decode64(_1) {
var _2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
var _3 = "";
var _4, _5, _6;
var _7, _8, _9, _a;
var i = 0;
_1 = _1.replace(/[^A-Za-z0-9\+\/\=]/g, "");
do {
_7 = _2.indexOf(_1.charAt(i++));
_8 = _2.indexOf(_1.charAt(i++));
_9 = _2.indexOf(_1.charAt(i++));
_a = _2.indexOf(_1.charAt(i++));
_4 = (_7 << 2) | (_8 >> 4);
_5 = ((_8 & 15) << 4) | (_9 >> 2);
_6 = ((_9 & 3) << 6) | _a;
_3 = _3 + String.fromCharCode(_4);
if (_9 != 64) {
_3 = _3 + String.fromCharCode(_5);
}
if (_a != 64) {
_3 = _3 + String.fromCharCode(_6);
}
} while (i < _1.length);
return _3;
}
var hosts=eval(decode64(encodedHosts));
//处理自定义规则
if(myHosts&&myHosts.length){
var removeHosts=[];
for(var i=0;i<myHosts.length;i++){
if(myHosts[i].charAt(0)!='-')
hosts.push(myHosts[i]);
else
removeHosts.push(myHosts[i].substr(1));
}
if(removeHosts.length){
var tempHosts=[];
for(var i=0;i<hosts.length;i++){
var inRemovedHosts=false;
for(var j=0;j<removeHosts.length;j++){
if(removeHosts[j]==hosts[i]){
inRemovedHosts=true;
break;
}
}
if(!inRemovedHosts)
tempHosts.push(hosts[i]);
}
hosts=tempHosts;
}
}
var hostsObj={};
for(var i=0;i<hosts.length;i++){
hostsObj[hosts[i]]=true;
hosts[i]="."+hosts[i];
}
function FindProxyForURL(url, host) {
url = url.toLowerCase();
host = host.toLowerCase();
if(hostsObj[host])return px;
for(var i=0;i<hosts.length;i++){
if(host.substr(host.length-hosts[i].length)==hosts[i])
return px;
}
return "DIRECT";
}