write-ublock-origin-filters
完整的 uBlock Origin (uBO) 静态过滤语法参考。编写 uBlock Origin 自定义过滤规则时使用此技能,涵盖广告拦截、隐私保护或内容过滤。包含基础网络过滤模式(||、*、^、|)、所有网络过滤选项($domain、$third-party、$important、$redirect、$removeparam、$csp、$replace、$header、$method、$denyallow、$badfilter、$all 等)、内容类型选项($script、$image、$stylesheet、$font、$media、$xhr、$popup、$document、$frame 等)、元素隐藏规则(## 选择器、实体匹配、主机名正则)、过程式元素隐藏过滤器(:has、:has-text、:matches-css、:upward、:xpath、:matches-path、:watch-attr 等)、动作操作符(:remove、:style、:remove-attr、:remove-class)、HTML 过滤器(##^)、响应头过滤(##^responseheader)、脚本注入(##+js())以及预处理指令(!#include、!#if)。当用户提到 uBlock Origin 过滤规则、uBO 语法、广告拦截规则、元素隐藏规则、过程式选择器、脚本注入或希望编写/调试任何 uBO 兼容过滤列表时触发。即使用户只是在编写或调试 uBlock Origin 过滤规则、创建自定义过滤列表或从 AdBlock Plus/AdGuard 迁移过滤规则到 uBO,也应使用此技能。
- License 许可
- MIT
- 所属仓库
- luestr/skills
- 最近更新
- 2026-11-14
- Stars
- ★ 94
- Forks
- 1
01 前言 Front Matter
- name
- write-ublock-origin-filters
- metadata
- { "language": "zh-CN" }
- description
- 完整的 uBlock Origin (uBO) 静态过滤语法参考。编写 uBlock Origin 自定义过滤规则时使用此技能,涵盖广告拦截、隐私保护或内容过滤。包含基础网络过滤模式(||、*、^、|)、所有网络过滤选项($domain、$third-party、$important、$redirect、$removeparam、$csp、$replace、$header、$method、$denyallow、$badfilter、$all 等)、内容类型选项($script、$image、$stylesheet、$font、$media、$xhr、$popup、$document、$frame 等)、元素隐藏规则(## 选择器、实体匹配、主机名正则)、过程式元素隐藏过滤器(:has、:has-text、:matches-css、:upward、:xpath、:matches-path、:watch-attr 等)、动作操作符(:remove、:style、:remove-attr、:remove-class)、HTML 过滤器(##^)、响应头过滤(##^responseheader)、脚本注入(##+js())以及预处理指令(!#include、!#if)。当用户提到 uBlock Origin 过滤规则、uBO 语法、广告拦截规则、元素隐藏规则、过程式选择器、脚本注入或希望编写/调试任何 uBO 兼容过滤列表时触发。即使用户只是在编写或调试 uBlock Origin 过滤规则、创建自定义过滤列表或从 AdBlock Plus/AdGuard 迁移过滤规则到 uBO,也应使用此技能。
02 资源文件 8
- 参考文档references/01-network-filter-basics.md4.3 KB
- 参考文档references/02-content-type-options.md3.9 KB
- 参考文档references/03-behavior-modifiers.md5.7 KB
- 参考文档references/04-modifier-filters.md4.6 KB
- 参考文档references/05-cosmetic-filters.md7.1 KB
- 参考文档references/06-html-response-header-filters.md3.1 KB
- 参考文档references/07-scriptlet-injection.md6.6 KB
- 参考文档references/08-preparsing-directives.md4.6 KB
03 SKILL.md 正文
uBlock Origin 静态过滤语法参考
来源:https://github.com/gorhill/uBlock/wiki/Static-filter-syntax
本技能是 uBlock Origin (uBO) 静态过滤语法的完整参考索引。不要一次性加载所有参考文件 — 根据用户的问题只加载相关文件以节省 token。
快速路由:应加载哪个文件
| 用户需求 | 加载文件 |
|---|---|
基础 URL 模式匹配(*、||、^、|)、HOSTS 文件解析、_(noop)、*(所有 URL) |
references/01-network-filter-basics.md |
内容类型选项:$script、$image、$stylesheet/$css、$font、$media、$subdocument/$frame、$object、$other、$ping、$websocket、$xhr、$popup、$document、$top |
references/02-content-type-options.md |
行为修饰符:$third-party/$3p、$first-party/$1p、$domain/$from、$to、$match-case、$important、$badfilter、$denyallow、$method、$header、$strict1p、$strict3p、$all、$elemhide/$ehide、$generichide/$ghide、$specifichide/$shide、$popunder、$inline-script、$inline-font、$cname、$ipaddress、$permissions |
references/03-behavior-modifiers.md |
修改器过滤器(响应修改):$csp、$redirect、$redirect-rule、$removeparam、$replace、$uritransform、$urlskip、$empty、$mp4 |
references/04-modifier-filters.md |
元素隐藏过滤器(##/#@#)、实体匹配、主机名正则、特定泛型、过程式过滤器(:has()、:has-text()、:matches-css()、:upward()、:xpath()、:matches-path()、:watch-attr() 等)、动作操作符(:remove()、:style()、:remove-attr()、:remove-class()) |
references/05-cosmetic-filters.md |
HTML 过滤器(##^)、响应头过滤(##^responseheader()) |
references/06-html-response-header-filters.md |
脚本注入(##+js())、可用脚本、重定向资源、资源库 |
references/07-scriptlet-injection.md |
预处理指令(!#include、!#if/!#else/!#endif)、不支持的功能、兼容性说明 |
references/08-preparsing-directives.md |
规则类型速查
1. 网络过滤器 — 拦截/允许 URL 请求
模式 [$选项]
@@模式 [$选项] (例外/白名单)
||example.com^— 拦截 example.com 及其所有子域名的请求|https://example.com/ad.js|— 精确 URL 匹配@@||example.com^— 白名单允许 example.com||example.com^$important— 强制规则(覆盖例外规则)
2. 元素隐藏过滤器 — 隐藏/修改页面元素
example.com##.ad-banner— 隐藏元素example.com#@#.ad-banner— 例外(取消隐藏)example.com##h1:style(color: red !important)— 注入 CSS 样式example.com##.ad:remove()— 从 DOM 中移除元素
3. HTML 过滤器 — 在浏览器解析前移除 HTML(仅限 Firefox)
example.com##^script:has-text(adScript)— 从响应中移除 script 标签
4. 响应头过滤 — 移除响应头
example.com##^responseheader(refresh)— 移除 refresh 头
5. 脚本注入 — 注入 JavaScript
example.com##+js(set-constant, adBlockDetected, false)— 注入脚本
核心概念
- 注释:以
!开头的行是注释 - 例外规则:以
@@开头的规则允许请求 - 选项/修饰符:
$后的参数,用于限制/改变规则行为 - 域名限制:网络过滤器中的
$domain=,元素隐藏/扩展过滤器中的主机名前缀 - 第三方:
$third-party($3p)限制为跨站请求 - HOSTS 文件格式:uBO 将裸主机名如
example.com解释为||example.com^ - 受信来源:仅 uBO 自带过滤列表和用户的"我的过滤"(如已启用)可用于
$replace、脚本注入等 - 实体匹配:
google.*匹配所有 Google 顶级域名(google.com、google.co.uk 等) - 主机名正则:扩展过滤器中使用
/regex/作为主机名(为性能考虑应谨慎使用)
重要:uBO 与 ABP/AdGuard 的差异
| 功能 | uBO | ABP/AdGuard |
|---|---|---|
document 用于整页例外 |
❌ 不支持 | ✅ 支持 |
genericblock |
❌ 不支持 | ✅ 支持 |
$webrtc 选项 |
❌ 使用 ##+js(nowebrtc) |
✅ 支持 |
$replace 过滤 |
仅受信来源 | 更宽松 |
| HOSTS 文件解释 | example.com → ||example.com^ |
example.com 匹配 URL 中任何位置 |
$badfilter |
✅ 支持 | 部分支持 |
$denyallow |
✅ 支持 | ❌ 不支持 |
HTML 过滤(##^) |
仅 Firefox | CoreLibs 应用 |
| 脚本命名 | uBO 原生 + AG 兼容 | AG 原生 |
04 同仓库更多 Skills
write-ublock-origin-filters
Complete uBlock Origin (uBO) static filter reference. Use this skill when writing or debugging uBO custom filters or filter lists for ad blocking, privacy or content filtering, or when migrating filters from AdBlock Plus/AdGuard. Covers network patterns (||, *, ^, |) and options ($domain, $third-party, $important, $redirect, $removeparam, $csp, $replace, $header, $method, $badfilter, $all), content-type options ($script, $image, $stylesheet, $font, $media, $xhr, $popup, $document, $frame), cosmetic filters (##, CSS selectors, entity matching), procedural filters (:has, :has-text, :matches-css, :upward, :xpath, :matches-path, :watch-attr), action operators (:remove, :style, :remove-attr), HTML filters (##^), response-header filtering (##^responseheader), scriptlet injection (##+js()), and pre-parsing directives (!#include, !#if). Trigger whenever the user mentions uBO syntax, ad blocking rules, element hiding, procedural selectors, scriptlet injection, or a uBO-compatible filter list.
write-tampermonkey-scripts
引导 AI 代理规划、编写、调试、测试和维护 Tampermonkey 用户脚本。当用户请求用户脚本、浏览器页面自动化、DOM 增强、Tampermonkey 元数据、GM_* API、@match、@grant、@run-at、@connect、跨源请求、SPA 页面集成或脚本注入任务时使用此技能,即使用户没有明确提及 Tampermonkey。
write-tampermonkey-scripts
Guide an AI agent through planning, writing, debugging, testing, and maintaining Tampermonkey userscripts. Use this skill whenever a user asks for a userscript, browser-page automation, DOM enhancement, Tampermonkey metadata, GM_* API, @match, @grant, @run-at, @connect, cross-origin request, SPA page integration, or script injection task, even when Tampermonkey is not named explicitly.
write-adguard-filters
编写 AdGuard 自定义过滤规则时使用此技能。涵盖基本规则语法、所有修饰符($domain/$third-party/$important/$redirect/$replace/$removeparam/$cookie/$csp 等)、外观规则(元素隐藏/CSS/Extended CSS 选择器)、HTML 过滤、JavaScript/脚本片段规则、非基本规则修饰符、预处理器指令和调试技巧。当用户提及 AdGuard 过滤规则、广告拦截规则语法、过滤器列表编写、ABP 语法兼容、元素隐藏规则、Extended CSS 选择器(:has/:contains/:matches-css 等)时触发。即使用户只是在编写或调试任何类型的广告过滤规则,也应使用此技能。
write-adguard-filters
Complete AdGuard filtering rules syntax reference. Use this skill when writing AdGuard custom filters. Covers basic rule syntax, all modifiers ($domain/$third-party/$important/$redirect/$replace/$removeparam/$cookie/$csp etc.), cosmetic rules (element hiding/CSS/Extended CSS selectors), HTML filtering, JavaScript/scriptlet rules, non-basic rule modifiers, preprocessor directives, and debugging. Trigger when user mentions AdGuard filtering rules, ad blocking rule syntax, filter list authoring, ABP syntax compatibility, element hiding rules, Extended CSS selectors (:has/:contains/:matches-css etc.). Use this skill even when the user is just writing or debugging any type of ad filtering rules.
write-adblock-plus-filters
编写、调试和解释 Adblock Plus (ABP) 过滤规则语法。当用户需要创建 ABP 过滤规则、了解过滤规则语法、构建过滤规则列表、调试规则为何不生效、在不同过滤规则类型之间转换,或学习 ABP 特有功能(如扩展 CSS 选择器、代码片段过滤器、站点密钥等)时使用此技能。当用户提到广告拦截规则、元素隐藏、过滤规则选项、EasyList 格式或任何 ABP 过滤规则相关问题时也应触发,即使他们没有明确说'Adblock Plus'。