forked from brookhong/Surfingkeys
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirefox_pac.js
38 lines (36 loc) · 1.03 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
var pacGlobal = {};
browser.runtime.onMessage.addListener((message) => {
pacGlobal = message;
if (pacGlobal.proxy.toLowerCase().indexOf("socks") === 0) {
var p = pacGlobal.proxy.split(" ");
var h = p[1].split(":");
pacGlobal.proxy = [{
type: p[0],
host: h[0],
port: h[1],
proxyDNS: true
}];
}
});
function FindProxyForURL(url, host) {
var lastPos;
if (pacGlobal.proxyMode === "always") {
return pacGlobal.proxy;
}
var gates = [pacGlobal.proxy, "DIRECT"];
if (pacGlobal.proxyMode === "bypass") {
gates = ["DIRECT", pacGlobal.proxy];
}
var pp = new RegExp(pacGlobal.autoproxy_pattern);
do {
if (pacGlobal.hosts.hasOwnProperty(host)) {
return gates[0];
}
if (pacGlobal.autoproxy_pattern.length && pp.test(host)) {
return gates[0];
}
lastPos = host.indexOf('.') + 1;
host = host.slice(lastPos);
} while (lastPos >= 1);
return gates[1];
}