投稿信箱地址:chinagfwblog(at)gmail.com。
作者:dRq qx072009
有人抱怨PAC慢,目前网上见到的PAC写法主要是正则或
DomainIs,前者条目多时速度不理想,后者又过于死板长列表中很少使用。这里推荐一种不常见的写法。这个写法有如下优势:
* ChkDomain 主函数根据根域名进行分组,可以成组跳过大片记录
* IsDomain 函数
高效先比较域名长度,再从后向前比较域名是否匹配
简洁 “Google.com” 只匹配 *.Google.com 或 Google.com
* 脚本比较格式化仍然可以通过程序处理或生成
示例:
//确定一个主代理容易修改
var Current_Proxy = "SOCKS5 127.0.0.1:8580";
var No_Proxy = "DIRECT";
// .Onion
var TOR_Proxy = "PROXY 127.0.0.1:9050";
// 经常更改或需要程序化更改的条件放在了前面方便修改,
// 例如对``开头的Google搜索自动进行代理
var GoogleSearch_Str = "http://www.google.com/search*&q=``*";
// 再设置一个网站测试代理是否成功
var IPTest_Str = "ip-adress.com";
// //////////////////////////////////////////////////////////////////
// dRq, Apr 2009
// special thanks to no-ads author ;)
// //////////////////////////////////////////////////////////////////
var hLen = 0; // host长度
function FindProxyForURL(url, host) {
hLen = host.length;
//下面开始匹配,URI条件和域名条件的数量如果相差悬殊较少的可以放在前面
if (chkDomain(host)||chkMatch(host, url)) {
return Current_Proxy;
} else {
//Else放固定的专用代理,例如TOR的 .onion 只能用TOR
if (IsDomain(host, "onion")) {
return TOR_Proxy;
}
return No_Proxy;
}
}
// URL匹配列表
function chkMatch(host, url) {
var IsHost = false;
if (0 || shExpMatch(host, "*.epochtimes.*")
|| shExpMatch(host, "epochtimes.*")
|| shExpMatch(url, "http://www.voanews.com/chinese*")
|| shExpMatch(url, "http://www.voanews.com/vietnamese*")
|| shExpMatch(url, "http://*.bbc.co.uk/chinese*")
|| shExpMatch(url, "http://www.rfi.fr/actucn*")
|| shExpMatch(url, "http://feeds.*")
IsHost = true;
};
//复杂规则先domain避免大量无效匹配
if (IsDomain(host, "google.com")) {
if (0 || shExpMatch(url, "*http://??.??.???.???/search?q=cache:*")) {
|| shExpMatch(url, "http://images.google.com/images*q=``*")) {
//前面定义的 google 搜索 暗号``
|| shExpMatch(url, GoogleSearch_Str)
IsHost = true;
};
};
return IsHost;
}
//域名列表
function chkDomain(host) {
var IsHost = false;
//.com和.net域名很多如果能分开会快不少,分开!
switch (true) {
case IsDomain(host, "com") :
if (0 || IsDomain(host, "64memo.com")
|| IsDomain(host, "aboluowang.com")
|| IsDomain(host, "blogspot.com")
|| IsDomain(host, "chinaeweekly.com")
|| IsDomain(host, "dongtaiwang.com")
|| IsDomain(host, "epochtimes-bg.com")
|| IsDomain(host, "feeds.feedburner.com")
|| IsDomain(host, "groups.google.com")
|| IsDomain(host, "heartyit.com")
|| IsDomain(host, "wordpress.com")
|| IsDomain(host, "youtube.com")
//更多.com域名按格式括起来就可以了
// [tab]+|| IsDomain(host, "+域名+"))
IsHost = true;
break;
//。net
case IsDomain(host, "net") :
if (0 || IsDomain(host, "77sea.net")
|| IsDomain(host, "aiph.net")
|| IsDomain(host, "chinainperspective.net")
|| IsDomain(host, "dongtaiwang.net")
|| IsDomain(host, "freenet.sourceforge.net")
|| IsDomain(host, "huping.net")
|| IsDomain(host, "twitbrowser.net")
|| IsDomain(host, "tibetpost.net")
|| IsDomain(host, "xinsheng.net")
|| IsDomain(host, "wujie.net")
IsHost = true;
break;
//。org
case IsDomain(host, "org") :
if (0
|| IsDomain(host, "asiademo.org")
|| IsDomain(host, "bignews.org")
|| IsDomain(host, "chinaaffairs.org")
|| IsDomain(host, "delegate.org")
|| IsDomain(host, "cncitizen.org")
|| IsDomain(host, "freenetproject.org")
|| IsDomain(host, "grandtrial.org")
|| IsDomain(host, "rfa.org")
|| IsDomain(host, "zh.wikipedia.org"))
IsHost = true;
break;
//所有非.com/net/org域名都放在这里
default :
if (0 || IsDomain(host, "ccc.de")
|| IsDomain(host, "autonet.com.tw")
|| IsDomain(host, "bit.ly")
|| IsDomain(host, "soundofhope.or.kr")
|| IsDomain(host, "erabaru.or.id")
|| IsDomain(host, "gcbbs.info")
|| IsDomain(host, "libertytimes.com.tw")
|| IsDomain(host, "open.com.hk")
|| IsDomain(host, "rq2007.cc")
|| IsDomain(host, "rti.org.tw")
|| IsDomain(host, "ff.im")
|| IsDomain(host, "bit.ly")
|| IsDomain(host, "shenyun.us")
|| IsDomain(host, "videopedia.us")
|| IsDomain(host, "yoshow.com.tw")
|| IsDomain(host, "zyzg.us")
|| IsDomain(host, "velkaepocha.sk")
|| IsDomain(host, "cntv.us")
|| IsDomain(host, "cna.com.tw")
|| IsDomain(host, "boxun.us")
//插入最前面定义的代理测试网站
|| IsDomain(host, IPTest_Str))
IsHost = true;
break;
}
return IsHost;
}
//先长度后内容
function IsDomain(host, domain) {
var dLen = domain.length;
if (hLen > dLen) {
return (host.substring(hLen - dLen - 1) == "." + domain);
}
return (host == domain);
}
DomainIs,前者条目多时速度不理想,后者又过于死板长列表中很少使用。这里推荐一种不常见的写法。这个写法有如下优势:
* ChkDomain 主函数根据根域名进行分组,可以成组跳过大片记录
* IsDomain 函数
高效先比较域名长度,再从后向前比较域名是否匹配
简洁 “Google.com” 只匹配 *.Google.com 或 Google.com
* 脚本比较格式化仍然可以通过程序处理或生成
示例:
//确定一个主代理容易修改
var Current_Proxy = "SOCKS5 127.0.0.1:8580";
var No_Proxy = "DIRECT";
// .Onion
var TOR_Proxy = "PROXY 127.0.0.1:9050";
// 经常更改或需要程序化更改的条件放在了前面方便修改,
// 例如对``开头的Google搜索自动进行代理
var GoogleSearch_Str = "http://www.google.com/search*&q=``*";
// 再设置一个网站测试代理是否成功
var IPTest_Str = "ip-adress.com";
// //////////////////////////////////////////////////////////////////
// dRq, Apr 2009
// special thanks to no-ads author ;)
// //////////////////////////////////////////////////////////////////
var hLen = 0; // host长度
function FindProxyForURL(url, host) {
hLen = host.length;
//下面开始匹配,URI条件和域名条件的数量如果相差悬殊较少的可以放在前面
if (chkDomain(host)||chkMatch(host, url)) {
return Current_Proxy;
} else {
//Else放固定的专用代理,例如TOR的 .onion 只能用TOR
if (IsDomain(host, "onion")) {
return TOR_Proxy;
}
return No_Proxy;
}
}
// URL匹配列表
function chkMatch(host, url) {
var IsHost = false;
if (0 || shExpMatch(host, "*.epochtimes.*")
|| shExpMatch(host, "epochtimes.*")
|| shExpMatch(url, "http://www.voanews.com/chinese*")
|| shExpMatch(url, "http://www.voanews.com/vietnamese*")
|| shExpMatch(url, "http://*.bbc.co.uk/chinese*")
|| shExpMatch(url, "http://www.rfi.fr/actucn*")
|| shExpMatch(url, "http://feeds.*")
IsHost = true;
};
//复杂规则先domain避免大量无效匹配
if (IsDomain(host, "google.com")) {
if (0 || shExpMatch(url, "*http://??.??.???.???/search?q=cache:*")) {
|| shExpMatch(url, "http://images.google.com/images*q=``*")) {
//前面定义的 google 搜索 暗号``
|| shExpMatch(url, GoogleSearch_Str)
IsHost = true;
};
};
return IsHost;
}
//域名列表
function chkDomain(host) {
var IsHost = false;
//.com和.net域名很多如果能分开会快不少,分开!
switch (true) {
case IsDomain(host, "com") :
if (0 || IsDomain(host, "64memo.com")
|| IsDomain(host, "aboluowang.com")
|| IsDomain(host, "blogspot.com")
|| IsDomain(host, "chinaeweekly.com")
|| IsDomain(host, "dongtaiwang.com")
|| IsDomain(host, "epochtimes-bg.com")
|| IsDomain(host, "feeds.feedburner.com")
|| IsDomain(host, "groups.google.com")
|| IsDomain(host, "heartyit.com")
|| IsDomain(host, "wordpress.com")
|| IsDomain(host, "youtube.com")
//更多.com域名按格式括起来就可以了
// [tab]+|| IsDomain(host, "+域名+"))
IsHost = true;
break;
//。net
case IsDomain(host, "net") :
if (0 || IsDomain(host, "77sea.net")
|| IsDomain(host, "aiph.net")
|| IsDomain(host, "chinainperspective.net")
|| IsDomain(host, "dongtaiwang.net")
|| IsDomain(host, "freenet.sourceforge.net")
|| IsDomain(host, "huping.net")
|| IsDomain(host, "twitbrowser.net")
|| IsDomain(host, "tibetpost.net")
|| IsDomain(host, "xinsheng.net")
|| IsDomain(host, "wujie.net")
IsHost = true;
break;
//。org
case IsDomain(host, "org") :
if (0
|| IsDomain(host, "asiademo.org")
|| IsDomain(host, "bignews.org")
|| IsDomain(host, "chinaaffairs.org")
|| IsDomain(host, "delegate.org")
|| IsDomain(host, "cncitizen.org")
|| IsDomain(host, "freenetproject.org")
|| IsDomain(host, "grandtrial.org")
|| IsDomain(host, "rfa.org")
|| IsDomain(host, "zh.wikipedia.org"))
IsHost = true;
break;
//所有非.com/net/org域名都放在这里
default :
if (0 || IsDomain(host, "ccc.de")
|| IsDomain(host, "autonet.com.tw")
|| IsDomain(host, "bit.ly")
|| IsDomain(host, "soundofhope.or.kr")
|| IsDomain(host, "erabaru.or.id")
|| IsDomain(host, "gcbbs.info")
|| IsDomain(host, "libertytimes.com.tw")
|| IsDomain(host, "open.com.hk")
|| IsDomain(host, "rq2007.cc")
|| IsDomain(host, "rti.org.tw")
|| IsDomain(host, "ff.im")
|| IsDomain(host, "bit.ly")
|| IsDomain(host, "shenyun.us")
|| IsDomain(host, "videopedia.us")
|| IsDomain(host, "yoshow.com.tw")
|| IsDomain(host, "zyzg.us")
|| IsDomain(host, "velkaepocha.sk")
|| IsDomain(host, "cntv.us")
|| IsDomain(host, "cna.com.tw")
|| IsDomain(host, "boxun.us")
//插入最前面定义的代理测试网站
|| IsDomain(host, IPTest_Str))
IsHost = true;
break;
}
return IsHost;
}
//先长度后内容
function IsDomain(host, domain) {
var dLen = domain.length;
if (hLen > dLen) {
return (host.substring(hLen - dLen - 1) == "." + domain);
}
return (host == domain);
}
--
Posted By GFW Blog to GFW BLOG at 4/10/2010 08:06:00 PM --
1、请点击www.chinagfw.org访问我们,订阅地址:http://feeds2.feedburner.com/chinagfwblog。2、需要Psiphon2注册邀请的朋友,请向english@sesawe.net发送电子邮件请求,说明 "can I have psiphon2 access" 并告诉您所在的国家。也可以使用Twitter Direct Messages或登陆Psiphon网站直接向Psiphon索取使用邀请。3、GFW Blog现提供最新翻墙工具下载(地址一、二、三),翻墙(突破网络封锁)方法介绍请见本站anti-censorship部分。4、本站热烈欢迎各位朋友投稿或推荐文章,请发邮件至chinagfwblog[at]gmail.com。5、敬请关注、支持、参与Sesawe和黑箱监管集体诉讼。
To unsubscribe from this group, send email to
gfw-blog+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/gfw-blog?hl=zh-CN
没有评论:
发表评论