自编的小巧型广告通杀规则

普遍适用的规则分享、讨论

Moderator: phoenix

Post Reply
nepter
Posts: 30
Joined: Jan 14 2009, 15:36

自编的小巧型广告通杀规则

Post by nepter »

自编的小巧型广告通杀规则。基本思路是:
1. div里的id和class包含敏感字段的,把它display:none了。
2. iframe js img embed里引用的链接中含敏感字段的,把链接删了。

Code: Select all

Name = "all div ads"
Active = TRUE
URL = "$TST(FLT=0)"
Bounds = "<div[^>]+>"
Limit = 256
Match = "(*\s(id)=["']\0["']*|*\s(class)=["']\0["']*)\1>$TST(\0=(*[^a-z%]|)$LST(adkey)([^a-z]*|))"
Replace = " \1 style="display:none !important;">"

Name = "all iframe js img embed ads"
Active = TRUE
URL = "$TST(FLT=0)"
Bounds = "<(iframe|script|img|embed)[^>]+>"
Limit = 256
Match = "\1src=["']\w[^a-z%]$LST(adkey)[^a-z]\w["']\2"
Replace = "\1\2"
adkey是blocklist,比如adimg,adver,ggao,adlink等,另外把$TST(FLT=0)删了就能用了。
User avatar
phoenix
Site Admin
Posts: 529
Joined: Dec 29 2007, 16:27

Re: 自编的小巧型广告通杀规则

Post by phoenix »

取属性值可以用 $AV() 命令,你的那种方式没考虑到没有引号的情况,也没考虑到引号嵌套的情况。
This is used to match any attribute's value. It first parses and isolates the value - automatically taking things like quotes vs. no quotes into account. The match within the command is then limited to just the attribute value. Note: Any quotes surrounding the value will not be part of the match.
第一个规则可以把 id 和 class 写在一起,单独写的话没必要加括号,除非你要把它们放进某个变量;另外,也没必要取了值放进 \0 再 $TST() ,可以参考你的第二个规则那种方式。
nepter
Posts: 30
Joined: Jan 14 2009, 15:36

Re: 自编的小巧型广告通杀规则

Post by nepter »

$AV()和读取顺序的问题没想明白,刚一试全想明白了。本来也用$AV,后来一些问题没搞清楚就不用了,现在想清楚了。谢谢了

Code: Select all

Name = "all div ads"
Active = TRUE
URL = "$TYPE(htm)"
Bounds = "<div[^>]+>"
Limit = 512
Match = "(*\s(id|class)=$AV((*[^a-z%]|)$LST(adkey)([^a-z]*|))*)\1>"
Replace = " \1 style="display:none !important;">"

Name = "all iframe js img embed ads"
Active = TRUE
URL = "$TYPE(htm)"
Bounds = "<(iframe|script|img|embed)[^>]+>"
Limit = 256
Match = "\#src=$AV((*[^a-z%]|)$LST(adkey)([^a-z]*|))\#"
Replace = "\@"
Post Reply