forked from 1a57danc3/gfvvlist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmono-unicode.js
79 lines (64 loc) · 1.61 KB
/
mono-unicode.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
/*
* Copyright (C) 2015 BlackGear
* https://github.com/BlackGear/Mono_PAC
*/
function merge(obj, key) {
obj[key] = 1;
return obj;
}
var tunnel = __proxyList__;
var direct = "DIRECT";
var whiteList = "__whiteList__".split("|").reduce(merge, {});
var blackList = "__blackList__".split("|").reduce(merge, {});
var codeList = __codeList__;
var maskList = __maskList__;
function FindProxyForURL(url, host) {
if (isPlainHostName(host)) {
return direct;
}
var domain = host;
var pos = 0;
do {
if (blackList.hasOwnProperty(domain)) {
return tunnel;
}
if (whiteList.hasOwnProperty(domain)) {
return direct;
}
pos = host.indexOf(".", pos) + 1;
domain = host.substring(pos);
} while (pos > 0);
var IP = dnsResolve(host);
if (!IP) {
return tunnel;
}
if (IP.indexOf(":") >= 0) {
return direct;
}
var atom = IP.split(".");
var code = ((atom[1] & 0xff) << 8) | ((atom[2] & 0xff));
var hash = atom[0];
var codeLine = codeList[hash];
var maskLine = maskList[hash];
if (codeLine === "") {
return tunnel;
}
if (maskLine === "10") {
return direct;
}
var min = 0;
var max = codeLine.length;
var mid = max >> 1;
do {
if (codeLine[mid].charCodeAt(0) > code) {
max = mid;
} else {
min = mid;
}
mid = (min + max) >> 1;
} while (min + 1 < max);
if (code - codeLine[min].charCodeAt(0) >> parseInt(maskLine[min], 16) === 0) {
return direct;
}
return tunnel;
}