Last active
September 29, 2020 03:45
-
-
Save JaHIY/2861871 to your computer and use it in GitHub Desktop.
Javacript: My Pac File (some code from @ayanamist 's Pac File)
This file contains hidden or 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
var METHODS = { | |
PROXY_METHOD:"PROXY 127.0.0.1:8123", | |
NO_PROXY_METHOD:"DIRECT" | |
}, | |
rules = [ | |
".akamai.net", | |
".akamaihd.net", | |
".appspot.com", | |
".bitsnoop.com", | |
".blogspot.com", | |
".chinagfw.org", | |
".dotcloud.com", | |
".dropbox.com", | |
".facebook.com", | |
".fbcdn.net", | |
".fc2.com", | |
".flickr.com", | |
".getfoxyproxy.com", | |
".gist.github.com", | |
".google.com", | |
".google.co.jp", | |
".googleapis.com", | |
".googleusercontent.com", | |
".gstatic.com", | |
".isohunt.com", | |
".mediafire.com", | |
".mobypicture.com", | |
".pastebin.com", | |
".pixnet.net", | |
".simplecd.me", | |
"t.co", | |
".twitpic.com", | |
".twitter.com", | |
".twimg.com", | |
".wordpress.com", | |
".waigaobu.com", | |
".yfrog.com", | |
".youtube.com", | |
".ytimg.com" | |
], | |
global = (function(){return this || (1,eval)('this');})(); | |
function FindProxyForURL(url, host) { | |
var METHODS=global.METHODS; | |
function dnsDomainIs(domain) { | |
var host_length, domain_length; | |
return ((domain[0] === '.') ? (host === domain.slice(1) || ((host_length = host.length) >= (domain_length = domain.length) && host.slice(host_length - domain_length) === domain)) : (host === domain)); | |
} | |
function rule_filter(callback) { | |
var rules=global.rules, i=rules.length; | |
do { | |
if (callback(rules[--i]) === true) { | |
return true; | |
} | |
} while(i !== 0); | |
return false; | |
} | |
if (isPlainHostName(host) === true) { | |
return METHODS.NO_PROXY_METHOD; | |
} else { | |
if (rule_filter(dnsDomainIs) === true) { | |
return METHODS.PROXY_METHOD; | |
} else { | |
return METHODS.NO_PROXY_METHOD; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
基于 @ayanamist 的自用 PAC 文件 ( https://gist.github.com/1390732 ),仅使用了一个代理配置,重写了部分函数……仅支持域名匹配……咱暂时不需要用正则匹配,所以就没加上、