How to create your own ad filters
如何创建您自己的广告过滤器
In this article, we explain how to write custom filtering rules for use in AdGuard products. To test your rules, you can download the AdGuard app
在本文中,我们将解释如何编写在 AdGuard 产品中使用的自定义过滤规则。要测试您的规则,您可以下载 AdGuard 应用程序
A filter is a set of filtering rules applied to specific content, such as banners or pop-ups. AdGuard has a list of standard filters created by our team. We constantly improve and update them, striving to meet the needs of most of our users.
过滤器是一组应用于特定内容(例如横幅或弹出窗口)的过滤规则。 AdGuard 有我们团队创建的标准过滤器列表。我们不断改进和更新它们,努力满足大多数用户的需求。
At the same time, AdGuard allows you to create your own custom filters using the same types of rules that we have in our filters.
同时,AdGuard 允许您使用与我们过滤器中相同类型的规则来创建自己的自定义过滤器。
To describe the syntax of our filtering rules, we use Augmented BNF for Syntax Specifications, but we do not always strictly follow this specification.
为了描述过滤规则的语法,我们使用增强 BNF 语法规范,但我们并不总是严格遵循此规范。
Originally, the AdGuard's syntax was based on the syntax of Adblock Plus rules. Later, we extended it with new types of rules for better ad filtering. Some parts of this article about the rules common both to AdGuard and ABP were taken from the Adblock Plus guide on how to write filters.
最初,AdGuard 的语法是基于 Adblock Plus 规则的语法。后来,我们用新类型的规则对其进行了扩展,以实现更好的广告过滤。本文中有关 AdGuard 和 ABP 通用规则的某些部分摘自有关如何编写过滤器的 Adblock Plus 指南。
Comments 评论
Any line that starts with an exclamation mark is a comment. In the list of rules it is displayed in gray color. AdGuard will ignore this line, so you can write anything you want. Comments are usually placed above the rules and used to describe what a rule does.
任何以感叹号开头的行都是注释。在规则列表中,它以灰色显示。 AdGuard 将忽略这一行,因此您可以编写任何您想要的内容。注释通常放置在规则之上,用于描述规则的作用。
For example: 例如:
! This is the comment. Below this line, there is an actual filtering rule.
||example.org^
Examples 示例
Blocking by domain name 通过域名屏蔽
This rule blocks: 该规则阻止:
http://example.org/ad1.gif
http://subdomain.example.org/ad1.gif
https://ads.example.org:8000/
This rule does not block:
该规则不会阻止:
http://ads.example.org.us/ad1.gif
http://example.com/redirect/http://ads.example.org/
By default, such rules do not work for document requests. This means that the ||example.org^
rule will block a request made to example.org
when you try to navigate to this domain from another website, but if you type example.org
into the address bar and try to navigate to it, the website will open. To block the document request, you will need to use a rule with the $document
modifier: ||example.org^$document
.
默认情况下,此类规则不适用于文档请求。这意味着当您尝试从另一个网站导航到该域时, ||example.org^
规则将阻止向example.org
发出的请求,但如果您在地址栏中键入example.org
并尝试导航到它,网站将打开。要阻止文档请求,您需要使用带有$document
修饰符的规则: ||example.org^$document
。
Blocking exact address 阻止确切地址
This rule blocks: 该规则阻止:
http://example.org/
This rule does not block:
该规则不会阻止:
https://example.org/banner/img
Basic rule modifiers 基本规则修改器
Filtering rules support numerous modifiers that allow you to fine-tune the rule behavior. Here is an example of a rule with some simple modifiers.
过滤规则支持多种修饰符,允许您微调规则行为。下面是带有一些简单修饰符的规则示例。
This rule blocks: 该规则阻止:
http://example.org/script.js
if this script is loaded fromexample.com
.http://example.org/script.js
如果此脚本是从example.com
加载的。
This rule does not block:
该规则不会阻止:
https://example.org/script.js
if this script is loaded fromexample.org
.https://example.org/script.js
如果此脚本是从example.org
加载的。https://example.org/banner.png
because it is not a script.
https://example.org/banner.png
因为它不是脚本。
Unblocking an address 解锁地址
This rule unblocks: 此规则解锁:
http://example.org/banner.png
even if there is a blocking rule for this address.http://example.org/banner.png
即使该地址有阻止规则。
Blocking rules with $important
modifier can override exceptions.
使用$important
修饰符阻止规则可以覆盖异常。
Unblocking an entire website
解锁整个网站
This rule unblocks 这条规则解锁
- It disables all cosmetic rules on
example.com
.
它禁用example.com
上的所有修饰规则。 - It unblocks all requests sent from this website even if there is are blocking rules matching these requests.
即使存在与这些请求匹配的阻止规则,它也会取消阻止从此网站发送的所有请求。
Cosmetic rule 美容法则
Cosmetic rules are based on using a special language named CSS, which every browser understands. Basically, it adds a new CSS style to the website which purpose is to hide particular elements. You can learn more about CSS in general here.
外观规则基于使用一种名为 CSS 的特殊语言,每个浏览器都能理解这种语言。基本上,它向网站添加了新的 CSS 样式,其目的是隐藏特定元素。您可以在此处了解有关 CSS 的更多一般信息。
AdGuard extends CSS and lets filters developers handle much more complicated cases. However, to use these extended rules, you need to be fluent in regular CSS.
AdGuard扩展了 CSS ,让过滤器开发人员可以处理更复杂的情况。但是,要使用这些扩展规则,您需要精通常规 CSS。
Popular CSS selectors 流行的 CSS 选择器
Name 姓名 | CSS selector CSS 选择器 | Description 描述 |
---|---|---|
ID selector ID选择器 | #banners | Matches all elements with id attribute equal to banners .匹配 id 属性等于banners 的所有元素。![]() |
Class selector 类选择器 | .banners | Matches all elements with class attribute containing banners .匹配 class 属性包含banners 的所有元素。![]() |
Attribute selector 属性选择器 | div[class="banners"] | Matches all div elements with class attribute exactly equal to banners .匹配 class 属性完全等于banners 的所有div 元素。![]() |
Attribute substring selector 属性子串选择器 | div[class^="advert1"] | Matches all div elements which class attribute starts with the advert1 string.匹配 class 属性以advert1 字符串开头的所有div 元素。![]() |
Attribute substring selector 属性子串选择器 | div[class$="banners_ads"] | Matches all div elements which class attribute ends with the banners_ads string.匹配 class 属性以banners_ads 字符串结尾的所有div 元素。![]() |
Attribute substring selector 属性子串选择器 | a[href^="http://example.com/"] | Matches all links that are loaded from http://example.com/ domain.匹配从 http://example.com/ 域加载的所有链接。![]() |
Attribute selector 属性选择器 | a[href="http://example.com/"] | Matches all links to exactly the http://example.com/ address.将所有链接与 http://example.com/ 地址完全匹配。![]() |
Restrictions and limitations
限制和限制
Trusted filters 值得信赖的过滤器
Some rules can be used only in trusted filters. This category includes:
某些规则只能在受信任的过滤器中使用。该类别包括:
- filter lists created by the AdGuard team,
AdGuard 团队创建的过滤器列表, - custom filter lists installed as
trusted
,
自定义过滤器列表安装为trusted
, - user rules. 用户规则。
AdGuard Content Blocker AdGuard 内容拦截器
AdGuard Content Blocker is an extension for Samsung and Yandex browsers that can be installed from Google Play.
It is not to be confused with the fully functional AdGuard for Android that can only be downloaded from
our website. Unfortunately, AdGuard Content Blocker capabilities
are limited by what the browsers allow and they only support an old Adblock Plus filters syntax:
AdGuard Content Blocker 是 Samsung 和 Yandex 浏览器的扩展,可以从 Google Play 安装。
不要将其与功能齐全的 Android 版 AdGuard 相混淆,后者只能从
我们的网站。不幸的是,AdGuard 内容拦截器的功能受到浏览器允许的限制,并且它们仅支持旧的 Adblock Plus 过滤器语法:
- Basic blocking rules with the following modifiers:
$domain
,$third-party
, content-type modifiers.
具有以下修饰符的基本阻止规则:$domain
、$third-party
、 content-type modifiers 。 - Basic exception rules with the following modifiers:
$document
,$elemhide
.
具有以下修饰符的基本异常规则:$document
、$elemhide
。 - Basic element hiding rules with no extended CSS support.
没有扩展 CSS 支持的基本元素隐藏规则。
Because of the limitations above AdGuard Content Blocker will not be mentioned in the compatibility notes.
由于上述限制,AdGuard Content Blocker 将不会在兼容性说明中提及。
Basic rules 基本规则
The most simple rules are so-called Basic rules. They are used to block requests to specific URLs. Or to unblock it, if there is a special marker "@@" at the beginning of the rule.
最简单的规则就是所谓的基本规则。它们用于阻止对特定 URL 的请求。或者解除阻止,如果规则开头有特殊标记“@@”。
The basic principle for this type of rules is quite simple: you have to specify the address and additional parameters that limit or expand the rule scope.
此类规则的基本原理非常简单:您必须指定限制或扩展规则范围的地址和附加参数。
Basic rules for blocking requests are applied only to sub-requests. That means they will not block the loading of the page unless it is explicitly specified with a $document
modifier.
阻止请求的基本规则仅适用于子请求。这意味着它们不会阻止页面的加载,除非使用$document
修饰符显式指定。
Browser detects a blocked request as completed with an error.
浏览器检测到已阻止的请求已完成但有错误。
Rules shorter than 4 characters are considered incorrect and will be ignored.
少于 4 个字符的规则将被视为不正确并将被忽略。
Basic rule syntax 基本规则语法
rule = ["@@"] pattern [ "$" modifiers ]
modifiers = [modifier0, modifier1[, ...[, modifierN]]]
pattern
— an address mask. Every request URL is collated to this mask. In the template, you can also use the special characters described below. Note that AdGuard truncates URLs to a length of 4096 characters in order to speed up matching and avoid issues with ridiculously long URLs.pattern
——地址掩码。每个请求 URL 都会与此掩码进行比较。在模板中,您还可以使用下面描述的特殊字符。请注意,AdGuard 将 URL 截断为 4096 个字符的长度,以加快匹配速度并避免出现 URL 过长的问题。@@
— a marker that is used in rules of exception. To turn off filtering for a request, start your rule with this marker.@@
— 在例外规则中使用的标记。要关闭对请求的过滤,请使用此标记开始您的规则。modifiers
— parameters that "clarify" the basic rule. Some of them limit the rule scope and some can completely change they way it works.modifiers
——“阐明”基本规则的参数。其中一些限制规则范围,一些可以完全改变规则的工作方式。
Special characters 特殊字符
*
— a wildcard character. It is used to represent any set of characters. This can also be an empty string or a string of any length.*
— 通配符。它用于表示任何字符集。这也可以是空字符串或任意长度的字符串。||
— an indication to apply the rule to the specified domain and its subdomains. With this character, you do not have to specify a particular protocol and subdomain in address mask. It means that||
stands forhttp://*.
,https://*.
,ws://*.
,wss://*.
at once.||
— 将规则应用于指定域及其子域的指示。使用此字符,您不必在地址掩码中指定特定协议和子域。这意味着||
代表http://*.
,https://*.
,ws://*.
,wss://*.
立刻。^
— a separator character mark. Separator character is any character, but a letter, a digit, or one of the following:_
-
.
%
. In this example separator characters are shown in bold:http:
//
example.com
/?
t=1
&
t2=t3
. The end of the address is also accepted as separator.^
— 分隔符标记。分隔符可以是任何字符,但字母、数字或以下字符之一:_
-
.
%
。在此示例中example.com
分隔符以粗体显示:http:
//
/?
t=1
&
t2=t3
。地址末尾也可以作为分隔符。|
— a pointer to the beginning or the end of address. The value depends on the character placement in the mask. For example, a ruleswf|
corresponds tohttp://example.com/annoyingflash.swf
, but not tohttp://example.com/swf/index.html
.|http://example.org
corresponds tohttp://example.org
, but not tohttp://domain.com?url=http://example.org
.|
— 指向地址开头或结尾的指针。该值取决于蒙版中的字符位置。例如,规则swf|
对应于http://example.com/annoyingflash.swf
,但不至于http://example.com/swf/index.html
。|http://example.org
对应于http://example.org
,但不对应于http://domain.com?url=http://example.org
。
|
, ||
, ^
can only be used with rules that have a URL pattern. For example, ||example.com##.advert
is incorrect and will be ignored by the blocker.|
, ||
, ^
只能与具有 URL 模式的规则一起使用。例如, ||example.com##.advert
不正确,将被拦截器忽略。
We also recommend to get acquainted with the Adblock Plus filter cheatsheet, for better understanding of how such rules should be made.
我们还建议您熟悉Adblock Plus 过滤器备忘单,以便更好地了解如何制定此类规则。
Regular expressions support
正则表达式支持
If you want even more flexibility in making rules, you can use Regular expressions instead of a default simplified mask with special characters.
如果您希望在制定规则时更加灵活,可以使用正则表达式而不是带有特殊字符的默认简化掩码。
Rules with regular expressions work more slowly, therefore it is recommended to avoid them or to limit their scope to specific domains.
使用正则表达式的规则运行速度较慢,因此建议避免使用它们或将其范围限制在特定域。
If you want a blocker to determine a regular expression, the pattern
has to look like this:
如果您希望阻止程序确定正则表达式, pattern
必须如下所示:
pattern = "/" regexp "/"
For example, /banner\d+/$third-party
this rule will apply the regular expression banner\d+
to all third-party requests. Exclusion rule with regular expression looks like this: @@/banner\d+/
.
例如, /banner\d+/$third-party
该规则将把正则表达式banner\d+
应用于所有第三方请求。正则表达式的排除规则如下所示: @@/banner\d+/
。
AdGuard Safari and AdGuard for iOS do not fully support regular expressions because of Content Blocking API restrictions (look for "The Regular expression format" section).
由于内容阻止 API 限制, AdGuard Safari 和 AdGuard for iOS 不完全支持正则表达式(请查找“正则表达式格式”部分)。
Wildcard support for TLD (top-level domains)
TLD(顶级域)的通配符支持
Wildcard characters are supported for TLDs of the domains in patterns of cosmetic, HTML filtering and JavaScript rules.
域的 TLD 支持通配符,格式为修饰、 HTML 过滤和JavaScript规则。
For cosmetic rules, e.g. example.*##.banner
, multiple domains are matched due to the part .*
, i.e. example.com
, sub.example.net
, example.co.uk
, etc.
对于修饰规则,例如example.*##.banner
,由于.*
部分而匹配多个域,即example.com
、 sub.example.net
、 example.co.uk
等。
For basic rules the described logic is applicable only for the domains specified in $domain
modifier, e.g. ||*/banners/*$image,domain=example.*
.
对于基本规则,所描述的逻辑仅适用于$domain
修饰符中指定的域,例如 ||*/banners/*$image,domain=example.*
。
In AdGuard for Windows, Mac, Android, and AdGuard Browser Extension rules with wildcard .*
match any public suffix (or eTLD). But for AdGuard for Safari and iOS the supported list of top-level domains is limited due to Safari limitations.
在 AdGuard for Windows、Mac、Android 和 AdGuard 浏览器扩展规则中,带有通配符.*
规则与任何公共后缀(或 eTLD)匹配。但对于适用于 Safari 和 iOS 的 AdGuard,由于 Safari 的限制,支持的顶级域列表有限。
Rules with wildcard for TLD are not supported by AdGuard Content Blocker.
AdGuard 内容拦截器不支持 TLD 通配符规则。
Basic rule examples 基本规则示例
||example.com/ads/*
— a simple rule, which corresponds to addresses likehttp://example.com/ads/banner.jpg
and evenhttp://subdomain.example.com/ads/otherbanner.jpg
.||example.com/ads/*
— 一个简单的规则,对应于如下地址http://example.com/ads/banner.jpg
甚至http://subdomain.example.com/ads/otherbanner.jpg
。||example.org^$third-party
— this rule blocks third-party requests toexample.org
and its subdomains.||example.org^$third-party
— 此规则阻止第三方对example.org
及其子域的请求。@@||example.com$document
— general exception rule. It completely disables filtering forexample.com
and all subdomains. There is a number of modifiers which can be used in exception rules. For more details, please follow the link below.@@||example.com$document
— 一般例外规则。它完全禁用对example.com
和所有子域的过滤。有许多修饰符可以在异常规则中使用。欲了解更多详情,请点击以下链接。
Basic rule modifiers 基本规则修改器
The features described in this section are intended for experienced users. They extend capabilities of "Basic rules", but in order to use them you need to have a basic understanding of the way your browser works.
本节中描述的功能适用于有经验的用户。它们扩展了“基本规则”的功能,但为了使用它们,您需要对浏览器的工作方式有基本的了解。
You can change the behavior of a "basic rule" by using additional modifiers. Modifiers should be located in the end of the rule after a $
sign and be separated by commas.
您可以使用其他修饰符来更改“基本规则”的行为。修饰符应位于规则末尾的$
符号之后,并用逗号分隔。
Example: 例子:
||domain.com^$popup,third-party
Basic modifiers 基本修饰符
The following modifiers are the most simple and frequently used.
Basically, they just limit the scope of rule application.
以下修饰符是最简单且最常用的。基本上,它们只是限制了规则的应用范围。
Modifier \ Products 改性剂\产品 | CoreLibs apps CoreLibs 应用程序 | AdGuard for Chromium 适用于 Chromium 的 AdGuard | AdGuard for Chrome MV3 适用于 Chrome 的 AdGuard MV3 | AdGuard for Firefox 适用于 Firefox 的 AdGuard | AdGuard for iOS iOS 版 AdGuard | AdGuard for Safari 适用于 Safari 的 AdGuard | AdGuard Content Blocker AdGuard 内容拦截器 |
---|---|---|---|---|---|---|---|
$app $应用程序 | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
$denyallow | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ |
$domain $域名 | ✅ | ✅ | ✅ *[1] | ✅ | ✅ *[1] | ✅ *[1] | ✅ |
$header $标头 | ✅ | ✅ *[2] | ❌ | ✅ *[2] | ❌ | ❌ | ❌ |
$important $重要 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ |
$match-case $匹配大小写 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
$method $方法 | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ |
$popup $弹出窗口 | ✅ *[3] | ✅ | ✅ *[3] | ✅ | ✅ *[3] | ✅ *[3] | ❌ |
$strict-first-party $严格第一方 | ⏳ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
$strict-third-party $严格第三方 | ⏳ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
$third-party $第三方 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
$to $至 | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ |
- ✅ — fully supported ✅ — 完全支持
- ✅ * — supported, but reliability may vary or limitations may occur; check the modifier description for more details
✅ * — 支持,但可靠性可能会有所不同或可能会出现限制;检查修改器描述以获取更多详细信息 - ⏳ — feature that is planned to be implemented but is not yet available in any product
⏳ — 计划实现但尚未在任何产品中提供的功能 - ❌ — not supported ❌ — 不支持
$app
This modifier lets you narrow the rule coverage down to a specific application (or a list of applications). This might be not too important on Windows and Mac, but this is very important on mobile devices where some of the filtering rules must be app-specific.
此修饰符可让您将规则覆盖范围缩小到特定应用程序(或应用程序列表)。这在 Windows 和 Mac 上可能不太重要,但在移动设备上非常重要,其中某些过滤规则必须特定于应用程序。
- Android — use the app package name, e.g.
org.example.app
.
Android — 使用应用程序包名称,例如org.example.app
。 - Windows — use the process name, e.g.
chrome.exe
.
Windows — 使用进程名称,例如chrome.exe
。 - Mac — use the bundle ID or the process name, e.g.
com.google.Chrome
.
Mac — 使用捆绑 ID 或进程名称,例如com.google.Chrome
。
For Mac, you can find out the bundle ID or the process name of the app by viewing the respective request details in the Filtering log.
对于 Mac,您可以通过查看过滤日志中的相应请求详细信息来查找应用程序的捆绑包 ID 或进程名称。
Examples 示例
||baddomain.com^$app=org.example.app
— a rule to block requests that match the specified mask and are sent from theorg.example.app
Android app.
||baddomain.com^$app=org.example.app
— 阻止与指定掩码匹配并从org.example.app
Android 应用发送的请求的规则。||baddomain.com^$app=org.example.app1|org.example.app2
— the same rule but it works for bothorg.example.app1
andorg.example.app2
apps.
||baddomain.com^$app=org.example.app1|org.example.app2
— 相同的规则,但它适用于org.example.app1
和org.example.app2
应用程序。
If you want the rule not to be applied to certain apps, start the app name with the ~
sign.
如果您希望规则不应用于某些应用程序,请以~
符号开头应用程序名称。
||baddomain.com^$app=~org.example.app
— a rule to block requests that match the specified mask and are sent from any app except for theorg.example.app
.
||baddomain.com^$app=~org.example.app
— 阻止与指定掩码匹配且从除org.example.app
之外的任何应用程序发送的请求的规则。||baddomain.com^$app=~org.example.app1|~org.example.app2
— same as above, but now two apps are excluded:org.example.app1
andorg.example.app2
.
||baddomain.com^$app=~org.example.app1|~org.example.app2
— 与上面相同,但现在排除了两个应用程序:org.example.app1
和org.example.app2
。
Apps in the modifier value cannot have a wildcard, e.g. $app=com.*.music
.
Rules with such modifier are considered invalid.
修饰符值中的应用程序不能有通配符,例如$app=com.*.music
。具有此类修饰符的规则被视为无效。
- Only AdGuard for Windows, Mac, Android are technically capable of using rules with
$app
modifier.
从技术上讲,只有适用于 Windows、Mac、Android 的 AdGuard 能够使用带有$app
修饰符的规则。 - On Windows the process name is case-insensitive starting with AdGuard for Windows with CoreLibs v1.12 or later.
在 Windows 上,从带有CoreLibs v1.12 或更高版本的 AdGuard for Windows 开始,进程名称不区分大小写。
$denyallow
$denyallow
modifier allows to avoid creating additional rules when it is needed to disable a certain rule for specific domains. $denyallow
matches only target domains and not referrer domains.$denyallow
修饰符允许在需要禁用特定域的特定规则时避免创建额外的规则。 $denyallow
仅匹配目标域而不匹配引荐来源域。
Adding this modifier to a rule is equivalent to excluding the domains by the rule's matching pattern or to adding the corresponding exclusion rules. To add multiple domains to one rule, use the |
character as a separator.
向规则添加此修饰符相当于通过规则的匹配模式排除域或添加相应的排除规则。要将多个域添加到一条规则,请使用|
字符作为分隔符。
Examples 示例
This rule: 这条规则:
*$script,domain=a.com|b.com,denyallow=x.com|y.com
is equivalent to this one:
相当于这个:
/^(?!.*(x.com|y.com)).*$/$script,domain=a.com|b.com
or to the combination of these three:
或这三者的组合:
*$script,domain=a.com|b.com
@@||x.com$script,domain=a.com|b.com
@@||y.com$script,domain=a.com|b.com
- The rule's matching pattern cannot target any specific domains, e.g. it cannot start with
||
.
规则的匹配模式不能针对任何特定域,例如它不能以||
开头。 。 - Domains in the modifier value cannot be negated, e.g.
$denyallow=~x.com
, or have a wildcard TLD, e.g.$denyallow=x.*
, or be a regular expression, e.g.$denyallow=/\.(com\|org)/
.
修饰符值中的域不能被否定,例如$denyallow=~x.com
,或者具有通配符 TLD,例如$denyallow=x.*
,或者是正则表达式,例如$denyallow=/\.(com\|org)/
. $denyallow
cannot be used together with$to
. It can be expressed with inverted$to
:$denyallow=a.com|b.com
is equivalent to$to=~a.com|~b.com
.$denyallow
不能与$to
一起使用。它可以用倒置的$to
表示:$denyallow=a.com|b.com
相当于$to=~a.com|~b.com
。
The rules which violate these restrictions are considered invalid.
违反这些限制的规则被视为无效。
Rules with $denyallow
modifier are not supported by AdGuard for iOS, Safari, and AdGuard Content Blocker.
适用于 iOS、Safari 的 AdGuard 和 AdGuard 内容拦截器不支持带有$denyallow
修饰符的规则。
$domain
$domain
limits the rule scope to requests made from the specified domains and their subdomains (as indicated by the Referer HTTP header).$domain
将规则范围限制为从指定域及其子域发出的请求(如Referer HTTP 标头所示)。
Syntax 句法
The modifier is a list of one or more expressions separated by the |
symbol, each of which is matched against a domain in a particular way depending on its type (see below).
修饰符是由|
分隔的一个或多个表达式的列表。符号,每个符号根据其类型以特定方式与域匹配(见下文)。
domains = ["~"] entry_0 ["|" ["~"] entry_1 ["|" ["~"]entry_2 ["|" ... ["|" ["~"]entry_N]]]]
entry_i = ( regular_domain / any_tld_domain / regexp )
regular_domain
— a regular domain name (domain.com
). Corresponds the specified domain and its subdomains. It is matched lexicographically.regular_domain
— 常规域名 (domain.com
)。对应指定的域及其子域。它是按字典顺序匹配的。any_tld_domain
— a domain name ending with a wildcard character as a public suffix, e.g. forexample.*
it isco.uk
inexample.co.uk
. Corresponds to the specified domain and its subdomains with any public suffix. It is matched lexicographically.any_tld_domain
— 以通配符结尾的域名作为公共后缀,例如example.*
它是example.co.uk
中的co.uk
。对应于指定的域及其带有任何公共后缀的子域。它是按字典顺序匹配的。regexp
— a regular expression, starts and ends with/
. The pattern works the same way as in the basic URL rules, but the characters/
,$
,,
, and|
must be escaped with\
.regexp
— 正则表达式,以/
开头和结尾。该模式的工作方式与基本 URL 规则相同,但字符/
、$
、,
和|
必须用\
转义。
Rules with $domain
modifier as regular_domain
are supported by all AdGuard products.
所有 AdGuard 产品都支持以$domain
修饰符作为regular_domain
的规则。
Examples 示例
Just $domain
:
只是$domain
:
||baddomain.com^$domain=example.org
blocks requests that match the specified mask, and are sent from domainexample.org
or its subdomains.
||baddomain.com^$domain=example.org
阻止与指定掩码匹配并从域example.org
或其子域发送的请求。||baddomain.com^$domain=example.org|example.com
— the same rule, but it works for bothexample.org
andexample.com
.
||baddomain.com^$domain=example.org|example.com
— 相同的规则,但它适用于example.org
和example.com
。
If you want the rule not to be applied to certain domains, start a domain name with ~
sign.
如果您希望规则不应用于某些域,请以~
符号开头的域名。
$domain
and negation ~
:$domain
和否定~
:
||baddomain.com^$domain=example.org
blocks requests that match the specified mask and are sent from theexample.org
domain or its subdomains.
||baddomain.com^$domain=example.org
阻止与指定掩码匹配并从example.org
域或其子域发送的请求。||baddomain.com^$domain=example.org|example.com
— the same rule, but it works for bothexample.org
andexample.com
.
||baddomain.com^$domain=example.org|example.com
— 相同的规则,但它适用于example.org
和example.com
。||baddomain.com^$domain=~example.org
blocks requests matching the pattern sent from any domain exceptexample.org
and its subdomains.
||baddomain.com^$domain=~example.org
阻止与除example.org
及其子域之外的任何域发送的模式匹配的请求。||baddomain.com^$domain=example.org|~foo.example.org
blocks requests sent fromexample.org
and its subdomains, except the subdomainfoo.example.org
.
||baddomain.com^$domain=example.org|~foo.example.org
阻止从example.org
及其子域(子域foo.example.org
除外)发送的请求。||baddomain.com^$domain=/(^\|.+\.)example\.(com\|org)\$/
blocks requests sent fromexample.org
andexample.com
domains and all their subdomains.
||baddomain.com^$domain=/(^\|.+\.)example\.(com\|org)\$/
阻止从example.org
和example.com
域及其所有子域发送的请求。||baddomain.com^$domain=~a.com|~b.*|~/(^\|.+\.)c\.(com\|org)\$/
blocks requests sent from any domains, excepta.com
,b
with any public suffix (b.com
,b.co.uk
, etc.),c.com
,c.org
, and their subdomains.
||baddomain.com^$domain=~a.com|~b.*|~/(^\|.+\.)c\.(com\|org)\$/
阻止从任何域发送的请求,除了a.com
、带有任何公共后缀(b.com
、b.co.uk
等)的b
、c.com
、c.org
及其子域。
$domain
modifier matching target domain:$domain
修饰符匹配目标域:
In some cases the $domain
modifier can match not only the referrer domain, but also the target domain. This happens when all the following conditions are met:
在某些情况下, $domain
修饰符不仅可以匹配引用域,还可以匹配目标域。当满足以下所有条件时会发生这种情况:
- The request has the
document
content type
请求具有document
内容类型 - The rule pattern does not match any particular domains
规则模式不匹配任何特定域 - The rule pattern does not contain regular expressions
规则模式不包含正则表达式 - The
$domain
modifier contains only excluded domains, e.g.$domain=~example.org|~example.com
$domain
修饰符仅包含排除的域,例如$domain=~example.org|~example.com
The following predicate should be satisfied to perform a target domain matching:
应满足以下谓词才能执行目标域匹配:
1 AND ((2 AND 3) OR 4)
That is, if the modifier $domain
contains only excluded domains, then the rule does not need to meet the second and third conditions to match the target domain against the modifier $domain
.
也就是说,如果修饰符$domain
仅包含排除的域,则规则不需要满足第二个和第三个条件即可将目标域与修饰符$domain
进行匹配。
If some of the conditions above are not met but the rule contains $cookie
or $csp
modifier, the target domain will still be matched.
如果不满足上述某些条件,但规则包含$cookie
或$csp
修饰符,则仍会匹配目标域。
If the referrer matches a rule with $domain
that explicitly excludes the referrer domain, then the rule will not be applied even if the target domain also matches the rule. This affects rules with $cookie
and $csp
modifiers, too.
如果引荐来源网址与$domain
显式排除引荐来源网址域的规则相匹配,则即使目标域也匹配该规则,也不会应用该规则。这也会影响带有$cookie
和$csp
修饰符的规则。
Examples 示例
*$cookie,domain=example.org|example.com
will block cookies for all requests to and fromexample.org
andexample.com
.
*$cookie,domain=example.org|example.com
将阻止来自example.org
和example.com
的所有请求的 cookie。*$document,domain=example.org|example.com
will block all requests to and fromexample.org
andexample.com
.
*$document,domain=example.org|example.com
将阻止所有发往和来自example.org
和example.com
请求。
In the following examples it is implied that requests are sent from http://example.org/page
(the referrer) and the target URL is http://targetdomain.com/page
.
在以下示例中,暗示请求是从http://example.org/page
(引荐来源网址)发送的,目标 URL 是http://targetdomain.com/page
。
page$domain=example.org
will be matched, as it matches the referrer domain.page$domain=example.org
将被匹配,因为它与引荐来源网址匹配。page$domain=targetdomain.com
will be matched, as it matches the target domain and satisfies all requirements mentioned above.page$domain=targetdomain.com
将被匹配,因为它匹配目标域并满足上述所有要求。||*page$domain=targetdomain.com
will not be matched, as the pattern||*page
may match specific domains, e.g.example.page
.
||*page$domain=targetdomain.com
将不匹配,因为模式||*page
可能匹配特定域,例如example.page
。||*page$domain=targetdomain.com,cookie
will be matched because the rule contains$cookie
modifier despite the pattern||*page
may match specific domains.
||*page$domain=targetdomain.com,cookie
将被匹配,因为规则包含$cookie
修饰符,尽管模式||*page
可能匹配特定域。/banner\d+/$domain=targetdomain.com
will not be matched as it contains a regular expression.
/banner\d+/$domain=targetdomain.com
将不会被匹配,因为它包含正则表达式。page$domain=targetdomain.com|~example.org
will not be matched because the referrer domain is explicitly excluded.
page$domain=targetdomain.com|~example.org
不会匹配,因为引用域已被明确排除。
$domain
modifier limitations
$domain
修饰符限制
In AdGuard for Chrome MV3, regexp
and any_tld_domain
entries are not supported.
在AdGuard for Chrome MV3中,不支持regexp
和any_tld_domain
条目。
Safari does not support the simultaneous use of allowed and disallowed domains, so rules like ||baddomain.com^$domain=example.org|~foo.example.org
will not work in AdGuard for iOS and AdGuard for Safari.
Safari 不支持同时使用允许和不允许的域,因此如下规则 ||baddomain.com^$domain=example.org|~foo.example.org
不适用于 iOS 版 AdGuard 和 Safari 版 AdGuard。
Rules with regular expressions in the $domain
modifier are supported by AdGuard for Windows, AdGuard for Mac, and AdGuard for Android with CoreLibs v1.11 or later, and AdGuard Browser Extension with TSUrlFilter v3.0.0 or later.
使用CoreLibs v1.11 或更高版本的 AdGuard for Windows、AdGuard for Mac 和 AdGuard for Android 以及带有TSUrlFilter v3.0.0 或更高版本的 AdGuard 浏览器扩展支持$domain
修饰符中包含正则表达式的规则。
In AdGuard for Windows, Mac and Android with CoreLibs v1.12 or later the $domain
modifier can be alternatively spelled as $from
.
在带有CoreLibs v1.12 或更高版本的 Windows、Mac 和 Android 版 AdGuard 中, $domain
修饰符也可以拼写为$from
。
$header
The $header
modifier allows matching the HTTP response having a specific header with (optionally) a specific value.$header
修饰符允许将具有特定标头的 HTTP 响应与(可选)特定值进行匹配。
Syntax 句法
$header "=" h_name [":" h_value]
h_value = string / regexp
where: 在哪里:
h_name
— required, an HTTP header name. It is matched case-insensitively.h_name
— 必需,HTTP 标头名称。它的匹配不区分大小写。h_value
— optional, an HTTP header value matching expression, it may be one of the following:h_value
— 可选,HTTP 标头值匹配表达式,它可能是以下之一:string
— a sequence of characters. It is matched against the header value lexicographically;string
— 字符序列。它按字典顺序与标头值进行匹配;regexp
— a regular expression, starts and ends with/
. The pattern works the same way as in the basic URL rules, but the characters/
,$
and,
must be escaped with\
.regexp
— 正则表达式,以/
开头和结尾。该模式的工作方式与基本 URL 规则相同,但字符/
、$
和,
必须用\
转义。
The modifier part, ":" h_value
, may be omitted. In that case, the modifier matches the header name only.
修饰符部分":" h_value
可以省略。在这种情况下,修饰符仅匹配标头名称。
Examples 示例
||example.com^$header=set-cookie:foo
blocks requests whose responses have theSet-Cookie
header with the value matchingfoo
literally.
||example.com^$header=set-cookie:foo
阻止其响应具有Set-Cookie
标头且其值与字面匹配foo
的请求。||example.com^$header=set-cookie
blocks requests whose responses have theSet-Cookie
header with any value.
||example.com^$header=set-cookie
阻止其响应具有任意值的Set-Cookie
标头的请求。@@||example.com^$header=set-cookie:/foo\, bar\$/
unblocks requests whose responses have theSet-Cookie
header with value matching thefoo, bar$
regular expression.
@@||example.com^$header=set-cookie:/foo\, bar\$/
取消阻止其响应具有Set-Cookie
标头且其值与foo, bar$
正则表达式匹配的请求。@@||example.com^$header=set-cookie
unblocks requests whose responses have aSet-Cookie
header with any value.
@@||example.com^$header=set-cookie
取消阻止其响应具有任意值的Set-Cookie
标头的请求。
$header
modifier limitations
$header
修饰符限制
- The
$header
modifier can be matched only when headers are received. So if the request is blocked or redirected at an earlier stage, the modifier cannot be applied.
仅当收到标头时,$header
修饰符才能匹配。因此,如果请求在较早阶段被阻止或重定向,则无法应用修饰符。 - In Adguard Browser Extension, the
$header
modifier is only compatible with$csp
,$removeheader
,$important
, and$badfilter
.
在 Adguard 浏览器扩展中,$header
修饰符仅兼容$csp
、$removeheader
、$important
和$badfilter
。
Rules with the $header
modifier are supported by AdGuard for Windows, AdGuard for Mac, and AdGuard for Android
with CoreLibs v1.11 or later, and AdGuard Browser Extension with TSUrlFilter v3.0.0 or later.
使用CoreLibs v1.11 或更高版本的 AdGuard for Windows、AdGuard for Mac 和 AdGuard for Android 以及带有TSUrlFilter v3.0.0 或更高版本的 AdGuard 浏览器扩展支持使用$header
修饰符的规则。
$important
The $important
modifier applied to a rule increases its priority over rules without the identical modifier. Even over basic exception rules.
应用于规则的$important
修饰符会提高其相对于没有相同修饰符的规则的优先级。甚至超越基本的例外规则。
Go to rules priorities for more details.
请参阅规则优先级了解更多详细信息。
Examples 示例
! blocking rule will block all requests despite of the exception rule
||example.org^$important
@@||example.org^
! if the exception rule also has `$important` modifier, it will prevail and requests won't be blocked
||example.org^$important
@@||example.org^$important
$match-case
This modifier defines a rule which applies only to addresses that match the case. Default rules are case-insensitive.
此修饰符定义仅适用于与大小写匹配的地址的规则。默认规则不区分大小写。
Examples 示例
*/BannerAd.gif$match-case
— this rule will blockhttp://example.com/BannerAd.gif
, but nothttp://example.com/bannerad.gif
.*/BannerAd.gif$match-case
— 此规则将被阻止http://example.com/BannerAd.gif
,但不是http://example.com/bannerad.gif
。
Rules with the $match-case
are supported by AdGuard for iOS and AdGuard for Safari with SafariConverterLib v2.0.43 or later.
AdGuard for iOS 和 AdGuard for Safari 以及 SafariConverterLib v2.0.43 或更高版本支持使用$match-case
规则。
All other products already support this modifier.
所有其他产品都已支持此修饰符。
$method
This modifier limits the rule scope to requests that use the specified set of HTTP methods. Negated methods are allowed. The methods must be specified in all lowercase characters, but are matched case-insensitively. To add multiple methods to one rule, use the vertical bar |
as a separator.
此修饰符将规则范围限制为使用指定 HTTP 方法集的请求。允许否定方法。方法必须全部以小写字符指定,但匹配时不区分大小写。要将多种方法添加到一条规则,请使用竖线|
作为分隔符。
Examples 示例
||evil.com^$method=get|head
blocks only GET and HEAD requests toevil.com
.||evil.com^$method=get|head
仅阻止对evil.com
GET 和 HEAD 请求。||evil.com^$method=~post|~put
blocks any requests toevil.com
except POST or PUT.||evil.com^$method=~post|~put
会阻止对evil.com
的任何请求(POST 或 PUT 除外)。@@||evil.com$method=get
unblocks only GET requests toevil.com
.@@||evil.com$method=get
仅解除阻止对evil.com
的 GET 请求。@@||evil.com$method=~post
unblocks any requests toevil.com
except POST.@@||evil.com$method=~post
取消阻止除 POST 之外的任何对evil.com
的请求。
Rules with mixed negated and not negated values are considered invalid.
So, for example, the rule ||evil.com^$method=get|~head
will be ignored.
具有混合否定值和非否定值的规则被视为无效。因此,例如,规则||evil.com^$method=get|~head
将被忽略。
Rules with $method
modifier are supported by AdGuard for Windows, AdGuard for Mac, and AdGuard for Android with CoreLibs v1.12 or later, and AdGuard Browser Extension for Chrome, Firefox, and Edge with TSUrlFilter v2.1.1 or later.
带$method
修饰符的规则受具有CoreLibs v1.12 或更高版本的 AdGuard for Windows、AdGuard for Mac 和 AdGuard for Android 以及具有TSUrlFilter v2.1.1 或更高版本的适用于 Chrome、Firefox 和 Edge 的 AdGuard 浏览器扩展支持。
$popup
AdGuard will try to close the browser tab with any address that matches a blocking rule with this modifier. Please note that not all the tabs can be closed.
AdGuard 将尝试关闭具有此修饰符的阻止规则匹配的任何地址的浏览器选项卡。请注意,并非所有选项卡都可以关闭。
Examples 示例
||domain.com^$popup
— if you try to go tohttp://domain.com/
from any page in the browser, a new tab in which specified site has to be opened will be closed by this rule.||domain.com^$popup
— 如果您尝试从浏览器中的任何页面访问http://domain.com/
,则此规则将关闭必须打开指定站点的新选项卡。
$popup
modifier limitations
$popup
修饰符限制
- The
$popup
modifier works best in AdGuard Browser Extension for Chromium-based browsers and Firefox.$popup
修饰符在基于 Chromium 的浏览器和 Firefox 的 AdGuard 浏览器扩展中效果最佳。 - In AdGuard for Chrome MV3 rules with the
$popup
modifier would not work, so we disable converting them to declarative rules. We will try to use them only in our TSUrlFilter engine and close new tabs programmatically.
在AdGuard for Chrome MV3中,带有$popup
修饰符的规则不起作用,因此我们禁止将它们转换为声明性规则。我们将尝试仅在TSUrlFilter引擎中使用它们,并以编程方式关闭新选项卡。 - In AdGuard for iOS and AdGuard for Safari,
$popup
rules simply block the page right away.
在 AdGuard for iOS 和 AdGuard for Safari 中,$popup
规则只是立即阻止页面。 - In AdGuard for Windows, AdGuard for Mac, and AdGuard for Android, the
$popup
modifier may not detect a popup in some cases and it will not be blocked. The$popup
modifier applies thedocument
content type with a special flag which is passed to a blocking page. Blocking page itself can do some checks and close the window if it is really a popup. Otherwise, page should be loaded. It can be combined with other request type modifiers, such as$third-party
,$strict-third-party
,$strict-first-party
, and$important
.
在 AdGuard for Windows、AdGuard for Mac 和 AdGuard for Android 中,$popup
修饰符在某些情况下可能无法检测到弹出窗口,并且不会被阻止。$popup
修饰符应用带有特殊标志的document
内容类型,该标志被传递到阻塞页面。阻止页面本身可以进行一些检查,如果确实是弹出窗口,则关闭窗口。否则,应该加载页面。它可以与其他请求类型修饰符结合使用,例如$third-party
、$strict-third-party
、$strict-first-party
和$important
。
Rules with the $popup
modifier are not supported by AdGuard Content Blocker.
AdGuard 内容拦截器不支持带有$popup
修饰符的规则。
$strict-first-party
Works the same as the $~third-party
modifier, but only treats the request as first-party if the referrer and origin have exactly the same hostname.
与$~third-party
修饰符的工作方式相同,但仅当引荐来源网址和来源具有完全相同的主机名时才将请求视为第一方。
Examples 示例
- domain.com$strict-first-party' — this rule applies only to
domain.com
. For example, a request fromdomain.com
tohttp://domain.com/icon.ico
is a first-party request. A request fromsub.domain.com
tohttp://domain.com/icon.ico
is treated as a third-party one (as opposed to the$~third-party
modifier).
domain.com$strict-first-party' — 此规则仅适用于domain.com
。例如,从domain.com
到http://domain.com/icon.ico
的请求是第一方请求。从sub.domain.com
到http://domain.com/icon.ico
的请求被视为第三方请求(而不是$~third-party
修饰符)。
You can use a shorter name (alias) instead of using the full modifier name: $strict1p
.
您可以使用较短的名称(别名)而不是使用完整的修饰符名称: $strict1p
。
$strict-third-party
Works the same as the $third-party
modifier but also treats requests from the domain to its subdomains and vice versa as third-party requests.
与$third-party
修饰符的工作方式相同,但也将从域到其子域的请求视为第三方请求,反之亦然。
Examples 示例
||domain.com^$strict-third-party
— this rule applies to all domains exceptdomain.com
. An example of a third-party request:http://sub.domain.com/banner.jpg
(as opposed to the$third-party
modifier).
||domain.com^$strict-third-party
— 此规则适用于除domain.com
之外的所有域。第三方请求的示例:http://sub.domain.com/banner.jpg
(与$third-party
修饰符相对)。
You can use a shorter name (alias) instead of using the full modifier name: $strict3p
.
您可以使用较短的名称(别名)而不是使用完整的修饰符名称: $strict3p
。
$third-party
A restriction on third-party and custom requests. A third-party request is a request from an external domain. For example, a request to example.org
from domain.com
is a third-party request.
对第三方和自定义请求的限制。第三方请求是来自外部域的请求。例如,从domain.com
向example.org
发出的请求就是第三方请求。
To be considered as such, a third-party request should meet one of the following conditions:
要被视为此类请求,第三方请求应满足以下条件之一:
- Its referrer is not a subdomain of the target domain or vice versa. For example, a request to
subdomain.example.org
fromexample.org
is not a third-party request
它的引荐来源网址不是目标域的子域,反之亦然。例如,从example.org
到subdomain.example.org
的请求不是第三方请求 - Its
Sec-Fetch-Site
header is set tocross-site
其Sec-Fetch-Site
标头设置为cross-site
Examples 示例
$third-party
:$third-party
:
||domain.com^$third-party
— this rule applies to all domains, exceptdomain.com
and its subdomains. An example of a third-party request:http://example.org/banner.jpg
.||domain.com^$third-party
— 此规则适用于所有域,domain.com
及其子域除外。第三方请求的示例:http:http://example.org/banner.jpg
。
If there is a $~third-party
modifier, the rule is only applied to the requests that are not from third parties. Which means, they have to be sent from the same domain.
如果有$~third-party
修饰符,则该规则仅适用于非第三方的请求。这意味着,它们必须从同一域发送。
$~third-party
:$~third-party
:
||domain.com$~third-party
— this rule is applied exclusively todomain.com
. Example of a non third-party request:http://domain.com/icon.ico
.||domain.com$~third-party
— 此规则仅适用于domain.com
。非第三方请求示例:http:http://domain.com/icon.ico
。
You may use a shorter name (alias) instead of using the full modifier name: $3p
.
您可以使用较短的名称(别名)而不是使用完整的修饰符名称: $3p
。
$to
$to
limits the rule scope to requests made to the specified domains and their subdomains. To add multiple domains to one rule, use the |
character as a separator.$to
将规则范围限制为对指定域及其子域发出的请求。要将多个域添加到一条规则,请使用|
字符作为分隔符。
Examples 示例
/ads$to=evil.com|evil.org
blocks any request toevil.com
orevil.org
and their subdomains with a path matching/ads
./ads$to=evil.com|evil.org
阻止任何对evil.com
或evil.org
及其子域的请求,其路径与/ads
匹配。/ads$to=~not.evil.com|evil.com
blocks any request toevil.com
and its subdomains, with a path matching/ads
, except requests tonot.evil.com
and its subdomains.
/ads$to=~not.evil.com|evil.com
阻止任何路径与/ads
匹配的对evil.com
及其子域的请求,对not.evil.com
及其子域的请求除外。/ads$to=~good.com|~good.org
blocks any request with a path matching/ads
, except requests togood.com
orgood.org
and their subdomains./ads$to=~good.com|~good.org
阻止路径与/ads
匹配的任何请求,但对good.com
或good.org
及其子域的请求除外。
$denyallow
cannot be used together with $to
. It can be expressed with inverted $to
: $denyallow=a.com|b.com
is equivalent to $to=~a.com|~b.com
.$denyallow
不能与$to
一起使用。它可以用倒置的$to
表示: $denyallow=a.com|b.com
相当于$to=~a.com|~b.com
。
Rules with the $to
modifier are supported by AdGuard for Windows, AdGuard for Mac, and AdGuard for Android with CoreLibs v1.12 or later, and AdGuard Browser Extension with TSUrlFilter v2.1.3 or later.
使用CoreLibs v1.12 或更高版本的 AdGuard for Windows、AdGuard for Mac 和 AdGuard for Android 以及带有TSUrlFilter v2.1.3 或更高版本的 AdGuard 浏览器扩展支持带有$to
修饰符的规则。
Content-type modifiers 内容类型修饰符
There is a set of modifiers, which can be used to limit the rule's application area to certain type of content. These modifiers can also be combined to cover, for example, both images and scripts.
有一组修饰符,可用于将规则的应用范围限制为特定类型的内容。这些修饰符还可以组合起来以覆盖例如图像和脚本。
There is a big difference in how AdGuard determines the content type on different platforms.
For AdGuard Browser Extension, content type for every request is provided by the browser.
AdGuard 在不同平台上确定内容类型的方式存在很大差异。
对于 AdGuard 浏览器扩展,每个请求的内容类型均由浏览器提供。
AdGuard for Windows, Mac, and Android use the following method:
first, the apps try to determine the type of the request by the Sec-Fetch-Dest
request header or by the filename extension.
If the request is not blocked at this stage,
the type will be determined using the Content-Type
header at the beginning of the server response.
适用于 Windows、Mac 和 Android 的 AdGuard 使用以下方法:
首先,应用程序尝试通过Sec-Fetch-Dest
请求标头或文件扩展名来确定请求的类型。如果在此阶段请求未被阻止,则将使用服务器响应开头的Content-Type
标头来确定类型。
Examples of content-type modifiers
内容类型修饰符的示例
||example.org^$image
— corresponds to all images fromexample.org
.||example.org^$image
— 对应于example.org
中的所有图像。||example.org^$script,stylesheet
— corresponds to all the scripts and styles fromexample.org
.
||example.org^$script,stylesheet
— 对应于example.org
中的所有脚本和样式。||example.org^$~image,~script,~stylesheet
— corresponds to all requests toexample.org
except for the images, scripts and styles.
||example.org^$~image,~script,~stylesheet
— 对应于对example.org
的所有请求,图像、脚本和样式除外。
Modifier \ Products 改性剂\产品 | CoreLibs apps CoreLibs 应用程序 | AdGuard for Chromium 适用于 Chromium 的 AdGuard | AdGuard for Chrome MV3 适用于 Chrome 的 AdGuard MV3 | AdGuard for Firefox 适用于 Firefox 的 AdGuard | AdGuard for iOS iOS 版 AdGuard | AdGuard for Safari 适用于 Safari 的 AdGuard | AdGuard Content Blocker AdGuard 内容拦截器 |
---|---|---|---|---|---|---|---|
$document $文档 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ |
$font $字体 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
$image $图像 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
$media $媒体 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
$object $对象 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
$other $其他 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ |
$ping | ✅ *[1] | ✅ | ✅ | ✅ | ❌ | ❌ | ✅ |
$script $脚本 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
$stylesheet $样式表 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
$subdocument $子文档 | ✅ *[2] | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ |
$websocket | ✅ | ✅ | ✅ | ✅ | ✅ *[3] | ✅ *[3] | ❌ |
$xmlhttprequest $xmlhttp请求 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
$webrtc 🚫 $webrtc🚫 | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
$object-subrequest 🚫 $对象子请求🚫 | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
- ✅ — fully supported ✅ — 完全支持
- ✅ * — supported, but reliability may vary or limitations may occur; check the modifier description for more details
✅ * — 支持,但可靠性可能会有所不同或可能会出现限制;检查修改器描述以获取更多详细信息 - ❌ — not supported ❌ — 不支持
- 🚫 — removed and no longer supported
🚫 — 已删除且不再受支持
$document
The rule corresponds to the main frame document requests, i.e. HTML documents that are loaded in the browser tab. It does not match iframes, there is a $subdocument
modifier for these.
该规则对应于主框架文档请求,即在浏览器选项卡中加载的 HTML 文档。它与 iframe 不匹配,有一个$subdocument
修饰符。
By default, AdGuard does not block the requests that are loaded in the browser tab (e.g. "main frame bypass"). The idea is not to prevent pages from loading as the user clearly indicated that they want this page to be loaded. However, if the $document
modifier is specified explicitly, AdGuard does not use that logic and prevents the page load. Instead, it responds with a "blocking page".
默认情况下,AdGuard 不会阻止浏览器选项卡中加载的请求(例如“主机绕过”)。这个想法并不是阻止页面加载,因为用户明确表示他们希望加载此页面。但是,如果显式指定$document
修饰符,AdGuard 不会使用该逻辑并阻止页面加载。相反,它以“阻止页面”响应。
If this modifier is used with an exclusion rule (@@
), it completely disables blocking on corresponding pages. It is equivalent to using $elemhide
, $content
, $urlblock
, $jsinject
, $extension
modifiers simultaneously.
如果此修饰符与排除规则 ( @@
) 一起使用,则会完全禁用相应页面上的阻止。它相当于同时使用$elemhide
、 $content
、 $urlblock
、 $jsinject
、 $extension
修饰符。
Examples 示例
@@||example.com^$document
completely disables filtering on all pages atexample.com
and all subdomains.@@||example.com^$document
完全禁用对example.com
和所有子域的所有页面的过滤。||example.com^$document
blocks HTML document request toexample.com
with a blocking page.||example.com^$document
使用阻止页面阻止对example.com
HTML 文档请求。||example.com^$document,redirect=noopframe
redirects HTML document request toexample.com
to an empty html document.
||example.com^$document,redirect=noopframe
将对example.com
HTML 文档请求重定向到空 html 文档。||example.com^$document,removeparam=test
removestest
query parameter from HTML document request toexample.com
.
||example.com^$document,removeparam=test
从对example.com
的 HTML 文档请求中删除test
查询参数。||example.com^$document,replace=/test1/test2/
replacestest1
withtest2
in HTML document request toexample.com
.
||example.com^$document,replace=/test1/test2/
在对example.com
的 HTML 文档请求中将test1
替换为test2
。
You may use a shorter name (alias) instead of using the full modifier name: $doc
.
您可以使用较短的名称(别名)而不是使用完整的修饰符名称: $doc
。
$font
The rule corresponds to requests for fonts, e.g. .woff
filename extension.
该规则对应于字体请求,例如.woff
文件扩展名。
$image
The rule corresponds to images requests.
该规则对应于图像请求。
$media
The rule corresponds to requests for media files — music and video, e.g. .mp4
files.
该规则对应于对媒体文件(音乐和视频,例如.mp4
文件)的请求。
$object
The rule corresponds to browser plugins resources, e.g. Java or Flash.
该规则对应于浏览器插件资源,例如Java 或Flash。
$other
The rule applies to requests for which the type has not been determined or does not match the types listed above.
该规则适用于类型尚未确定或与上面列出的类型不匹配的请求。
$ping
The rule corresponds to requests caused by either navigator.sendBeacon()
or the ping
attribute on links.
该规则对应于由navigator.sendBeacon()
或链接上的ping
属性引起的请求。
$ping
modifier limitations
$ping
修饰符限制
AdGuard for Windows, Mac, and Android often cannot accurately detect navigator.sendBeacon()
.
Using $ping
is not recommended in the filter lists that are supposed to be used by CoreLibs-based AdGuard products.
适用于 Windows、Mac 和 Android 的 AdGuard 通常无法准确检测navigator.sendBeacon()
。不建议在基于 CoreLibs 的 AdGuard 产品应该使用的过滤器列表中使用$ping
。
Rules with $ping
modifier are not supported by AdGuard for Safari and AdGuard for iOS.
AdGuard for Safari 和 AdGuard for iOS 不支持带有$ping
修饰符的规则。
$script
The rule corresponds to script requests, e.g. javascript, vbscript.
该规则对应于脚本请求,例如javascript、vbscript。
$stylesheet
The rule corresponds to CSS files requests.
该规则对应于 CSS 文件请求。
You may use a shorter name (alias) instead of using the full modifier name: $css
.
您可以使用较短的名称(别名)而不是使用完整的修饰符名称: $css
。
$subdocument
The rule corresponds to requests for built-in pages — HTML tags frame
and iframe
.
该规则对应于对内置页面的请求 - HTML 标签frame
和iframe
。
Examples 示例
||example.com^$subdocument
blocks built-in page requests (frame
andiframe
) toexample.com
and all its subdomains anywhere.||example.com^$subdocument
阻止对example.com
及其所有子域的内置页面请求(frame
和iframe
)。||example.com^$subdocument,domain=domain.com
blocks built-in page requests (frame
иiframe
) toexample.com
(and its subdomains) fromdomain.com
and all its subdomains.
||example.com^$subdocument,domain=domain.com
阻止从domain.com
及其所有子域到example.com
(及其子域)的内置页面请求(frame
和iframe
)。
You may use a shorter name (alias) instead of using the full modifier name: $frame
.
您可以使用较短的名称(别名)而不是使用完整的修饰符名称: $frame
。
$subdocument
modified limitations
$subdocument
修改限制
In AdGuard for Windows, Mac, and Android subdocuments are being detected by the Sec-Fetch-Dest header if it is present.
Otherwise, some main pages may be treated as subdocuments.
在 AdGuard for Windows、Mac 和 Android 中,Sec-Fetch-Dest 标头会检测子文档(如果存在)。否则,某些主页可能会被视为子文档。
Rules with $subdocument
modifier are not supported by AdGuard Content Blocker.
AdGuard 内容拦截器不支持带有$subdocument
修饰符的规则。
$websocket
The rule applies only to WebSocket connections.
该规则仅适用于 WebSocket 连接。
$websocket
modifier limitations
$websocket
修饰符限制
For AdGuard for Safari and AdGuard for iOS, it is supported on devices
with macOS Monterey (version 12) and iOS 16 or higher respectively.
对于 AdGuard for Safari 和 AdGuard for iOS,分别在装有 macOS Monterey(版本 12)和 iOS 16 或更高版本的设备上受支持。
$websocket
modifier is supported in all AdGuard products except AdGuard Content Blocker.
除了 AdGuard Content Blocker 之外,所有 AdGuard 产品均支持$websocket
修饰符。
$xmlhttprequest
The rule applies only to ajax requests (requests sent via javascript object XMLHttpRequest
).
该规则仅适用于 ajax 请求(通过 javascript 对象XMLHttpRequest
发送的请求)。
You may use a shorter name (alias) instead of using the full modifier name: $xhr
.
您可以使用较短的名称(别名)而不是使用完整的修饰符名称: $xhr
。
AdGuard for Windows, Mac, Android when filtering older browsers cannot accurately detect this type and sometimes detects it as $other
or $script
. They can only reliably detect this content type when filtering modern browsers that support Fetch metadata request headers.
AdGuard for Windows、Mac、Android 在过滤旧版浏览器时无法准确检测此类型,有时会将其检测为$other
或$script
。他们只能在过滤支持Fetch 元数据请求标头的现代浏览器时才能可靠地检测到此内容类型。
$object-subrequest
(removed)
$object-subrequest
(已删除)
$object-subrequest
modifier is removed and is no longer supported. Rules with it are considered as invalid. The rule corresponds to requests by browser plugins (it is usually Flash).$object-subrequest
修饰符已删除并且不再受支持。带有它的规则被认为是无效的。该规则对应于浏览器插件(通常是Flash)的请求。
$webrtc
(removed)
$webrtc
(已删除)
The rule applies only to WebRTC connections.
该规则仅适用于 WebRTC 连接。
Examples 示例
||example.com^$webrtc,domain=example.org
blocks webRTC connections toexample.com
fromexample.org
.
||example.com^$webrtc,domain=example.org
阻止从example.org
到example.com
webRTC 连接。@@*$webrtc,domain=example.org
disables the RTC wrapper forexample.org
.@@*$webrtc,domain=example.org
禁用example.org
的 RTC 包装器。
Exception rules modifiers
异常规则修饰符
Exception rules disable the other basic rules for the addresses to which they correspond. They begin with a @@
mark. All the basic modifiers listed above can be applied to them and they also have a few special modifiers.
例外规则禁用它们对应的地址的其他基本规则。它们以@@
标记开头。上面列出的所有基本修饰符都可以应用于它们,并且它们还有一些特殊修饰符。
We recommend to get acquainted with the Adblock Plus filter cheatsheet, for better understanding of how exception rules should be made.
我们建议您熟悉Adblock Plus 过滤器备忘单,以便更好地了解如何制定例外规则。
- ✅ — fully supported ✅ — 完全支持
- ✅ * — supported, but reliability may vary or limitations may occur; check the modifier description for more details
✅ * — 支持,但可靠性可能会有所不同或可能会出现限制;检查修改器描述以获取更多详细信息 - ❌ — not supported ❌ — 不支持
$content
Disables HTML filtering, $hls
, $replace
, and $jsonprune
rules on the pages that match the rule.
在与规则匹配的页面上禁用HTML 过滤、 $hls
、 $replace
和$jsonprune
规则。
Examples 示例
@@||example.com^$content
disables all content modifying rules on pages atexample.com
and all its subdomains.@@||example.com^$content
禁用example.com
及其所有子域页面上的所有内容修改规则。
$elemhide
Disables any cosmetic rules on the pages matching the rule.
禁用与规则匹配的页面上的任何修饰规则。
Examples 示例
@@||example.com^$elemhide
disables all cosmetic rules on pages atexample.com
and all subdomains.@@||example.com^$elemhide
禁用example.com
和所有子域页面上的所有修饰规则。
You may use a shorter name (alias) instead of using the full modifier name: $ehide
.
您可以使用较短的名称(别名)而不是使用完整的修饰符名称: $ehide
。
$extension
Disables specific userscripts or all userscripts for a given domain.
禁用给定域的特定用户脚本或所有用户脚本。
Syntax 句法
$extension[="userscript_name1"[|"userscript_name2"[|"userscript_name3"[...]]]]
userscript_name(i)
stands for a specific userscript name to be disabled by the modifier. The modifier can contain any number of userscript names or none. In the latter case the modifier disables all the userscripts.userscript_name(i)
代表要被修饰符禁用的特定用户脚本名称。修饰符可以包含任意数量的用户脚本名称,也可以不包含。在后一种情况下,修饰符将禁用所有用户脚本。
Userscript names usually contain spaces or other special characters, which is why you should enclose the name in quotes. Both single ('
) and double ("
) ASCII quotes are supported. Multiple userscript names should be separated with a pipe (|
). However, if a userscript name is a single word without any special characters, it can be used without quotes.
用户脚本名称通常包含空格或其他特殊字符,这就是为什么您应该将名称括在引号中。支持单 ( '
) 和双 ( "
) ASCII 引号。多个用户脚本名称应使用竖线 ( |
) 分隔。但是,如果用户脚本名称是没有任何特殊字符的单个单词,则可以不使用引号。
You can also exclude a userscript by adding a ~
character before it. In this case, the userscript will not be disabled by the modifier.
您还可以通过在用户脚本前添加~
字符来排除用户脚本。在这种情况下,用户脚本不会被修改器禁用。
$extension=~"userscript name"
When excluding a userscript, you must place ~
outside the quotes.
排除用户脚本时,必须将~
放在引号之外。
If a userscript's name includes quotes ("
), commas (,
), or pipes (|
), they must be escaped with a backslash (\
).
如果用户脚本的名称包含引号 ( "
)、逗号 ( ,
) 或竖线 ( |
),则必须使用反斜杠 ( \
) 对它们进行转义。
$extension="userscript name\, with \"quote\""
Examples 示例
@@||example.com^$extension="AdGuard Assistant"
disables theAdGuard Assistant
userscript onexample.com
website.
@@||example.com^$extension="AdGuard Assistant"
禁用example.com
网站上的AdGuard Assistant
脚本。@@||example.com^$extension=MyUserscript
disables theMyUserscript
userscript onexample.com
website.
@@||example.com^$extension=MyUserscript
禁用example.com
网站上的MyUserscript
用户脚本。@@||example.com^$extension='AdGuard Assistant'|'AdGuard Popup Blocker'
disables bothAdGuard Assistant
andAdGuard Popup Blocker
userscripts onexample.com
website.
@@||example.com^$extension='AdGuard Assistant'|'AdGuard Popup Blocker'
禁用example.com
网站上的AdGuard Assistant
和AdGuard Popup Blocker
用户脚本。@@||example.com^$extension=~"AdGuard Assistant"
disables all user scripts onexample.com
website, exceptAdGuard Assistant
.
@@||example.com^$extension=~"AdGuard Assistant"
禁用example.com
网站上的所有用户脚本AdGuard Assistant
除外)。@@||example.com^$extension=~"AdGuard Assistant"|~"AdGuard Popup Blocker"
disables all user scripts onexample.com
website, exceptAdGuard Assistant
andAdGuard Popup Blocker
.
@@||example.com^$extension=~"AdGuard Assistant"|~"AdGuard Popup Blocker"
禁用example.com
网站上的所有用户脚本,除了AdGuard Assistant
和AdGuard Popup Blocker
。@@||example.com^$extension
no userscript will work on webpages onexample.com
.@@||example.com^$extension
任何用户脚本都无法在example.com
上的网页上运行。@@||example.com^$extension="AdGuard \"Assistant\""
disables theAdGuard "Assistant"
userscript onexample.com
website.
@@||example.com^$extension="AdGuard \"Assistant\""
禁用example.com
网站上的AdGuard "Assistant"
用户脚本。
- Only AdGuard for Windows, Mac, Android are technically capable of using rules with
$extension
modifier.
从技术上讲,只有适用于 Windows、Mac、Android 的 AdGuard 能够使用带有$extension
修饰符的规则。 - Rules with
$extension
modifier with specific userscript name are supported by AdGuard for Windows, AdGuard for Mac, and AdGuard for Android with CoreLibs v1.13 or later.
AdGuard for Windows、AdGuard for Mac 和 AdGuard for Android(带有CoreLibs v1.13 或更高版本)支持带有$extension
修饰符和特定用户脚本名称的规则。
$jsinject
Forbids adding of JavaScript code to the page. You can read about scriptlets and javascript rules further.
禁止向页面添加 JavaScript 代码。您可以进一步阅读有关 scriptlet 和 javascript 规则的内容。
Examples 示例
@@||example.com^$jsinject
disables javascript on pages atexample.com
and all subdomains.@@||example.com^$jsinject
禁用example.com
和所有子域页面上的 javascript。
$jsinject
modifier limitations
$jsinject
修饰符限制
Rules with the $jsinject
modifier cannot be converted to DNR in AdGuard for Chrome MV3.
We only use them in the TSUrlFilter engine to disable some cosmetic rules.
带有$jsinject
修饰符的规则无法在AdGuard for Chrome MV3中转换为 DNR。我们仅在TSUrlFilter引擎中使用它们来禁用某些修饰规则。
$stealth
Disables the Tracking protection (formerly Stealth Mode) module for all corresponding pages and requests.
禁用所有相应页面和请求的跟踪保护(以前称为隐形模式)模块。
Syntax 句法
$stealth [= opt1 [| opt2 [| opt3 [...]]]]
opt(i)
stand for certain Tracking protection options disabled by the modifier.
The modifier can contain any number of specific options (see below) or none.
In the latter case the modifier disables all the Tracking protection features.opt(i)
代表由修饰符禁用的某些跟踪保护选项。修饰符可以包含任意数量的特定选项(见下文)或不包含。在后一种情况下,修改器将禁用所有跟踪保护功能。
The list of the available modifier options:
可用修饰符选项列表:
searchqueries
disables Hide your search queries optionsearchqueries
禁用隐藏您的搜索查询选项donottrack
disables Ask websites not to track you optiondonottrack
禁用“要求网站不要跟踪您”选项3p-cookie
disables Self-destructing third-party cookies option3p-cookie
禁用自毁第三方 cookie选项1p-cookie
disables Self-destructing first-party cookies option1p-cookie
禁用自毁第一方 cookie选项3p-cache
disables Disable cache for third-party requests option3p-cache
禁用禁用第三方请求缓存选项3p-auth
disables Block third-party Authorization header option3p-auth
禁用阻止第三方授权标头选项webrtc
disables Block WebRTC optionwebrtc
禁用阻止 WebRTC选项push
disables Block Push API optionpush
禁用Block Push API选项location
disables Block Location API optionlocation
禁用阻止位置 API选项flash
disables Block Flash optionflash
禁用Block Flash选项java
disables Block Java optionjava
禁用Block Java选项referrer
disables Hide Referer from third parties optionreferrer
禁用隐藏第三方选项的推荐人useragent
disables Hide your User-Agent optionuseragent
禁用隐藏您的用户代理选项ip
disables Hide your IP address optionip
禁用隐藏您的 IP 地址选项xclientdata
disables Remove X-Client-Data header from HTTP requests optionxclientdata
禁用“从 HTTP 请求中删除 X-Client-Data 标头”选项dpi
disables Protect from DPI optiondpi
禁用DPI 保护选项
Examples 示例
@@||example.com^$stealth
disables Tracking protection forexample.com
(and subdomains) requests, except for blocking cookies and hiding tracking parameters (see below).@@||example.com^$stealth
禁用对example.com
(和子域)请求的跟踪保护,但阻止 cookie 和隐藏跟踪参数除外(见下文)。@@||domain.com^$script,stealth,domain=example.com
disables Tracking protection only for script requests todomain.com
(and its subdomains) onexample.com
and all its subdomains.
@@||domain.com^$script,stealth,domain=example.com
仅对example.com
及其所有子域上的domain.com
(及其子域)的脚本请求禁用跟踪保护。@@||example.com^$stealth=3p-cookie|dpi
disables blocking third-party cookies and DPI fooling measures forexample.com
.
@@||example.com^$stealth=3p-cookie|dpi
禁用对example.com
的第三方 cookie 和 DPI 欺骗措施的阻止。
Blocking cookies and removing tracking parameters is achieved by using rules with the $cookie
, $urltransform
and $removeparam
modifiers. Exception rules that contain only the $stealth
modifier will not do these things. If you want to completely disable all Tracking protection features for a given domain, you must include all three modifiers: @@||example.org^$stealth,removeparam,cookie
.
阻止 cookie 和删除跟踪参数是通过使用带有$cookie
、 $urltransform
和$removeparam
修饰符的规则来实现的。仅包含$stealth
修饰符的异常规则不会执行这些操作。如果要完全禁用给定域的所有跟踪保护功能,则必须包含所有三个修饰符: @@||example.org^$stealth,removeparam,cookie
。
- Modifier options must be lowercase, i.e.
$stealth=DPI
will be rejected.
修饰符选项必须是小写,即$stealth=DPI
将被拒绝。 - Modifier options cannot be negated, i.e.
$stealth=~3p-cookie
will be rejected.
修饰符选项不能被否定,即$stealth=~3p-cookie
将被拒绝。 - AdGuard Browser Extension supports only
searchqueries
,donottrack
,referrer
,xclientdata
,1p-cookie
and3p-cookie
options.
AdGuard 浏览器扩展仅支持searchqueries
、donottrack
、referrer
、xclientdata
、1p-cookie
和3p-cookie
选项。
- Tracking protection (formerly Stealth Mode) is available in AdGuard for Windows, AdGuard for Mac,
AdGuard for Android, and AdGuard Browser Extension for Firefox and Chromium-based browsers, except AdGuard for Chrome MV3.
All other products will ignore the rules with
$stealth
modifier.
跟踪保护(以前称为隐秘模式)适用于 Windows 版 AdGuard、Mac 版 AdGuard、Android 版 AdGuard 以及 Firefox 和基于 Chromium 的浏览器的 AdGuard 浏览器扩展(AdGuard for Chrome MV3 除外)。所有其他产品将忽略带有$stealth
修饰符的规则。 - Rules with
$stealth
modifier with specific options are supported by AdGuard for Windows, AdGuard for Mac, and AdGuard for Android with CoreLibs v1.10 or later, and AdGuard Browser Extension with TSUrlFilter v3.0.0 or later.
具有特定选项的$stealth
修饰符的规则受带有 CoreLibs v1.10 或更高版本的 AdGuard for Windows、AdGuard for Mac 和 AdGuard for Android with CoreLibs v1.10 或更高版本以及带有TSUrlFilter v3.0.0 或更高版本的 AdGuard 浏览器扩展的支持。
$urlblock
Disables blocking of all requests sent from the pages matching the rule and disables all $cookie
rules.
禁用对从匹配规则的页面发送的所有请求的阻止,并禁用所有$cookie
规则。
Examples 示例
@@||example.com^$urlblock
— any requests sent from the pages atexample.com
and all subdomains are not going to be blocked.@@||example.com^$urlblock
— 从example.com
页面和所有子域发送的任何请求都不会被阻止。
$urlblock
modifier limitations
$urlblock
修饰符限制
In AdGuard for iOS and AdGuard for Safari, rules with $urlblock
work
as $document exclusion — unblock everything.
在 AdGuard for iOS 和 AdGuard for Safari 中,带有$urlblock
规则充当$document 排除— 解锁所有内容。
Rules with $urlblock
modifier are not supported by AdGuard Content Blocker,
and AdGuard for Chrome MV3.
AdGuard 内容拦截器和 AdGuard for Chrome MV3 不支持带有$urlblock
修饰符的规则。
Generic rules 通用规则
Before we can proceed to the next modifiers, we have to make a definition of generic rules. The rule is generic if it is not limited to specific domains.
Wildcard character *
is supported as well.
在我们继续进行下一个修饰符之前,我们必须定义通用规则。如果该规则不限于特定域,则该规则是通用的。还支持通配符*
。
For example, these rules are generic:
例如,这些规则是通用的:
###banner
*###banner
#@#.adsblock
*#@#.adsblock
~domain.com###banner
||domain.com^
||domain.com^$domain=~example.com
And these are not: 这些不是:
domain.com###banner
||domain.com^$domain=example.com
$genericblock
Disables generic basic rules on pages that correspond to exception rule.
禁用与例外规则对应的页面上的通用基本规则。
Examples 示例
@@||example.com^$genericblock
disables generic basic rules on any pages atexample.com
and all subdomains.@@||example.com^$genericblock
禁用example.com
和所有子域的任何页面上的通用基本规则。
$genericblock
modifier limitations
$genericblock
修饰符限制
In AdGuard for iOS and AdGuard for Safari, rules with $genericblock
work
as $document exclusion — unblock everything.
在 AdGuard for iOS 和 AdGuard for Safari 中,带有$genericblock
规则充当$document 排除— 解锁所有内容。
Rules with $genericblock
modifier are not supported by AdGuard Content Blocker,
and AdGuard for Chrome MV3.
AdGuard 内容拦截器和 AdGuard for Chrome MV3 不支持带有$genericblock
修饰符的规则。
$generichide
Disables all generic cosmetic rules on pages that correspond to the exception rule.
禁用与例外规则对应的页面上的所有通用修饰规则。
Examples 示例
@@||example.com^$generichide
disables generic cosmetic rules on any pages atexample.com
and its subdomains.@@||example.com^$generichide
禁用example.com
及其子域的任何页面上的通用修饰规则。
You may use a shorter name (alias) instead of using the full modifier name: $ghide
.
您可以使用较短的名称(别名)而不是使用完整的修饰符名称: $ghide
。
specifichide
Disables all specific element hiding and CSS rules, but not general ones. Has an opposite effect to $generichide
.
禁用所有特定元素隐藏和 CSS 规则,但不禁用一般规则。与$generichide
具有相反的效果。
Examples 示例
@@||example.org^$specifichide
disablesexample.org##.banner
but not##.banner
.@@||example.org^$specifichide
禁用example.org##.banner
但不禁用##.banner
。
You may use a shorter name (alias) instead of using the full modifier name: $shide
.
您可以使用较短的名称(别名)而不是使用完整的修饰符名称: $shide
。
All cosmetic rules — not just specific ones — can be disabled by $elemhide
modifier.
所有修饰规则(不仅仅是特定的规则)都可以通过$elemhide
修饰符禁用。
Rules with $specifichide
modifier are not supported by AdGuard for iOS, AdGuard for Safari, and AdGuard Content Blocker.
AdGuard for iOS、AdGuard for Safari 和 AdGuard Content Blocker 不支持带有$specifichide
修饰符的规则。
Advanced capabilities 先进的功能
These modifiers are able to completely change the behavior of basic rules.
这些修饰符能够完全改变基本规则的行为。
Modifier \ Products 改性剂\产品 | CoreLibs apps CoreLibs 应用程序 | AdGuard for Chromium 适用于 Chromium 的 AdGuard | AdGuard for Chrome MV3 适用于 Chrome 的 AdGuard MV3 | AdGuard for Firefox 适用于 Firefox 的 AdGuard | AdGuard for iOS iOS 版 AdGuard | AdGuard for Safari 适用于 Safari 的 AdGuard | AdGuard Content Blocker AdGuard 内容拦截器 |
---|---|---|---|---|---|---|---|
$all $全部 | ✅ | ✅ | ✅ *[1] | ✅ | ✅ | ✅ | ❌ |
$badfilter $坏过滤器 | ✅ | ✅ | ✅ *[2] | ✅ | ✅ | ✅ | ❌ |
$cookie | ✅ | ✅ | ✅ *[3] | ✅ | ❌ | ❌ | ❌ |
$csp | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ |
$hls | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
$inline-font $内联字体 | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ |
$inline-script $内联脚本 | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ |
$jsonprune | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
$xmlprune | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
$network $网络 | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
$permissions $权限 | ✅ *[4] | ✅ | ✅ | ✅ *[4] | ❌ | ❌ | ❌ |
$redirect $重定向 | ✅ | ✅ | ✅ *[5] | ✅ | ❌ | ❌ | ❌ |
$redirect-rule $重定向规则 | ✅ | ✅ | ❌ | ✅ | ❌ | ❌ | ❌ |
$referrerpolicy $referrer政策 | ✅ | ❌ | ⏳ | ❌ | ❌ | ❌ | ❌ |
$removeheader $删除标题 | ✅ | ✅ | ❌ | ✅ | ❌ | ❌ | ❌ |
$removeparam $删除参数 | ✅ | ✅ | ✅ *[6] | ✅ | ❌ | ❌ | ❌ |
$replace $替换 | ✅ | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ |
$urltransform $url变换 | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
noop 努普 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ |
$empty 👎 $空👎 | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ |
$mp4 👎 | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ |
- ✅ — fully supported ✅ — 完全支持
- ✅ * — supported, but reliability may vary or limitations may occur; check the modifier description for more details
✅ * — 支持,但可靠性可能会有所不同或可能会出现限制;检查修改器描述以获取更多详细信息 - ⏳ — feature that is planned to be implemented but is not yet available in any product
⏳ — 计划实现但尚未在任何产品中提供的功能 - ❌ — not supported ❌ — 不支持
- 👎 — deprecated; still supported but will be removed in the future
👎 — 已弃用;仍然受支持,但将来会被删除
$all
$all
modifier is made of all content-types modifiers and $popup
.
E.g. rule ||example.org^$all
is converting into rule:$all
修饰符由所有内容类型修饰符和$popup
组成。例如规则||example.org^$all
正在转换为规则:
||example.org^$document,subdocument,font,image,media,object,other,ping,script,stylesheet,websocket,xmlhttprequest,popup
This modifier cannot be used as an exception with the @@
mark.
此修饰符不能与@@
标记一起用作例外。
$all
modifier limitations
$all
修饰符限制
Since $popup
is a part if $all
, the $all
modifier is not supported by AdGuard for Chrome MV3
because of $popup
modifier limitations.
由于$popup
是$all
一部分,因此由于$popup
修饰符的限制, AdGuard for Chrome MV3 不支持$all
修饰符。
Rules with $all
modifier are not supported by AdGuard Content Blocker.
AdGuard 内容拦截器不支持带有$all
修饰符的规则。
$badfilter
The rules with the $badfilter
modifier disable other basic rules to which they refer. It means that the text of the disabled rule should match the text of the $badfilter
rule (without the $badfilter
modifier).
带有$badfilter
修饰符的规则禁用它们引用的其他基本规则。这意味着禁用规则的文本应与$badfilter
规则的文本匹配(不带$badfilter
修饰符)。
Examples 示例
||example.com$badfilter
disables||example.com
||example.com$badfilter
禁用||example.com
||example.com$image,badfilter
disables||example.com$image
||example.com$image,badfilter
禁用||example.com$image
@@||example.com$badfilter
disables@@||example.com
@@||example.com$badfilter
禁用@@||example.com
||example.com$domain=domain.com,badfilter
disables||example.com$domain=domain.com
||example.com$domain=domain.com,badfilter
禁用||example.com$domain=domain.com
Rules with $badfilter
modifier can disable other basic rules for specific domains if they fulfill the following conditions:
如果具有$badfilter
修饰符的规则满足以下条件,则可以禁用特定域的其他基本规则:
- The rule has a
$domain
modifier
该规则有一个$domain
修饰符 - The rule does not have a negated domain
~
in$domain
modifier value
该规则在$domain
修饰符值中没有否定域~
In that case, the $badfilter
rule will disable the corresponding rule for domains specified in both the $badfilter
and basic rules. Please note that wildcard-TLD logic works here as well.
在这种情况下, $badfilter
规则将禁用$badfilter
和基本规则中指定的域的相应规则。请注意,通配符 TLD 逻辑在这里也适用。
Examples 示例
/some$domain=example.com|example.org|example.io
is disabled forexample.com
by/some$domain=example.com,badfilter
/some$domain=example.com|example.org|example.io
被example.com
禁用/some$domain=example.com,badfilter
/some$domain=example.com|example.org|example.io
is disabled forexample.com
andexample.org
by/some$domain=example.com|example.org,badfilter
/some$domain=example.com|example.org|example.io
对example.com
和example.org
禁用/some$domain=example.com|example.org,badfilter
/some$domain=example.com|example.org
and/some$domain=example.io
are disabled completely by/some$domain=example.com|example.org|example.io,badfilter
/some$domain=example.com|example.org
和/some$domain=example.io
被完全禁用/some$domain=example.com|example.org|example.io,badfilter
/some$domain=example.com|example.org|example.io
is disabled completely by/some$domain=example.*,badfilter
/some$domain=example.com|example.org|example.io
被完全禁用/some$domain=example.*,badfilter
/some$domain=example.*
is disabled forexample.com
andexample.org
by/some$domain=example.com|example.org,badfilter
/some$domain=example.*
对example.com
和example.org
禁用/some$domain=example.com|example.org,badfilter
/some$domain=example.com|example.org|example.io
is NOT disabled forexample.com
by/some$domain=example.com|~example.org,badfilter
because the value of$domain
modifier contains a negated domain
/some$domain=example.com|example.org|example.io
未禁用example.com
/some$domain=example.com|~example.org,badfilter
因为$domain
修饰符的值包含否定域
$badfilter
modifier limitations
$badfilter
修饰符限制
In AdGuard for Chrome MV3 a rule with the $badfilter
modifier is applied in DNR only if it fully cancels the source rule. We cannot calculate it if it is only partially canceled. Examples
在AdGuard for Chrome MV3中,仅当完全取消源规则时,才会在 DNR 中应用带有$badfilter
修饰符的规则。如果只是部分取消的话我们无法计算。示例
Rules with $badfilter
modifier are not supported by AdGuard Content Blocker.
AdGuard 内容拦截器不支持带有$badfilter
修饰符的规则。
$cookie
The $cookie
modifier completely changes rule behavior. Instead of blocking a request, this modifier makes AdGuard suppress or modify the Cookie
and Set-Cookie
headers.$cookie
修饰符完全改变了规则行为。此修饰符不会阻止请求,而是使 AdGuard 抑制或修改Cookie
和Set-Cookie
标头。
Multiple rules matching a single request
多个规则匹配单个请求
In case if multiple $cookie
rules match a single request, we will apply each of them one by one.
如果多个$cookie
规则与单个请求匹配,我们将一一应用它们。
Syntax 句法
$cookie [= name[; maxAge = seconds [; sameSite = strategy ]]]
where: 在哪里:
name
— optional, string or regular expression to match cookie name.name
— 可选,字符串或正则表达式来匹配 cookie 名称。seconds
— number of seconds for current time to offset the expiration date of cookie.seconds
— 当前时间偏移 cookie 过期日期的秒数。strategy
— string for Same-Site strategy to be applied to the cookie.strategy
— 应用于 cookie 的同站点策略的字符串。
For example, 例如,
||example.org^$cookie=NAME;maxAge=3600;sameSite=lax
every time AdGuard encounters a cookie called NAME
in a request to example.org
, it will do the following:
每次 AdGuard 在对example.org
请求中遇到名为NAME
的 cookie 时,它都会执行以下操作:
- Set its expiration date to current time plus
3600
seconds
将其到期日期设置为当前时间加上3600
秒 - Makes the cookie use Same-Site "lax" strategy.
使 cookie 使用Same-Site “宽松”策略。
Escaping special characters
转义特殊字符
If regular expression name
is used for matching, two characters must be escaped: comma ,
and dollar sign $
. Use backslash \
to escape each of them. For example, escaped comma looks like this: \,
.
如果使用正则表达式name
进行匹配,则必须转义两个字符:逗号,
美元符号$
。使用反斜杠\
来转义它们中的每一个。例如,转义逗号如下所示: \,
。
Examples 示例
||example.org^$cookie
blocks all cookies set byexample.org
; this is an equivalent to settingmaxAge=0
||example.org^$cookie
阻止example.org
设置的所有cookie;这相当于设置maxAge=0
$cookie=__cfduid
blocks CloudFlare cookie everywhere$cookie=__cfduid
到处阻止 CloudFlare cookie$cookie=/__utm[a-z]/
blocks Google Analytics cookies everywhere$cookie=/__utm[az]/
到处阻止 Google Analytics cookie||facebook.com^$third-party,cookie=c_user
prevents Facebook from tracking you even if you are logged in
||facebook.com^$third-party,cookie=c_user
即使您已登录,也会阻止 Facebook 跟踪您
There are two methods to deactivate $cookie
rules: the primary method involves using an exception marked with @@
— @@||example.org^$cookie
. The alternative method employs a $urlblock
exception (also included under the $document
exception alias — $elemhide,jsinject,content,urlblock,extension
).
Here's how it works:
有两种方法可以停用$cookie
规则:主要方法涉及使用标有@@
异常 — @@||example.org^$cookie
。另一种方法采用$urlblock
异常(也包含在$document
异常别名下 - $elemhide,jsinject,content,urlblock,extension
)。它的工作原理如下:
@@||example.org^$cookie
unblocks all cookies set byexample.org
@@||example.org^$cookie
取消阻止example.org
设置的所有 cookie@@||example.org^$urlblock
unblocks all cookies set byexample.org
and disables blocking of all requests sent fromexample.org
@@||example.org^$urlblock
取消阻止example.org
设置的所有 cookie 并禁用阻止阻止从example.org
发送的所有请求@@||example.org^$cookie=concept
unblocks a single cookie namedconcept
@@||example.org^$cookie=concept
解锁单个名为concept
的cookie@@||example.org^$cookie=/^_ga_/
unblocks every cookie that matches the regular expression
@@||example.org^$cookie=/^_ga_/
解除阻止与正则表达式匹配的每个 cookie
$cookie
modifier limitations
$cookie
修饰符限制
In AdGuard for Chrome MV3 we delete cookies in 2 ways: from content-script
side (to which we have access)
and from onBeforeSendHeaders
listener. Since onBeforeSendHeaders
and other listeners are no longer blocking,
we are not able to delete them in all cases.
You can check if a rule works with this test.
在AdGuard for Chrome MV3中,我们通过两种方式删除 cookie:从content-script
端(我们有权访问)和从onBeforeSendHeaders
侦听器。由于onBeforeSendHeaders
和其他侦听器不再阻塞,因此我们无法在所有情况下删除它们。您可以检查规则是否适用于此测试。
$cookie
rules support these types of modifiers: $domain
, $~domain
, $important
, $third-party
, $~third-party
, strict-third-party
, and strict-first-party
.$cookie
规则支持以下类型的修饰符: $domain
、 $~domain
、 $important
、 $third-party
、 $~third-party
、 strict-third-party
和strict-first-party
。
Rules with $cookie
modifier are not supported by AdGuard Content Blocker, AdGuard for iOS, and AdGuard for Safari.
AdGuard 内容拦截器、AdGuard for iOS 和 AdGuard for Safari 不支持带有$cookie
修饰符的规则。
$csp
This modifier completely changes the rule behavior. If it is applied to a rule, the rule will not block the matching request. Response headers will be modified instead.
此修饰符完全改变了规则行为。如果应用于规则,则该规则不会阻止匹配的请求。响应标头将被修改。
In order to use this type of rules, it is required to have the basic understanding of the Content Security Policy security layer.
为了使用此类规则,需要对内容安全策略安全层有基本的了解。
For the requests matching a $csp
rule, we will strengthen response security policy by enhancing the content security policy, similar to the content security policy of the $csp
modifier contents. $csp
rules are applied independently from any other rule type. Only document-level exceptions can influence it (see the examples section), but no other basic rules.
对于匹配$csp
规则的请求,我们会通过增强内容安全策略来加强响应安全策略,类似于$csp
修饰符内容的内容安全策略。 $csp
规则的应用独立于任何其他规则类型。只有文档级异常可以影响它(请参阅示例部分),但没有其他基本规则。
Multiple rules matching a single request
多个规则匹配单个请求
In case if multiple $csp
rules match a single request, we will apply each of them.
如果多个$csp
规则与单个请求匹配,我们将应用每个规则。
Syntax 句法
$csp
value syntax is similar to the Content Security Policy header syntax.$csp
值语法类似于内容安全策略标头语法。
$csp
value can be empty in the case of exception rules. See examples section below.
如果有例外规则, $csp
值可以为空。请参阅下面的示例部分。
Examples 示例
||example.org^$csp=frame-src 'none'
blocks all frames on example.org and its subdomains.
||example.org^$csp=frame-src 'none'
阻止 example.org 及其子域上的所有框架。@@||example.org/page/*$csp=frame-src 'none'
disables all rules with the$csp
modifier exactly matchingframe-src 'none'
on all the pages matching the rule pattern. For instance, the rule above.
@@||example.org/page/*$csp=frame-src 'none'
禁用与规则模式匹配的所有页面上的$csp
修饰符与frame-src 'none'
完全匹配的所有规则。例如上面的规则。@@||example.org/page/*$csp
disables all the$csp
rules on all the pages matching the rule pattern.@@||example.org/page/*$csp
禁用与规则模式匹配的所有页面上的所有$csp
规则。||example.org^$csp=script-src 'self' 'unsafe-eval' http: https:
disables inline scripts on all the pages matching the rule pattern.
||example.org^$csp=script-src 'self' 'unsafe-eval' http: https:
禁用与规则模式匹配的所有页面上的内联脚本。@@||example.org^$document
or@@||example.org^$urlblock
disables all the$csp
rules on all the pages matching the rule pattern.@@||example.org^$document
或@@||example.org^$urlblock
禁用所有与规则模式匹配的页面上的所有$csp
规则。
- There are a few characters forbidden in the
$csp
value:,
,$
.$csp
值中禁止使用一些字符:,
,$
。 $csp
rules support three types of modifiers:$domain
,$important
,$subdocument
.$csp
规则支持三种类型的修饰符:$domain
、$important
、$subdocument
。- Rules with
report-*
directives are considered invalid.
带有report-*
指令的规则被认为是无效的。
Rules with $csp
modifier are not supported by AdGuard Content Blocker, AdGuard for iOS and AdGuard for Safari.
AdGuard 内容拦截器、AdGuard for iOS 和 AdGuard for Safari 不支持带有$csp
修饰符的规则。
$hls
$hls
rules modify the response of a matching request. They are intended as a convenient way to remove segments from HLS playlists (RFC 8216).$hls
规则修改匹配请求的响应。它们旨在作为从HLS 播放列表 (RFC 8216)中删除片段的便捷方法。
The word "segment" in this document means either a "Media Segment" or a "playlist" as part of a "Master Playlist": $hls
rules do not distinguish between a "Master Playlist" and a "Media Playlist".
本文档中的“片段”一词表示“媒体片段”或作为“主播放列表”一部分的“播放列表”: $hls
规则不区分“主播放列表”和“媒体播放列表”。
Syntax 句法
||example.org^$hls=urlpattern
removes segments whose URL matches the URL patternurlpattern
. The pattern works just like the one in basic URL rules, however, the characters/
,$
and,
must be escaped with\
insideurlpattern
.||example.org^$hls=urlpattern
删除 URL 与 URL 模式urlpattern
匹配的段。该模式的工作方式与基本 URL 规则中的模式类似,但是字符/
、$
和,
必须在urlpattern
中使用\
进行转义。||example.org^$hls=/regexp/options
removes segments where the URL or one of the tags (for certain options, if present) is matched by the regular expressionregexp
. Availableoptions
are:
||example.org^$hls=/regexp/options
删除 URL 或标签之一(对于某些选项,如果存在)与正则表达式regexp
匹配的段。可用options
有:t
— instead of testing the segment's URL, test each of the segment's tags against the regular expression. A segment with a matching tag is removed;t
— 不是测试段的 URL,而是根据正则表达式测试段的每个标签。删除具有匹配标签的段;i
— make the regular expression case-insensitive.i
— 使正则表达式不区分大小写。
The characters /
, $
and ,
must be escaped with \
inside regexp
.
字符/
、 $
和,
必须在regexp
中使用\
进行转义。
Exceptions 例外情况
Basic URL exceptions shall not disable rules with $hls
modifier. They can be disabled as described below:
基本 URL 例外不得禁用带有$hls
修饰符的规则。可以按如下所述禁用它们:
@@||example.org^$hls
disables all$hls
rules for responses from URLs matching||example.org^
.@@||example.org^$hls
对来自匹配||example.org^
URL 的响应禁用所有$hls
规则。@@||example.org^$hls=text
disables all$hls
rules with the value of the$hls
modifier equal totext
for responses from URLs matching||example.org^
.@@||example.org^$hls=text
禁用所有$hls
规则,其中$hls
修饰符的值等于来自匹配||example.org^
URL 的响应的text
。
$hls
rules can also be disabled by $document
, $content
and $urlblock
exception rules.$hls
规则也可以通过$document
、 $content
和$urlblock
例外规则禁用。
When multiple $hls
rules match the same request, their effect is cumulative.
当多个$hls
规则匹配同一个请求时,它们的效果是累积的。
Examples 示例
||example.org^$hls=\/videoplayback^?*&source=dclk_video_ads
removes all segments with the matching URL.
||example.org^$hls=\/videoplayback^?*&source=dclk_video_ads
删除具有匹配 URL 的所有段。||example.org^$hls=/\/videoplayback\/?\?.*\&source=dclk_video_ads/i
achieves more or less the same with a regular expression instead of a URL pattern.
||example.org^$hls=/\/videoplayback\/?\?.*\&source=dclk_video_ads/i
使用正则表达式而不是 URL 模式可以实现或多或少相同的效果。||example.org^$hls=/#UPLYNK-SEGMENT:.*\,ad/t
removes all segments which have the matching tag.
||example.org^$hls=/#UPLYNK-SEGMENT:.*\,ad/t
删除所有具有匹配标签的段。
Anatomy of an HLS playlist
HLS 播放列表剖析
A quick summary of the specification:
规范的快速摘要:
- An HLS playlist is a collection of text lines
HLS 播放列表是文本行的集合 - A line may be empty, a comment (starts with
#
), a tag (also starts with#
, can only be recognized by name) or a URL
一行可以为空、注释(以#
开头)、标签(也以#
开头,只能通过名称识别)或 URL - A URL line is called a "segment"
URL 行称为“段” - Tags may apply to a single segment, i.e. the first URL line after the tag, to all segments following the tag and until the tag with the same name, or to the whole playlist
标签可以应用于单个片段,即标签之后的第一个 URL 行,应用于该标签之后的所有片段,直到具有相同名称的标签,或者应用于整个播放列表
Some points specific to the operation of $hls
rules:$hls
规则操作的一些具体要点:
- When a segment is removed, all of the tags that apply only to that segment are also removed
删除某个段时,仅适用于该段的所有标签也会被删除 - When there is a tag that applies to multiple segments, and all of those segments are removed, the tag is also removed
当一个标签适用于多个段,并且所有这些段都被删除时,该标签也会被删除 - Since there is no way to recognize different kinds of tags by syntax, we recognize all of the tags specified by the RFC, plus some non-standard tags that we have seen in the field. Any lines starting with
#
and not recognized as a tag are passed through without modification, and are not matched against the rules
由于无法通过语法来识别不同类型的标签,因此我们识别 RFC 指定的所有标签,以及我们在该领域看到的一些非标准标签。任何以#
开头且未被识别为标记的行都会不加修改地通过,并且不会与规则匹配 - Tags will not be matched if they apply to the entire playlist, and
$hls
rules cannot be used to remove them, as these rule types are intended for segment removals. If you know what you are doing, you can use$replace
rules to remove or rewrite just a single tag from the playlist
如果标签应用于整个播放列表,则它们不会被匹配,并且$hls
规则不能用于删除它们,因为这些规则类型旨在用于片段删除。如果您知道自己在做什么,则可以使用$replace
规则从播放列表中删除或重写单个标签
An example of a transformation done by the rules:
由规则完成的转换的示例:
Original response 原始回复
Applied rules 应用规则
Modified response 修改后的响应
- Rules with the
$hls
modifier can only be used in trusted filters.
带有$hls
修饰符的规则只能在受信任的过滤器中使用。 $hls
rules are compatible with the modifiers$domain
,$third-party
,$strict-third-party
,$strict-first-party
,$app
,$important
,$match-case
, and$xmlhttprequest
only.$hls
规则仅与修饰符$domain
、$third-party
、$strict-third-party
、$strict-first-party
、$app
、$important
、$match-case
和$xmlhttprequest
兼容。$hls
rules only apply to HLS playlists, which are UTF-8 encoded text starting with the line#EXTM3U
. Any other response will not be modified by these rules.$hls
规则仅适用于 HLS 播放列表,这些播放列表是以#EXTM3U
行开头的 UTF-8 编码文本。任何其他响应都不会被这些规则修改。$hls
rules do not apply if the size of the original response is more than 10 MB.
如果原始响应的大小超过 10 MB,则$hls
规则不适用。
$inline-script
The $inline-script
modifier is designed to block inline JavaScript embedded into the web page, using Content Security Policy (CSP). It improves security and privacy by preventing application of inline ads or potentially malicious scripts. The rule ||example.org^$inline-script
is converting into the CSP-syntax rule:$inline-script
修饰符旨在使用内容安全策略 (CSP) 阻止嵌入网页的内联 JavaScript。它通过防止应用内嵌广告或潜在的恶意脚本来提高安全性和隐私性。规则||example.org^$inline-script
正在转换为 CSP 语法规则:
||example.org^$csp=script-src 'self' 'unsafe-eval' http: https: data: blob: mediastream: filesystem:
$inline-font
The $inline-font
modifier is designed to block inline fonts embedded into the web page, using Content Security Policy (CSP). It improves security and privacy by preventing application of inline fonts that could be used for data collection and fingerprinting. The rule ||example.org^$inline-font
is converting into the CSP-syntax rule:$inline-font
修饰符旨在使用内容安全策略 (CSP) 阻止嵌入网页的内联字体。它通过阻止应用可用于数据收集和指纹识别的内联字体来提高安全性和隐私性。规则||example.org^$inline-font
正在转换为 CSP 语法规则:
||example.org^$csp=font-src 'self' 'unsafe-eval' http: https: data: blob: mediastream: filesystem:
$jsonprune
$jsonprune
rules modify the response to a matching request by removing JSON items that match a modified
JSONPath expression. They do not modify responses which are not valid JSON documents.$jsonprune
规则通过删除与修改后的内容匹配的 JSON 项目来修改对匹配请求的响应
JSONPath表达式。它们不会修改不是有效 JSON 文档的响应。
In AdGuard for Windows, Mac, and Android with CoreLibs v1.11 or later, $jsonprune
also supports modifying JSONP (padded JSON) documents.
在带有CoreLibs v1.11 或更高版本的 Windows、Mac 和 Android 版 AdGuard 中, $jsonprune
还支持修改 JSONP(填充 JSON)文档。
Syntax 句法
||example.org^$jsonprune=expression
removes items that match the modified JSONPath expressionexpression
from the response.
||example.org^$jsonprune=expression
从响应中删除与修改后的 JSONPathexpression
匹配的项目。
Due to the way rule parsing works, the characters $
and ,
must be escaped with \
inside expression
.
由于规则解析的工作方式,字符$
和,
必须在expression
内使用\
进行转义。
The modified JSONPath syntax has the following differences from the original:
修改后的 JSONPath 语法与原始语法有以下差异:
- Script expressions are not supported
不支持脚本表达式 - The supported filter expressions are:
支持的过滤器表达式有:?(has <key>)
— true if the current object has the specified key?(has <key>)
— 如果当前对象具有指定的键,则为 true?(key-eq <key> <value>)
— true if the current object has the specified key, and its value is equal to the specified value?(key-eq <key> <value>)
— 如果当前对象具有指定的键,并且其值等于指定的值,则为 true?(key-substr <key> <value>)
— true if the specified value is a substring of the value of the specified key of the current object?(key-substr <key> <value>)
— 如果指定值是当前对象的指定键值的子字符串,则为 true
- Whitespace outside of double- or single-quoted strings has no meaning
双引号或单引号字符串之外的空格没有意义 - Both double- and single-quoted strings can be used
双引号和单引号字符串都可以使用 - Expressions ending with
..
are not supported
不支持以..
结尾的表达式 - Multiple array slices can be specified in square brackets
可以在方括号中指定多个数组切片
There are various online tools that make working with JSONPath expressions more convenient:
有各种在线工具可以使使用 JSONPath 表达式更加方便:
https://www.site24x7.com/tools/jsonpath-finder-validator.html
https://jsonpathfinder.com/
https://jsonpath.com/
https://www.site24x7.com/tools/jsonpath-finder-validator.html https://jsonpathfinder.com/ https://jsonpath.com/
Keep in mind, though, that all JSONPath implementations have unique features/quirks and are subtly incompatible with each other.
但请记住,所有 JSONPath 实现都有独特的功能/怪癖,并且彼此之间存在微妙的不兼容。
Exceptions 例外情况
Basic URL exceptions shall not disable rules with the $jsonprune
modifier. They can be disabled as described below:
基本 URL 例外不得禁用带有$jsonprune
修饰符的规则。可以按如下所述禁用它们:
@@||example.org^$jsonprune
disables all$jsonprune
rules for responses from URLs matching||example.org^
.@@||example.org^$jsonprune
对来自匹配||example.org^
URL 的响应禁用所有$jsonprune
规则。@@||example.org^$jsonprune=text
disables all$jsonprune
rules with the value of the$jsonprune
modifier equal totext
for responses from URLs matching||example.org^
.
@@||example.org^$jsonprune=text
禁用所有$jsonprune
规则,其$jsonprune
修饰符的值等于来自匹配||example.org^
URL 的响应的text
。
$jsonprune
rules can also be disabled by $document
, $content
and $urlblock
exception rules.$jsonprune
规则也可以通过$document
、 $content
和$urlblock
异常规则禁用。
When multiple $jsonprune
rules match the same request, they are sorted in lexicographical order, the first rule is applied to the original response, and each of the remaining rules is applied to the result of applying the previous one.
当多个$jsonprune
规则匹配同一请求时,它们按字典顺序排序,第一个规则应用于原始响应,其余每个规则应用于应用前一个规则的结果。
Examples 示例
||example.org^$jsonprune=\$..[one\, "two three"]
removes all occurrences of the keys "one" and "two three" anywhere in the JSON document.
||example.org^$jsonprune=\$..[one\, "two three"]
删除 JSON 文档中任意位置出现的所有键“一”和“二三”。
Input 输入
Output 输出
||example.org^$jsonprune=\$.a[?(has ad_origin)]
removes all children ofa
that have anad_origin
key.
||example.org^$jsonprune=\$.a[?(has ad_origin)]
删除a
的所有具有ad_origin
键的子级。
Input 输入
Output 输出
||example.org^$jsonprune=\$.*.*[?(key-eq 'Some key' 'Some value')]
removes all items that are at nesting level 3 and have a property "Some key" equal to "Some value".
||example.org^$jsonprune=\$.*.*[?(key-eq 'Some key' 'Some value')]
删除嵌套级别 3 且属性“Some key”等于“Some value”的所有项目。
Input 输入
Output 输出
Nested JSONPath expressions
嵌套 JSONPath 表达式
In AdGuard for Windows, Mac and Android with CoreLibs v1.11 or later, JSONPath expressions may be used as keys in filter expressions.
在带有CoreLibs v1.11 或更高版本的 Windows、Mac 和 Android 版 AdGuard 中,JSONPath 表达式可以用作过滤器表达式中的键。
||example.org^$jsonprune=\$.elems[?(has "\$.a.b.c")]
removes all children ofelems
which have a property selectable by the JSONPath expression$.a.b.c
.
||example.org^$jsonprune=\$.elems[?(has "\$.a.b.c")]
删除具有可由 JSONPath 表达式$.abc
选择的属性的elems
的所有子级。
Input 输入
Output 输出
||example.org^$jsonprune=\$.elems[?(key-eq "\$.a.b.c" "abc")]
removes all children ofelems
which have a property selectable by the JSONPath expression$.a.b.c
with a value equal to"abc"
.
||example.org^$jsonprune=\$.elems[?(key-eq "\$.a.b.c" "abc")]
删除具有可由 JSONPath 表达式$.abc
选择且值等于"abc"
的属性的elems
的所有子级。
Input 输入
Output 输出
$jsonprune
rules are only compatible with these modifiers:$domain
,$third-party
,$strict-third-party
,$strict-first-party
,$app
,$important
,$match-case
, and$xmlhttprequest
.$jsonprune
规则仅与以下修饰符兼容:$domain
、$third-party
、$strict-third-party
、$strict-first-party
、$app
、$important
、$match-case
和$xmlhttprequest
。$jsonprune
rules do not apply if the size of the original response is greater than 10 MB.
如果原始响应的大小大于 10 MB,则$jsonprune
规则不适用。
$xmlprune
$xmlprune
rules modify the response to a matching request by removing XML items that match an XPath 1.0 expression.
The expression must return a node-set.
$xmlprune
rules do not modify responses which are not well-formed XML documents.$xmlprune
规则通过删除与XPath 1.0表达式匹配的 XML 项来修改对匹配请求的响应。该表达式必须返回一个节点集。
$xmlprune
规则不会修改不是格式良好的 XML 文档的响应。
Syntax 句法
||example.org^$xmlprune=expression
removes items that match the XPath expressionexpression
from the response.
||example.org^$xmlprune=expression
从响应中删除与 XPathexpression
匹配的项目。
Due to the way rule parsing works, the characters $
and ,
must be escaped with \
inside expression
.
由于规则解析的工作方式,字符$
和,
必须在expression
内使用\
进行转义。
Exceptions 例外情况
Basic URL exceptions shall not disable rules with the $xmlprune
modifier. They can be disabled as described below:
基本 URL 例外不得禁用带有$xmlprune
修饰符的规则。可以按如下所述禁用它们:
@@||example.org^$xmlprune
disables all$xmlprune
rules for responses from URLs matching||example.org^
.@@||example.org^$xmlprune
对来自匹配||example.org^
URL 的响应禁用所有$xmlprune
规则。@@||example.org^$xmlprune=text
disables all$xmlprune
rules with the value of the$xmlprune
modifier equal totext
for responses from URLs matching||example.org^
.
@@||example.org^$xmlprune=text
禁用所有$xmlprune
规则,其中$xmlprune
修饰符的值等于来自匹配||example.org^
URL 的响应的text
。
$xmlprune
rules can also be disabled by $document
, $content
and $urlblock
exception rules.$xmlprune
规则也可以通过$document
、 $content
和$urlblock
异常规则禁用。
When multiple $xmlprune
rules match the same request, they are applied in lexicographical order.
当多个$xmlprune
规则匹配同一请求时,它们将按字典顺序应用。
Examples 示例
||example.org^$xmlprune=/bookstore/book[position() mod 2 = 1]
removes odd-numbered books from the bookstore.
||example.org^$xmlprune=/bookstore/book[position() mod 2 = 1]
从书店中删除奇数书籍。
Input 输入
Output 输出
||example.org^$xmlprune=/bookstore/book[year = 2003]
removes books from the year 2003 from the bookstore.
||example.org^$xmlprune=/bookstore/book[year = 2003]
从书店中删除 2003 年的书籍。
Input 输入
Output 输出
||example.org^$xmlprune=//*/@*
removes all attributes from all elements.
||example.org^$xmlprune=//*/@*
删除所有元素的所有属性。
Input 输入
Output 输出
$xmlprune
rules are only compatible with these modifiers:$domain
,$third-party
,$strict-third-party
,$strict-first-party
,$app
,$important
,$match-case
, and$xmlhttprequest
.$xmlprune
规则仅与以下修饰符兼容:$domain
、$third-party
、$strict-third-party
、$strict-first-party
、$app
、$important
、$match-case
和$xmlhttprequest
。$xmlprune
rules do not apply if the size of the original response is greater than 10 MB.
如果原始响应的大小大于 10 MB,则$xmlprune
规则不适用。
$network
This is basically a Firewall-like rule allowing to fully block or unblock access to a specified remote address.
这基本上是一个类似防火墙的规则,允许完全阻止或取消阻止对指定远程地址的访问。
$network
rules match IP addresses only! You cannot use them to block or unblock access to a domain.$network
规则仅匹配IP地址!您不能使用它们来阻止或取消阻止对域的访问。- To match an IPv6 address, you have to use the collapsed syntax, e.g. use
[2001:4860:4860::8888]$network
instead of[2001:4860:4860:0:0:0:0:8888]$network
.
要匹配 IPv6 地址,您必须使用折叠语法,例如使用[2001:4860:4860::8888]$network
而不是[2001:4860:4860:0:0:0:0:8888]$network
。 - An allowlist
$network
rule makes AdGuard bypass data to the matching endpoint, hence there will be no further filtering at all.
白名单$network
规则使 AdGuard 绕过数据到匹配的端点,因此根本不会进行进一步的过滤。 - If the IP part starts and ends with
/
character, it is treated as a regular expression.
如果 IP 部分以/
字符开头和结尾,则将其视为正则表达式。
We recommend to get acquainted with this article for better understanding of regular expressions.
我们建议您熟悉本文,以便更好地理解正则表达式。
The $network
modifier can only be used in rules together with the $app
and $important
modifiers, and not with any other modifiers.$network
修饰符只能在规则中与$app
和$important
修饰符一起使用,而不能与任何其他修饰符一起使用。
Examples 示例
174.129.166.49:3478^$network
blocks access to174.129.166.49:3478
(but not to174.129.166.49:34788
).174.129.166.49:3478^$network
阻止访问174.129.166.49:3478
(但不阻止174.129.166.49:34788
)。[2001:4860:4860::8888]:443^$network
blocks access to[2001:4860:4860::8888]:443
.
[2001:4860:4860::8888]:443^$network
阻止访问[2001:4860:4860::8888]:443
。174.129.166.49$network
blocks access to174.129.166.49:*
.174.129.166.49$network
阻止访问174.129.166.49:*
。@@174.129.166.49$network
makes AdGuard bypass data to the endpoint. No other rules will be applied.@@174.129.166.49$network
使 AdGuard 绕过数据到端点。不适用其他规则。/.+:3[0-9]{4}/$network
blocks access to any port from 30000 to 39999./.+:3[0-9]{4}/$network
阻止访问 30000 到 39999 之间的任何端口。/8.8.8.(:?8|4)/$network
blocks access to both8.8.8.8
and8.8.8.4
./8.8.8.(:?8|4)/$network
阻止访问8.8.8.8
和8.8.8.4
。
Only AdGuard for Windows, Mac, and Android are technically capable of using rules with $network
modifier.
从技术上讲,只有适用于 Windows、Mac 和 Android 的 AdGuard 能够使用带有$network
修饰符的规则。
$permissions
This modifier completely changes the rule behavior. If it is applied to a rule, the rule will not block the matching request. Response headers will be modified instead.
此修饰符完全改变了规则行为。如果应用于规则,则该规则不会阻止匹配的请求。响应标头将被修改。
In order to use this type of rules, it is required to have a basic understanding of the Permissions Policy security layer.
为了使用此类规则,需要对权限策略安全层有基本的了解。
For the requests matching a $permissions
rule, AdGuard strengthens response's permissions policy by adding an additional permission policy equal to the $permissions
modifier contents. $permissions
rules are applied independently from any other rule type. Only document-level exceptions can influence it (see the examples section), but no other basic rules.
对于匹配$permissions
规则的请求,AdGuard 通过添加与$permissions
修饰符内容相同的附加权限策略来增强响应的权限策略。 $permissions
规则的应用独立于任何其他规则类型。只有文档级异常可以影响它(请参阅示例部分),但没有其他基本规则。
Syntax 句法
$permissions
value syntax is identical to that of the Permissions-Policy
header syntax with the following exceptions:$permissions
值语法与Permissions-Policy
标头语法相同,但有以下例外:
- A comma that separates multiple features MUST be escaped — see examples below.
分隔多个功能的逗号必须转义 - 请参阅下面的示例。 - A pipe character (
|
) can be used instead of a comma to separate features.
可以使用竖线字符 (|
) 代替逗号来分隔功能。
The list of available directives is available here.
可用指令的列表可在此处找到。
$permissions
value can be empty in the case of exception rules — see examples below.
在例外规则的情况下, $permissions
值可以为空 - 请参阅下面的示例。
Examples 示例
||example.org^$permissions=autoplay=()
disallows autoplay media requested through theHTMLMediaElement
interface acrossexample.org
.
||example.org^$permissions=autoplay=()
不允许通过example.org
上的HTMLMediaElement
接口请求自动播放媒体。@@||example.org/page/*$permissions=autoplay=()
disables all rules with the$permissions
modifier exactly matchingautoplay=()
on all the pages matching the rule pattern. For instance, the rule above. It is important to note that the exception rule only takes effect in the case of an exact value match. For example, if you want to disable the rule$permissions=a=()\,b=()
, you need exception rule@@$permissions=a=()\,b=()
, and not@@$permissions=b=()\,a=()
, nor@@$permissions=b=()
becauseb=()\,a=()
orb=()
does not match witha=()\,b=()
.
@@||example.org/page/*$permissions=autoplay=()
在与规则模式匹配的所有页面上禁用与$permissions
修饰符完全匹配autoplay=()
所有规则。例如上面的规则。需要注意的是,例外规则仅在值精确匹配的情况下才生效。例如,如果要禁用规则$permissions=a=()\,b=()
,则需要例外规则@@$permissions=a=()\,b=()
,而不是@@$permissions=b=()\,a=()
,也不是@@$permissions=b=()
因为b=()\,a=()
或b=()
与a=()\,b=()
不匹配a=()\,b=()
。@@||example.org/page/*$permissions
disables all the$permissions
rules on all the pages matching the rule pattern.
@@||example.org/page/*$permissions
禁用与规则模式匹配的所有页面上的所有$permissions
规则。$domain=example.org|example.com,permissions=storage-access=()\, camera=()
disallows using the Storage Access API to request access to unpartitioned cookies and using video input devices acrossexample.org
andexample.com
.
$domain=example.org|example.com,permissions=storage-access=()\, camera=()
不允许使用存储访问 API 请求访问未分区的 cookie 以及跨example.org
和example.com
使用视频输入设备。$domain=example.org|example.com,permissions=storage-access=()|camera=()
does the same — a|
can be used to separate the features instead of an escaped comma.
$domain=example.org|example.com,permissions=storage-access=()|camera=()
做同样的事 - a|
可以用来分隔功能而不是转义逗号。@@||example.org^$document
or@@||example.org^$urlblock
disables all the$permission
rules on all the pages matching the rule pattern.@@||example.org^$document
或@@||example.org^$urlblock
禁用所有与规则模式匹配的页面上的所有$permission
规则。
$permissions
rules only take effect for main frame and sub frame requests. This means they are applied when a page is loaded or when an iframe is loaded.$permissions
规则仅对主框架和子框架请求生效。这意味着它们在加载页面或加载 iframe 时应用。
If there are multiple $permissions
rules that match the same request, multiple Permissions-Policy
headers will be added to the response for each rule with their $permissions
value. So if you have two rules: ||example.org^$permissions=autoplay=()
and ||example.org^$permissions=geolocation=()\,camera=()
that match the same request, the response will contain two Permissions-Policy
headers: autoplay=()
and geolocation=()\,camera=()
.
如果有多个$permissions
规则匹配同一请求,则多个Permissions-Policy
标头将添加到每个规则的响应中及其$permissions
值。所以如果你有两条规则: ||example.org^$permissions=autoplay=()
和 ||example.org^$permissions=geolocation=()\,camera=()
匹配相同的请求,响应将包含两个Permissions-Policy
标头: autoplay=()
和geolocation=()\,camera=()
。
$permissions
modifier limitations
$permissions
修饰符限制
Firefox ignores the Permissions-Policy
header. For more information, see this issue.
Firefox 会忽略Permissions-Policy
标头。有关更多信息,请参阅此问题。
- Characters forbidden in the
$permissions
value:$
.$permissions
值中禁止使用的字符:$
。 $permissions
is compatible with a limited set of modifiers:$domain
,$important
,$subdocument
, and content-type modifiers.$permissions
与一组有限的修饰符兼容:$domain
、$important
、$subdocument
和content-type modifiers 。$permissions
rules that do not have any content-type modifiers will match only requests where content type isdocument
.
没有任何内容类型修饰符的$permissions
规则将仅匹配内容类型为document
请求。
- Rules with the
$permissions
modifier are supported by AdGuard for Windows, AdGuard for Mac, and AdGuard for Android with CoreLibs v1.11 or later, and AdGuard Browser Extension with TSUrlFilter v3.0.0 or later.
使用CoreLibs v1.11 或更高版本的 AdGuard for Windows、AdGuard for Mac 和 AdGuard for Android 以及带有TSUrlFilter v3.0.0 或更高版本的 AdGuard 浏览器扩展支持带有$permissions
修饰符的规则。 - Pipe separator
|
instead of escaped comma is supported by AdGuard for Windows, AdGuard for Mac, and AdGuard for Android with CoreLibs v1.14 or later, and AdGuard Browser Extension with TSUrlFilter v3.0.0 or later.
管道分离器|
带有CoreLibs v1.14 或更高版本的 AdGuard for Windows、AdGuard for Mac 和 AdGuard for Android 以及带有TSUrlFilter v3.0.0 或更高版本的 AdGuard 浏览器扩展支持代替转义逗号。
$redirect
AdGuard is able to redirect web requests to a local "resource".
AdGuard 能够将网络请求重定向到本地“资源”。
Syntax 句法
AdGuard uses the same filtering rule syntax as uBlock Origin. Also, it is compatible with ABP $rewrite=abp-resource
modifier.
AdGuard 使用与 uBlock Origin 相同的过滤规则语法。此外,它与 ABP $rewrite=abp-resource
修饰符兼容。
$redirect
is a modifier for the basic filtering rules so rules with this modifier support all other basic modifiers like $domain
, $third-party
, $script
, etc.$redirect
是基本过滤规则的修饰符,因此具有此修饰符的规则支持所有其他基本修饰符,例如$domain
、 $third-party
、 $script
等。
The value of the $redirect
modifier must be the name of the resource that will be used for redirection.$redirect
修饰符的值必须是将用于重定向的资源的名称。
Disabling $redirect
rules
禁用$redirect
规则
||example.org/script.js$script,redirect=noopjs
— this rule redirects all requests toexample.org/script.js
to the resource namednoopjs
.
||example.org/script.js$script,redirect=noopjs
— 此规则将所有对example.org/script.js
请求重定向到名为noopjs
的资源。||example.org/test.mp4$media,redirect=noopmp4-1s
— this rule redirects all requests toexample.org/test.mp4
to the resource namednoopmp4-1s
.
||example.org/test.mp4$media,redirect=noopmp4-1s
— 此规则将所有对example.org/test.mp4
的请求重定向到名为noopmp4-1s
的资源。@@||example.org^$redirect
will disable all$redirect
rules for URLs that match||example.org^
.@@||example.org^$redirect
将禁用与||example.org^
匹配的 URL 的所有$redirect
规则。@@||example.org^$redirect=nooptext
will disable all rules with$redirect=nooptext
for any request that matches||example.org^
.
@@||example.org^$redirect=nooptext
对于任何匹配||example.org^
的请求,将禁用$redirect=nooptext
的所有规则。
More information on redirects and their usage is available on GitHub.
有关重定向及其用法的更多信息,请访问GitHub 。
Priorities of $redirect
rules
$redirect
规则的优先级
$redirect
rules have higher priority than regular basic blocking rules.
This means that if there is a basic blocking rule, the $redirect
rule will override it.
Allowlist rules with @@
mark have higher priority than $redirect
rules.
If a basic rule with the $important
modifier and the $redirect
rule matches the same URL,
the latter is overridden unless it's also marked as $important
.$redirect
规则比常规基本阻止规则具有更高的优先级。这意味着如果存在基本阻止规则, $redirect
规则将覆盖它。带有@@
标记的白名单规则比$redirect
规则具有更高的优先级。如果带有$important
修饰符的基本规则和$redirect
规则匹配相同的 URL,则后者将被覆盖,除非它也被标记为$important
。
In short: $important
> @@
> $redirect
> basic rules
.
简而言之: $important
> @@
> $redirect
> basic rules
。
Go to rules priorities for more details.
请参阅规则优先级了解更多详细信息。
$redirect
modifier limitations
$redirect
修饰符限制
In AdGuard for Chrome MV3 allowlist rules with $redirect
are not supported.
在AdGuard for Chrome MV3中,不支持使用$redirect
的白名单规则。
- Rules with
$redirect
modifier are not supported by AdGuard Content Blocker, AdGuard for iOS, and AdGuard for Safari .
AdGuard 内容拦截器、 AdGuard for iOS和AdGuard for Safari不支持带有$redirect
修饰符的规则。 $redirect
in uBlock Origin supports specifying priority, e.g.$redirect=noopjs:42
. AdGuard does not support it and instead just discards the priority postfix.
uBlock Origin 中的$redirect
支持指定优先级,例如$redirect=noopjs:42
。 AdGuard 不支持它,而是丢弃优先级后缀。
$redirect-rule
This is basically an alias to $redirect
since it has the same "redirection" values and the logic is almost similar. The difference is that $redirect-rule
is applied only in the case when the target request is blocked by a different basic rule.
这基本上是$redirect
的别名,因为它具有相同的“重定向”值并且逻辑几乎相似。不同之处在于$redirect-rule
仅在目标请求被不同的基本规则阻止的情况下应用。
Go to rules priorities for more details.
请参阅规则优先级了解更多详细信息。
Negating $redirect-rule
works exactly the same way as for regular $redirect
rules. Even more than that, @@||example.org^$redirect
will negate both $redirect
and $redirect-rule
rules.
否定$redirect-rule
工作方式与常规$redirect
规则完全相同。更重要的是, @@||example.org^$redirect
将否定$redirect
和$redirect-rule
规则。
Examples 示例
||example.org/script.js
||example.org^$redirect-rule=noopjs
In this case, only requests to example.org/script.js
will be "redirected" to noopjs
. All other requests to example.org
will be kept intact.
在这种情况下,只有对example.org/script.js
的请求才会被“重定向”到noopjs
。对example.org
所有其他请求将保持不变。
Rules with $redirect-rule
modifier are not supported by AdGuard Content Blocker, AdGuard for iOS, AdGuard for Safari, and AdGuard for Chrome MV3. The discussion about adding support for $redirect-rule
rules in Chrome MV3 extensions is currently open.
AdGuard Content Blocker 、 AdGuard for iOS 、 AdGuard for Safari和AdGuard for Chrome MV3不支持带有$redirect-rule
修饰符的规则。关于在 Chrome MV3 扩展中添加对$redirect-rule
规则的支持的讨论目前正在进行中。
$referrerpolicy
These rules allow overriding of a page's referrer policy.
Responses to matching requests will have all of their Referrer-Policy
headers replaced with a single header with the value equal to the matching rule's modifier value.
If the response carries an HTML document with a <meta name="referrer"...
tag, the content
attribute of the tag will also be replaced with the modifier value.
这些规则允许覆盖页面的引荐来源网址策略。对匹配请求的响应将其所有Referrer-Policy
标头替换为单个标头,其值等于匹配规则的修饰符值。如果响应携带带有<meta name="referrer"...
标记的 HTML 文档,则该标记的content
属性也将替换为修饰符值。
An exception rule with a modifier value disables the blocking rule with the same modifier value.
An exception rule without a modifier value disables all matched referrer-policy rules.
具有修饰符值的例外规则会禁用具有相同修饰符值的阻止规则。没有修饰符值的例外规则会禁用所有匹配的引荐来源网址策略规则。
If a request matches multiple $referrerpolicy
rules not disabled by exceptions, only one of them (it is not specified which one) is applied. $referrerpolicy
rules without specified content-type modifiers apply to $document
and $subdocument
content types.
如果请求匹配多个未因异常而禁用的$referrerpolicy
规则,则仅应用其中之一(未指定哪一个)。没有指定内容类型修饰符的$referrerpolicy
规则适用于$document
和$subdocument
内容类型。
Examples 示例
||example.com^$referrerpolicy=unsafe-url
overrides the referrer policy forexample.com
withunsafe-url
.
||example.com^$referrerpolicy=unsafe-url
使用unsafe-url
覆盖example.com
的引荐来源网址策略。@@||example.com^$referrerpolicy=unsafe-url
disables the previous rule.
@@||example.com^$referrerpolicy=unsafe-url
禁用之前的规则。@@||example.com/abcd.html^$referrerpolicy
disables all$referrerpolicy
rules onexample.com/abcd.html
.
@@||example.com/abcd.html^$referrerpolicy
禁用example.com/abcd.html
上的所有$referrerpolicy
规则。
$removeheader
Rules with $removeheader
modifier are intended to remove headers from HTTP requests and responses. The initial motivation for this rule type is to be able to get rid of the Refresh
header which is often used to redirect users to an undesirable location. However, this is not the only case where this modifier can be useful.
带有$removeheader
修饰符的规则旨在从 HTTP 请求和响应中删除标头。此规则类型的最初动机是能够摆脱Refresh
标头,该标头通常用于将用户重定向到不需要的位置。然而,这并不是该修饰符有用的唯一情况。
Just like $csp
, $redirect
, $removeparam
, and $cookie
, this modifier exists independently, rules with it do not depend on the regular basic rules, i.e. regular exception or blocking rules will not affect it. By default, it only affects response headers. However, you can also change it to remove headers from HTTP requests as well.
就像$csp
、 $redirect
、 $removeparam
和$cookie
一样,这个修饰符独立存在,带有它的规则不依赖于常规的基本规则,即常规的异常或阻塞规则不会影响它。默认情况下,它仅影响响应标头。但是,您也可以更改它以从 HTTP 请求中删除标头。
Syntax 句法
Basic syntax 基本语法
||example.org^$removeheader=header-name
removes a response header calledheader-name
||example.org^$removeheader=header-name
删除名为header-name
的响应标头||example.org^$removeheader=request:header-name
removes a request header calledheader-name
||example.org^$removeheader=request:header-name
删除名为header-name
的请求标头
$removeheader
is case-insensitive, but we suggest always using lower case.$removeheader
不区分大小写,但我们建议始终使用小写。
Negating $removeheader
否定$removeheader
This type of rules works pretty much the same way it works with $csp
and $redirect
modifiers.
这种类型的规则的工作方式与$csp
和$redirect
修饰符的工作方式几乎相同。
Use @@
to negate $removeheader
:
使用@@
来否定$removeheader
:
@@||example.org^$removeheader
negates all$removeheader
rules for URLs that match||example.org^
.@@||example.org^$removeheader
否定与||example.org^
匹配的 URL 的所有$removeheader
规则。@@||example.org^$removeheader=header
negates the rule with$removeheader=header
for any request matching||example.org^
.
@@||example.org^$removeheader=header
对于任何匹配||example.org^
请求,使用$removeheader=header
否定规则。
$removeheader
rules can also be disabled by $document
and $urlblock
exception rules. But basic exception rules without modifiers will not do that. For example, @@||example.com^
will not disable $removeheader=p
for requests to example.com
, but @@||example.com^$urlblock
will.$removeheader
规则也可以通过$document
和$urlblock
异常规则禁用。但没有修饰符的基本例外规则不会这样做。例如, @@||example.com^
不会禁用$removeheader=p
对于example.com
的请求,但@@||example.com^$urlblock
会。
In case of multiple $removeheader
rules matching a single request, we will apply each of them one by one.
如果多个$removeheader
规则匹配单个请求,我们将一一应用它们。
Examples 示例
||example.org^$removeheader=refresh
removesRefresh
header from all HTTP responses returned byexample.org
and its subdomains.
||example.org^$removeheader=refresh
从example.org
及其子域返回的所有 HTTP 响应中删除Refresh
标头。||example.org^$removeheader=request:x-client-data
removesX-Client-Data
header from all HTTP requests.
||example.org^$removeheader=request:x-client-data
从所有 HTTP 请求中删除X-Client-Data
标头。Next block of rules removes
Refresh
andLocation
headers from all HTTP responses returned byexample.org
save for requests toexample.org/path/*
, for which no headers will be removed:
下一个规则块将从example.org
返回的所有 HTTP 响应中删除Refresh
和Location
标头,保存对example.org/path/*
的请求,不会删除任何标头:||example.org^$removeheader=refresh
||example.org^$removeheader=location
@@||example.org/path/$removeheader
This type of rules can only be used in trusted filters.
这种类型的规则只能在受信任的过滤器中使用。
In order to avoid compromising the security
$removeheader
cannot remove headers from the list below:
为了避免损害安全性,$removeheader
无法从下面的列表中删除标头:access-control-allow-origin
access-control-allow-credentials
access-control-allow-headers
access-control-allow-methods
access-control-expose-headers
access-control-max-age
access-control-request-headers
access-control-request-method
origin
timing-allow-origin
allow
cross-origin-embedder-policy
cross-origin-opener-policy
cross-origin-resource-policy
content-security-policy
content-security-policy-report-only
expect-ct
feature-policy
origin-isolation
strict-transport-security
upgrade-insecure-requests
x-content-type-options
x-download-options
x-frame-options
x-permitted-cross-domain-policies
x-powered-by
x-xss-protection
public-key-pins
public-key-pins-report-only
sec-websocket-key
sec-websocket-extensions
sec-websocket-accept
sec-websocket-protocol
sec-websocket-version
p3p
sec-fetch-mode
sec-fetch-dest
sec-fetch-site
sec-fetch-user
referrer-policy
content-type
content-length
accept
accept-encoding
host
connection
transfer-encoding
upgrade
$removeheader
rules are only compatible with$domain
,$third-party
,$strict-third-party
,$strict-first-party
,$app
,$important
,$match-case
, and content type modifiers such as$script
and$stylesheet
. The rules which have any other modifiers are considered invalid and will be discarded.$removeheader
规则仅与$domain
、$third-party
、$strict-third-party
、$strict-first-party
、$app
、$important
、$match-case
以及内容类型修饰符(例如$script
和$stylesheet
兼容$stylesheet
。具有任何其他修饰符的规则将被视为无效并被丢弃。
Rules with $removeheader
modifier are supported by AdGuard for Windows, AdGuard for Mac, AdGuard for Android, and AdGuard Browser Extension for Chrome, Firefox, and Edge.
带$removeheader
修饰符的规则受适用于 Windows 的 AdGuard、适用于 Mac 的 AdGuard、适用于 Android 的 AdGuard 以及适用于 Chrome、Firefox 和 Edge 的 AdGuard 浏览器扩展支持。
$removeparam
$queryprune
is an alias of $removeparam
. Since $queryprune
is deprecated, avoid using it and use $removeparam
instead.$queryprune
是$removeparam
的别名。由于$queryprune
已被弃用,因此请避免使用它并使用$removeparam
代替。
Rules with $removeparam
modifier are intended to strip query parameters from requests' URLs. Please note that such rules are only applied to GET
, HEAD
, OPTIONS
, and sometimes POST
requests.
带有$removeparam
修饰符的规则旨在从请求的 URL 中删除查询参数。请注意,此类规则仅适用于GET
、 HEAD
、 OPTIONS
,有时还适用于POST
请求。
Syntax 句法
Basic syntax 基本语法
$removeparam=param
removes query parameter with the nameparam
from URLs of any request, e.g. a request tohttp://example.com/page?param=1&another=2
will be transformed intohttp://example.com/page?another=2
.$removeparam=param
从任何请求的 URL 中删除带有名称param
查询参数,例如请求http://example.com/page?param=1&another=2
将转化为http://example.com/page?another=2
。
Regular expressions 正则表达式
You can also use regular expressions to match query parameters and/or their values:
您还可以使用正则表达式来匹配查询参数和/或其值:
$removeparam=/regexp/[options]
— removes query parameters that matches theregexp
regular expression from URLs of any request. Unlike basic syntax, it means "remove query parameters normalized to aname=value
string which match theregexp
regular expression".[options]
here is the list of regular expression options. At the moment, the only supported option isi
which makes matching case-insensitive.
$removeparam=/regexp/[options]
— 从任何请求的 URL 中删除与regexp
正则表达式匹配的查询参数。与基本语法不同,它的意思是“删除规范化为与regexp
正则表达式匹配的name=value
字符串的查询参数” 。[options]
这里是正则表达式选项的列表。目前,唯一支持的选项是i
,它使匹配不区分大小写。
Escaping special characters
转义特殊字符
Do not forget to escape special characters like ,
, /
and $
in the regular expressions. Use \
character for that purpose. For example, an escaped comma should look like this: \,
.
不要忘记在正则表达式中转义,
、 /
和$
等特殊字符。为此目的使用\
字符。例如,转义逗号应如下所示: \,
。
Regexp-type rules target both name and value of the parameter. To minimize mistakes, it is safer to start every regexp with /^
unless you specifically target parameter values.
正则表达式类型规则以参数的名称和值为目标。为了最大限度地减少错误,除非您专门针对参数值,否则以/^
开头每个正则表达式会更安全。
We will try to detect and ignore unescaped $
automatically using a simple rule of thumb — it is not an options delimiter if all three are true:
我们将尝试使用简单的经验法则自动检测和忽略未转义的$
— 如果这三个都为 true,则它不是选项分隔符:
- It looks like
$/
看起来像$/
- There is another slash character
/
to the left of it
其左侧还有一个斜杠字符/
- There is another unescaped dollar sign
$
to the left of that slash character
该斜杠字符的左侧还有另一个未转义的美元符号$
Remove all query parameters
删除所有查询参数
Specify naked $removeparam
to remove all query parameters:
指定naked $removeparam
以删除所有查询参数:
||example.org^$removeparam
— removes all query parameters from URLs matching||example.org^
.||example.org^$removeparam
— 从匹配||example.org^
URL 中删除所有查询参数。
Inversion 反转
Use ~
to apply inversion:
使用~
应用反转:
$removeparam=~param
— removes all query parameters with the name different fromparam
.$removeparam=~param
— 删除名称与param
不同的所有查询参数。$removeparam=~/regexp/
— removes all query parameters that do not match theregexp
regular expression.$removeparam=~/regexp/
— 删除所有与regexp
正则表达式不匹配的查询参数。
Negating $removeparam
否定$removeparam
This sort of rules work pretty much the same way it works with $csp
and $redirect
modifiers.
这种规则的工作方式与$csp
和$redirect
修饰符的工作方式几乎相同。
Use @@
to negate $removeparam
:
使用@@
来否定$removeparam
:
@@||example.org^$removeparam
negates all$removeparam
rules for URLs that match||example.org^
.@@||example.org^$removeparam
否定匹配||example.org^
URL 的所有$removeparam
规则。@@||example.org^$removeparam=param
negates the rule with$removeparam=param
for any request matching||example.org^
.
@@||example.org^$removeparam=param
对于任何匹配||example.org^
请求,使用$removeparam=param
否定规则。@@||example.org^$removeparam=/regexp/
negates the rule with$removeparam=/regexp/
for any request matching||example.org^
.
@@||example.org^$removeparam=/regexp/
对于任何匹配||example.org^
请求,使用$removeparam=/regexp/
否定规则。
Multiple rules matching a single request
多个规则匹配单个请求
In the case when multiple $removeparam
rules match a single request, each of them will be applied one by one.
如果多个$removeparam
规则与单个请求匹配,则每个规则都将被一一应用。
Examples 示例
$removeparam=/^(utm_source|utm_medium|utm_term)=/
$removeparam=/^(utm_content|utm_campaign|utm_referrer)=/
@@||example.com^$removeparam
With these rules some UTM parameters will be stripped out from any request, except that requests to example.com
will not be stripped at all, e.g. http://google.com/page?utm_source=s&utm_referrer=fb.com&utm_content=img
will be transformed to http://google.com/page
, but http://example.com/page?utm_source=s&utm_referrer=fb.com&utm_content=img
will not be affected by the blocking rule.
使用这些规则,某些UTM 参数将从任何请求中删除,但对example.com
的请求根本不会被删除,例如 http://google.com/page?utm_source=s&utm_referrer=fb.com&utm_content=img
将转换为http://google.com/page
,但是 http://example.com/page?utm_source=s&utm_referrer=fb.com&utm_content=img
不会受到屏蔽规则的影响。
$removeparam=utm_source
removesutm_source
query parameter from all requests.$removeparam=utm_source
从所有请求中删除utm_source
查询参数。$removeparam=/utm_.*/
removes allutm_* query
parameters from URL queries of any request, e.g. a request tohttp://example.com/page?utm_source=test
will be transformed tohttp://example.com/page
.$removeparam=/utm_.*/
从任何请求的 URL 查询中删除所有utm_* query
参数,例如请求http://example.com/page?utm_source=test
将转换为http://example.com/page
。$removeparam=/^utm_source=campaign$/
removesutm_source
query parameter with the value equal tocampaign
. It does not touch otherutm_source
parameters.
$removeparam=/^utm_source=campaign$/
删除utm_source
查询参数,其值等于campaign
。它不会触及其他utm_source
参数。
Negating one $removeparam
rule and replacing it with a different rule
否定一条$removeparam
规则并将其替换为另一条规则
$removeparam=/^(gclid|yclid|fbclid)=/
@@||example.com^$removeparam=/^(gclid|yclid|fbclid)=/
||example.com^$removeparam=/^(yclid|fbclid)=/
With these rules, Google, Yandex, and Facebook Click IDs will be removed from all requests. There is one exception: Google Click ID (gclid) will not be removed from requests to example.com.
根据这些规则,Google、Yandex 和 Facebook 点击 ID 将从所有请求中删除。有一个例外:Google 点击 ID (gclid) 不会从对 example.com 的请求中删除。
Negating $removeparam
for all parameters
对所有参数否定$removeparam
$removeparam=/^(utm_source|utm_medium|utm_term)=/
$removeparam=/^(utm_content|utm_campaign|utm_referrer)=/
@@||example.com^$removeparam
With these rules, specified UTM parameters will be removed from any request save for requests to example.org
.
使用这些规则,指定的 UTM 参数将从保存到example.org
的请求中删除。
$removeparam
rules can also be disabled by $document
and $urlblock
exception rules. But basic exception rules without modifiers do not do that. For example, @@||example.com^
will not disable $removeparam=p
for requests to example.com, but @@||example.com^$urlblock
will.$removeparam
规则也可以通过$document
和$urlblock
异常规则禁用。但不带修饰符的基本异常规则则不能做到这一点。例如, @@||example.com^
不会禁用$removeparam=p
对于example.com的请求,但@@||example.com^$urlblock
会。
$removeparam
modifier limitations
$removeparam
修饰符限制
AdGuard for Chrome MV3 has some limitations:
AdGuard for Chrome MV3有一些限制:
Regular expressions, negation and allowlist rules are not supported.
不支持正则表达式、否定和白名单规则。Group of similar
$removeparam
rules will be combined into one. Example:
一组类似的$removeparam
规则将合并为一个。例子:||testcases.adguard.com$xmlhttprequest,removeparam=p1case1
||testcases.adguard.com$xmlhttprequest,removeparam=p2case1
||testcases.adguard.com$xmlhttprequest,removeparam=P3Case1
$xmlhttprequest,removeparam=p1case2is converted to 被转换为
[
{
"id": 1,
"action": {
"type": "redirect",
"redirect": {
"transform": {
"queryTransform": {
"removeParams": [
"p1case1",
"p2case1",
"P3Case1"
]
}
}
}
},
"condition": {
"urlFilter": "||testcases.adguard.com",
"resourceTypes": [
"xmlhttprequest"
],
"isUrlFilterCaseSensitive": false
}
},
{
"id": 4,
"action": {
"type": "redirect",
"redirect": {
"transform": {
"queryTransform": {
"removeParams": [
"p1case2"
]
}
}
}
},
"condition": {
"resourceTypes": [
"xmlhttprequest"
],
"isUrlFilterCaseSensitive": false
}
}
]
- Rules with the
$removeparam
modifier can only be used in trusted filters.
带有$removeparam
修饰符的规则只能在受信任的过滤器中使用。 $removeparam
rules are compatible with basic modifiers, content-type modifiers, and with the$important
and$app
modifiers. Rules with any other modifiers are considered invalid and will be discarded.$removeparam
规则与基本修饰符、内容类型修饰符以及$important
和$app
修饰符兼容。具有任何其他修饰符的规则将被视为无效并将被丢弃。$removeparam
rules without content type modifiers will only match requests where the content type isdocument
.
不带内容类型修饰符的$removeparam
规则将仅匹配内容类型为document
请求。
- Rules with
$removeparam
modifier are supported by AdGuard for Windows, AdGuard for Mac, and AdGuard for Android with CoreLibs v1.7 or later, and AdGuard Browser Extension v3.6 or later.
带$removeparam
修饰符的规则受包含CoreLibs v1.7 或更高版本以及 AdGuard 浏览器扩展 v3.6 或更高版本的 AdGuard for Windows、AdGuard for Mac 和 AdGuard for Android 支持。 $removeparam
syntax for regular expressions is supported AdGuard for Windows, AdGuard for Mac, and AdGuard for Android with CoreLibs v1.8 or later, and AdGuard Browser Extension v4.0 or later.
正则表达式的$removeparam
语法受CoreLibs v1.8 或更高版本以及 AdGuard 浏览器扩展 v4.0 或更高版本的 AdGuard for Windows、AdGuard for Mac 和 AdGuard for Android 支持。POST
request types are supported only by AdGuard for Windows, Mac, and Android with CoreLibs v1.10 or later, and AdGuard Browser Extension with TSWebExtension v0.4.6 or later.POST
请求类型仅受具有CoreLibs v1.10 或更高版本的 Windows、Mac 和 Android 版 AdGuard 以及具有TSWebExtension v0.4.6 或更高版本的 AdGuard 浏览器扩展支持。
$replace
This modifier completely changes the rule behavior. If it is applied, the rule will not block the request. The response is going to be modified instead.
此修饰符完全改变了规则行为。如果应用,该规则将不会阻止该请求。相反,响应将被修改。
You will need some knowledge of regular expressions to use $replace
modifier.
您需要一些正则表达式知识才能使用$replace
修饰符。
Features 特征
$replace
rules apply to any text response, but will not apply to binary (media
,image
,object
, etc.).$replace
规则适用于任何文本响应,但不适用于二进制(media
、image
、object
等)。$replace
rules do not apply if the size of the original response is more than 10 MB.
如果原始响应的大小超过 10 MB,则$replace
规则不适用。$replace
rules have a higher priority than other basic rules (including exception rules). So if a request natches two different rules, one of which has the$replace
modifier, this rule will be applied.$replace
规则比其他基本规则(包括例外规则)具有更高的优先级。因此,如果一个请求捕获两个不同的规则,其中之一具有$replace
修饰符,则将应用该规则。- Document-level exception rules with
$content
or$document
modifiers do disable$replace
rules for requests matching them.
带有$content
或$document
修饰符的文档级异常规则会禁用匹配它们的请求的$replace
规则。 - Other document-level exception rules (
$generichide
,$elemhide
or$jsinject
modifiers) are applied alongside$replace
rules. It means that you can modify the page content with a$replace
rule and disable cosmetic rules there at the same time.
其他文档级异常规则($generichide
、$elemhide
或$jsinject
修饰符)与$replace
规则一起应用。这意味着您可以使用$replace
规则修改页面内容并同时禁用修饰规则。
$replace
value can be empty in the case of exception rules. See examples section for further information.
如果有例外规则, $replace
值可以为空。有关更多信息,请参阅示例部分。
Multiple rules matching a single request
多个规则匹配单个请求
In case if multiple $replace
rules match a single request, we will apply each of them. The order is defined alphabetically.
如果多个$replace
规则与单个请求匹配,我们将应用每个规则。顺序是按字母顺序定义的。
Syntax 句法
In general, $replace
syntax is similar to replacement with regular expressions in Perl.
一般来说, $replace
语法类似于Perl 中的正则表达式替换。
replace = "/" regexp "/" replacement "/" modifiers
regexp
— a regular expression.regexp
— 正则表达式。replacement
— a string that will be used to replace the string corresponding toregexp
.replacement
— 将用于替换与regexp
对应的字符串的字符串。modifiers
— a regular expression flags. For example,i
— insensitive search, ors
— single-line mode.modifiers
——正则表达式标志。例如,i
— 不敏感搜索,或s
— 单行模式。
In the $replace
value, two characters must be escaped: comma ,
and dollar sign $
. Use backslash \
for it. For example, an escaped comma looks like this: \,
.
在$replace
值中,必须转义两个字符:逗号,
美元符号$
。使用反斜杠\
来表示它。例如,转义逗号如下所示: \,
。
Examples 示例
||example.org^$replace=/(<VAST[\s\S]*?>)[\s\S]*<\/VAST>/\$1<\/VAST>/i
There are three parts in this rule:
该规则分为三个部分:
regexp
—(<VAST(.|\s)*?>)(.|\s)*<\/VAST>
;regexp
—(<VAST(.|\s)*?>)(.|\s)*<\/VAST>
;replacement
—\$1<\/VAST>
where$
is escaped;replacement
-\$1<\/VAST>
其中$
被转义;modifiers
—i
for insensitive search.modifiers
-i
表示不敏感搜索。
You can see how this rule works here:
http://regexr.com/3cesk
您可以在此处查看此规则的运作方式:
http://regexr.com/3cesk
Multiple $replace
rules
多个$replace
规则
||example.org^$replace=/X/Y/
||example.org^$replace=/Z/Y/
@@||example.org/page/*$replace=/Z/Y/
- Both rule 1 and 2 will be applied to all requests sent to
example.org
.
规则 1 和 2 都将应用于发送到example.org
所有请求。 - Rule 2 is disabled for requests matching
||example.org/page/
, but rule 1 still works!
对于匹配||example.org/page/
请求,规则 2 被禁用,但规则 1 仍然有效!
Disabling $replace
rules
禁用$replace
规则
@@||example.org^$replace
will disable all$replace
rules matching||example.org^
.@@||example.org^$replace
将禁用所有匹配||example.org^
$replace
规则。@@||example.org^$document
or@@||example.org^$content
will disable all$replace
rules originated from pages ofexample.org
including the page itself.@@||example.org^$document
或@@||example.org^$content
将禁用源自example.org
页面(包括页面本身)的所有$replace
规则。
Rules with the $replace
modifier can only be used in trusted filters.
带有$replace
修饰符的规则只能在受信任的过滤器中使用。
Rules with $replace
modifier are supported by AdGuard for Windows, AdGuard for Mac, AdGuard for Android, and AdGuard Browser Extension for Firefox. Such rules do not work in extensions for other browsers because they are unable to modify content on the network level.
带$replace
修饰符的规则受 AdGuard for Windows、AdGuard for Mac、AdGuard for Android 和 AdGuard Browser Extension for Firefox 支持。此类规则不适用于其他浏览器的扩展,因为它们无法修改网络级别的内容。
$urltransform
The $urltransform
rules allow you to modify the request URL by replacing text matched by a regular expression.$urltransform
规则允许您通过替换与正则表达式匹配的文本来修改请求 URL。
Features 特征
$urltransform
rules normally only apply to the path and query parts of the URL, see below for one exception.$urltransform
规则通常仅适用于 URL 的路径和查询部分,请参阅下面的一个例外。$urltransform
will not be applied if the original URL is blocked by other rules.
如果原始 URL 被其他规则阻止,则不会应用$urltransform
。$urltransform
will be applied before$removeparam
rules.$urltransform
将在$removeparam
规则之前应用。
The $urltransform
value can be empty for exception rules.
对于例外规则, $urltransform
值可以为空。
Multiple rules matching a single request
多个规则匹配单个请求
If multiple $urltransform
rules match a single request, we will apply each of them. The order is defined alphabetically.
如果多个$urltransform
规则与单个请求匹配,我们将应用每个规则。顺序是按字母顺序定义的。
Syntax 句法
$urltransform
syntax is similar to replacement with regular expressions in Perl.$urltransform
语法类似于Perl 中的正则表达式替换。