-
-
Save holys/4018360 to your computer and use it in GitHub Desktop.
PAC that uses a white list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*global isPlainHostName, isInNet*/ | |
var proxy = "SOCKS5 127.0.0.1:9999; SOCKS 127.0.0.1:9999; DIRECT"; | |
var noProxy = "DIRECT"; | |
var localhosts = [ | |
['192.168.0.0', '255.255.0.0'], | |
['10.0.0.0', '255.0.0.0'], | |
['172.0.0.0', '255.0.0.0'], | |
['127.0.0.0', '255.255.255.0'] | |
]; | |
var gi, whiteListed = {}, whiteList = [ | |
"alipay.com", | |
"alipayobjects.com", | |
"baidu.com", | |
"com.cn", | |
"douban.com", | |
"edu.cn", | |
"feidee.com", | |
"icast.cn", | |
"kandian.com", | |
"mmcdn.cn", | |
"mmstat.com", | |
"renren.com", | |
"sinaapp.com", | |
"sinaimg.cn", | |
"sinajs.cn", | |
"tanx.com", | |
"taobao.com", | |
"taobaocdn.com", | |
"tbcdn.cn", | |
"v2ex.com", | |
"weibo.com" | |
]; | |
for (gi = 0; gi < whiteList.length; gi += 1) { whiteListed[whiteList[gi]] = true; } | |
function isLocal(host) { | |
var i, ip, netmask; | |
if (isPlainHostName(host)) { return true; } | |
for (i = 0; i < localhosts.length; i++) { | |
ip = localhosts[i][0]; | |
netmask = localhosts[i][1]; | |
if (isInNet(host, ip, netmask)) { return true; } | |
} | |
return false; | |
} | |
function hostToDomain(host) { | |
var dotpos = host.lastIndexOf("."); | |
if (dotpos === -1) { return host; } | |
// Find the second last dot | |
dotpos = host.lastIndexOf(".", dotpos - 1); | |
if (dotpos === -1) { return host; } | |
return host.substring(dotpos + 1); | |
} | |
function FindProxyForURL(url, host) { | |
if (isLocal(host)) { return noProxy; } | |
return (whiteListed[hostToDomain(host)] ? noProxy : proxy); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment