-
-
Notifications
You must be signed in to change notification settings - Fork 486
/
firefox_pac.js
49 lines (47 loc) · 1.59 KB
/
firefox_pac.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
var pacGlobal = {};
browser.runtime.onMessage.addListener((message) => {
pacGlobal = message;
pacGlobal.proxy.forEach(function(proxy, i) {
if (proxy.toLowerCase().indexOf("socks") === 0) {
var p = proxy.split(" ");
var h = p[1].split(":");
pacGlobal.proxy[i] = [{
type: p[0],
host: h[0],
port: h[1],
proxyDNS: true
}];
}
});
});
function FindProxyForURL(url, host) {
var lastPos;
if (pacGlobal.proxyMode === "always") {
return pacGlobal.proxy[0];
} else if (pacGlobal.proxyMode === "bypass") {
var pp = new RegExp(pacGlobal.autoproxy_pattern[0]);
do {
if (pacGlobal.hosts[0].hasOwnProperty(host)
|| (pacGlobal.autoproxy_pattern[0].length && pp.test(host))) {
return "DIRECT";
}
lastPos = host.indexOf('.') + 1;
host = host.slice(lastPos);
} while (lastPos >= 1);
return pacGlobal.proxy[0];
} else {
for (var i = 0; i < pacGlobal.proxy.length; i++) {
var pp = new RegExp(pacGlobal.autoproxy_pattern[i]);
var ahost = host;
do {
if (pacGlobal.hosts[i].hasOwnProperty(ahost)
|| (pacGlobal.autoproxy_pattern[i].length && pp.test(ahost))) {
return pacGlobal.proxy[i];
}
lastPos = ahost.indexOf('.') + 1;
ahost = ahost.slice(lastPos);
} while (lastPos >= 1);
}
return "DIRECT";
}
}