2008年12月25日 星期四

介绍Opera用urlfilter.ini过滤广告的方法

Opera进入中国已经有些年头了,直到最近推出Opera中国版及Opera10 Alpha 测试版。但在广告过滤方面Opera 一直不内置任何过滤规则,官方也不提供任何规则包。Opera的这一立场,并不意味着Opera在广告过滤方面很弱,实际恰恰相反,只不过Opera的广告过滤需要用户DIY。
Opera可以用urlfilter.ini黑名单过滤广告,基本使用方法如下:

普通的广告过滤点击网页右键就可以进行,定制完成后Opera会生成一过滤黑名单urlfilter.ini默认保存为Opera\profile\urlfilter.ini。



有时候会遇到一些讨厌的广告,正常无法捕获拦截。可以先试试是否JS广告,确定后进行拦截。
为方便,先定制一个“客户端脚本”右键。
1、客户端脚本右键
客户端脚本这个右键,网络颇有好评的Opera定制版:极速版和白菜版都带有此功能,也可以将此右键提取出来。
Item, "客户端脚本"="Go to Page,"javascript:(function(){var es=document.getElementsByTagName('SCRIPT');if(es.length==0){return};var es_inline='';var es_linked='';var i_linked=0;var i_inline=0;var el_title='客户端脚本';var s='';for(var i=0;i<es.length;i++){if(es[i].src.length>1 && es_linked.indexOf(es[i].src)==-1){es_linked+='<a href=\''+es[i].src+'\' style=\'display:block;white-space:nowrap;overflow:hidden;padding-top:8px;padding-bottom:2px;font-size:9pt;\' target=\'_blank\'>'+es[i].src+'</a><iframe src=\''+es[i].src+'\' style=\'border:1px solid #ccc;width:100%%;\'></iframe><br />';i_linked++;}else{s=es[i].outerHTML;s=s.replace(/^\s*\n/, '').replace(/\s*$/, ''); if(s!=''){s=s.replace( /</g, '<' ).replace( />/g, '>' ).replace( /\[/g, '[' ).replace( /\]/g, ']' ).replace( /\r\n/g, '<br />' ).replace( /\n/g, '<br />' );es_inline+='<div style=\'border:1px solid #ccc;background-color:#fcfcfc;font:9pt 宋体,Curier !important;white-space:nowrap;overflow:auto;margin-bottom:8pt;color:green;padding:3px;\'>'+s+'</div>';i_inline++;}}}es_inline=((es_inline!='')?('<div id=\'es_inline\'>'+es_inline+'</div>'):'');es_inline=((es_inline!='')?('<div style=\'font:bold 8pt Tahoma;padding:3px;margin-bottom:3px;border-bottom:1px solid #eee;background-color:yellow;cursor:hand;\' onclick=\'document.getElementById(\u0022es_inline\u0022).style.display=(document.getElementById(\u0022es_inline\u0022).style.display==\u0022none\u0022)?\u0022block\u0022:\u0022none\u0022;this.innerText=(this.innerText.charCodeAt(0)==45)?this.innerText.replace(\u0022-\u0022,\u0022+\u0022):this.innerText.replace(\u0022+\u0022,\u0022-\u0022);this.scrollIntoView();\'>- 内嵌脚本'+' ('+i_inline+'): </div>'):'')+es_inline;es_linked=((es_linked!='')?('<div id=\'es_linked\'>'+es_linked+'</div>'):'');es_linked=((es_linked!='')?('<div style=\'font:bold 8pt Tahoma;padding:3px;margin-top:3px;border-bottom:1px solid #eee;background-color:yellow;cursor:hand;\' onclick=\'document.getElementById(\u0022es_linked\u0022).style.display=(document.getElementById(\u0022es_linked\u0022).style.display==\u0022none\u0022)?\u0022block\u0022:\u0022none\u0022;this.innerText=(this.innerText.charCodeAt(0)==45)?this.innerText.replace(\u0022-\u0022,\u0022+\u0022):this.innerText.replace(\u0022+\u0022,\u0022-\u0022);this.scrollIntoView();\'>- 外部脚本'+' ('+i_linked+'): </div>'):'')+es_linked;var w=window.open('');w.document.open();w.document.write('<html xmlns=\'http://www.w3.org/1999/xhtml\'><head><meta http-equiv=\'Content-Type\' content=\'text/html; charset=utf-8\' /><title>'+document.title+' - '+el_title+'</title></head><body style=\'padding:0;margin:0;margin-left:10%%;margin-right:10%%;background-color: #dfdfdf;font-size:8pt;font-family:tahoma;\'><div style=\'border:1px solid silver;\'><div style=\'height:5px;background-color:#990000;\'></div><div style=\'height:12px;padding:16px;border-bottom:1px solid silver;background-color: #f5f5f5;\'><div style=\'width:80%%;font-size:10.5pt;font-weight:bold;float:left;white-space:nowrap;overflow:hidden;\'>'+document.title+'</div><div style=\'font: normal 8pt tahoma;float:right;\'>'+el_title+'</div></div><div style=\'background-color:white;padding:8px;\'>');w.document.write(es_inline+es_linked+'</div></div></body></html>');w.document.close();})()""


