站内链接:

Adblock Plus Filter Rule

一种最常见的过滤规则格式, 其中firefox-autoproxy就是使用该格式, 简称为:autoproxy格式.
其中gfwlist/gfwlist.txt经过base64解码之后也是符合autoproxy格式

根据Ablock Plus来配置PAC, 增加自定义配置,其中pac原理见上面各个代理原理介绍文章介绍.

Rule

基本过滤规则

使用正则表达式进行匹配, 其中通配符有: *(任意多个), ?(任意一个), 根据一定的规则对匹配的
请求进行流量分流操作.

例外规则

@@–避免某一个规则的误伤操作,添加额外的白名单,”即该 HTTP 请求不走代理了哦”

匹配网址开头结尾

|:表示地址的最前端,最末端, 例如|http://example.com 或者 example.com|
||:协议http/https/www, 表示所有这些都匹配

分隔符

分隔符:除字母,数字,(_ - . %)之外的所有字符

注释

普通注释: !, 以感叹号开始的规则

特殊注释:

1
2
3
!Homepage: URL, 该过滤规则列表的首页
!Title:title, 标题
!Expired:5 days, 过滤规则列表更新

User-rule

不同于pac.txt, user-rule和pac-rule有一点细微的区别, 其中每一行代表一个URL通配符.

  • 通配符: *.example.com/*, 实际书写时可以省略*
  • 正则: 以\开始和结束, 例如\[\w]+:\/\/example.com\
  • 例外规则: @@
  • 开始和结尾: |, 例如|http://example.com
  • 协议:||, 例如||example.com匹配http://example.com, ftp://example.com
  • 注释: !

Example

gfwlist配置

利用python解码gfwlist.txt:

1
2
3
4
5
6
import base64
f1 = open('gfwlist.txt', 'r')
f2 = open('gfwlist_origin.txt', 'wb+')
base64.decode(f1, f2)
f1.close()
f2.close()

Output:

1
2
3
4
5
6
7
8
9
10
11
12
KV7Q
! Expires: 6h
! Title: GFWList4LL
! GFWList with EVERYTHING included
! Last Modified: Mon, 20 Nov 2017 19:12:20 -0500
!
! HomePage: https://github.com/gfwlist/gfwlist
...
!!---Google---
!###https://www.google.com/supported_domains###
.google.gr
||blog.google

配置例子

对于广告http://example.com/ads/banner124.gif,其中124经常变动,则使用规则:
http://example.com/ads/banner*.gif 进行匹配

配置: swf|会阻拦http://example.com/annoyingflash.swf,不会阻拦http://example.com/swf/index.html

||example.com/banner.gif会阻拦http://{value},https://{value}/other,不阻拦http://badexample.com/banner.gif

http://example.com^阻拦http://example.com/http://example.com:8000/,不能阻拦http://example.com.ar

引用: