Adblock 规则定义

from

https://adblockplus.org/en/filter-cheatsheet

translated by linx

#简单的屏蔽规则

##例子 1: 根据网址的一部分屏蔽

1
/banner/*/img

该规则屏蔽:

1
2
3
http://example.com/banner/foo/img
http://example.com/banner/foo/bar/img?param
http://example.com/banner//img/foo

但不屏蔽:

1
2
3
http://example.com/banner/img
http://example.com/banner/foo/imgraph
http://example.com/banner/foo/img.gif

##例子 2: 根据域名屏蔽

1
||ads.example.com^

该规则屏蔽:

1
2
3
http://ads.example.com/foo.gif
http://server1.ads.example.com/foo.gif
https://ads.example.com:8000/

但不屏蔽:

1
2
http://ads.example.com.ua/foo.gif
http://example.com/redirect/http://ads.example.com/

##例子3: 屏蔽确定的地址

1
|http://example.com/|

该规则屏蔽:

1
http://example.com/

但不屏蔽:

1
2
http://example.com/foo.gif
http://example.info/redirect/http://example.com/

#屏蔽规则中的选项

1
||ads.example.com^$script,image,domain=example.com|~foo.example.info

该规则仅仅屏蔽 http://ads.example.com/foo.gif 但仅当一下条件满足时:

该地址是作为脚本或者图片加载时. 脚本或者图片加载自 example.com域名 (例如 example.com 自身或者 子域名.example.com) 但不是其多级子域名.

#白名单规则 用于在已有规则命中时, 加入一条例外

##例子 1: 特定请求中的例外

1
@@||ads.example.com/notbanner^$~script

##例子 2: 整个页面的例外

1
@@||example.com^$document

#注释

1
!这是一条注释

#过滤选项

1
2
script
~script

包含或者排除JavaScript脚本文件

1
2
image
~image

包含或者排除图像

1
2
stylesheet
~stylesheet

包含或者排除css

1
2
object
~object

包含或者排除由浏览器插件管理的内容,例如flash java

1
2
object-subrequest
~object-subrequest

包含或者排除由浏览器插件加载的文件

1
2
subdocument
~subdocument

包含或者排除页面的嵌入内容(frames)

1
document

用于排除页面本身 (e.g. @@||example.com^$document)

1
elemhide

用于防止元素规则应用于页面 (e.g. @@||example.com^$elemhide)

1
domain=

指定域名列表, 由竖线分隔 (|), 使过滤规则生效. 可以用波浪符号 (~) 来否定之.

1
2
third-party
~third-party

指明一个过滤规则是否应该处理第三方或者第一域

#元素隐藏(由 Element Hiding Helper for Adblock Plus 扩展使用) ##域名选择器 ##selector 占位符. ###advert 匹配拥有unique id为 “advert” 的元素 ##.advert 匹配拥有class id 为 “advert” 的元素 ##table[height="100"][width="100"] ##a[href="http://example.com/"] ##div[style="width:300px;height:250px;"] `

###advert > .link 匹配元素内部的关闭的link标签, 并且id为"advert" ##a[href^="http://example.com/"]

##div[style^="width:300px;height:250px;"] ##div[style$="width:300px;height:250px;"] ##div[style*="width:300px;height:250px;"]

记录平时瞎折腾遇到的各种问题, 方便查找
使用 Hugo 构建
主题 Stack 3.29.0Jimmy 设计