2、图解说明




比较通用的过滤urlfilter.ini,希望没有误杀。
* 是通配符,urlfilter.ini黑名单对大小写字母敏感。
Opera Preferences version 2.1
; Do not edit this file while Opera is running
; This file is stored in UTF-8 encoding

[prefs]
prioritize excludelist=1

[include]
*

[exclude]
http://*_ads_*
http://*_ad_*
http://*_js/*_ad*.js
http://*_js/*_bottom.js
http://*_js/*_banner*.js
http://eiv.baidu.com/other/ff.js
http://eiv.baidu.com/maimg/*
http://*.ad.*
http://*.ad/*
http://*.ads.*
http://*/ads_*
http://*.ads/*
http://*.adsina.*
http://*.alimama.*/inf.js
http://*.skycn.*/js/*.js
http://*.swf?*AdID*
http://*.tianya.cn/js/global/tianyaRecommendSmallWindow*.js
http://*/AdShow/*
http://*/Ggao/*.gif
http://*/Ggao/*.htm
http://*/Ggao/*.jpg
http://*/Ggao/*.js
http://*/Ggao/*.swf
http://*/ad.*
http://*/ad/*
http://*/ad_banner.*
http://*/ad_js*
http://www.koowo.com/pa/www1.mtvtop.net/index-*.html
http://*/adfshow*
http://*/ads.*
http://*/ads/*
http://*/banner.*
http://*/button/*
http://*/gg/*
http://*/ggao/*.*gif
http://*/ggao/*.*htm
http://*/ggao/*.*jpg
http://*/ggao/*.*swf
http://*/images/*.js
http://*/images/*.swf
http://*/images/QQ*
http://*/images/ad*
http://*/js/baidu/top*
http://*/qq*.js
http://*/swf/logo.swf
http://*cpro.baidu*
http://*images/fra*.htm
http://*sogou.com/cpc_ads?pid*
http://80*.tianya.cn/*
http://ad4.*
http://ad.*
http://ads.*
http://baidutv.baidu.com/iknow.html?pt*
http://banner.*
http://banner/*
http://bannerads.*
http://bannerads/*
http://banners.*
http://banners/*
http://d1.sina.com.cn/*
http://ent.sina.com.cn/iframe/musicjs/importplayer.*.js
http://images*.html
http://images*.js
http://images.*/banners/*
http://img.*.swf
http://img.cnbeta.com/*.gif
http://imgad*
http://monitor.yigao.com/info.js
http://pagead*
http://sogou.com/cpc/*
http://*.tianya.*/tyad_*
http://pv.sohu.com/pv.gif?t?*
http://googleads.*
http://202.111.153.27/*
http://js.*.js
http://www.520wawa.com/js/ajaxXsl.js
http://s1.cr.itc.cn/sns/editor/crEmote.js
http://s*.cr.itc.cn/sns/widget/*.js
http://www.sohu.com/sohuflash_*.js
http://*/kaokaoni/*


可以查看当前网页所过滤的内容。

有时某个网页显示不正常,怀疑是广告拦截错误。我们可以暂时停止在此站点过滤广告以进行排查。


urlfilter.ini文件也可以保存在任意位置,然后在opera:config#URL Filter File中指定。

0 评论: