Parse ABP Cosmetic rules to CSS and apply it.
将 ABP 中的元素隐藏规则转换为 CSS 使用,
配合 AdGuard 的解析库,
用于增强 Android 系统上套壳 (WebView) 浏览器的广告拦截能力 。
这个脚本用 TypeScript 编写,源代码见 Gitee Bitbucket 。
用户反馈称:脚本使用 CPU 超 90%,对此我测试了下,
酷睿 i5-7400 在转换规则时,使用率最高 76% 。
配置更低的设备确实可能有更高的消耗 。
但我水平有限,没有好的办法优化 :( 。
我要强调一下,这个脚本就是为了 装不了插件,自身支持不足 的
套壳浏览器 支持 AdGuard 规则用的 。
如果你的浏览器能用 AdGuard / uBO 插件,那就请不要使用这个脚本!
替代的,用插件订阅 @大萌主 的两套规则:
https://slink.ltd/https://raw.githubusercontent.com/damengzhu/banad/main/jiekouAD.txt
https://slink.ltd/https://raw.githubusercontent.com/damengzhu/abpmerge/main/CSSRule.txt
官方插件在各个方面一定比这个脚本强得多!
2.8.0 添加了自动清理功能,默认关闭,你可以修改脚本开头的 autoCleanSize: 0,
开启,如果是电脑浏览器,建议 50000000,某些套壳浏览器可能要修改为 1200000 才可防止出现 无法存储 的问题
2.5.0 版本改动幅度过大,如果没有任何作用,请重新安装脚本
如果你使用插件,清空脚本存储(全选,删除,填 {},保存),然后试试
从 2.4.0 开始,Chrome 87 及以下内核可能会出现拦截能力变弱的情况,强烈建议升级浏览器 / WebView 内核
从 2.4.0 开始,新版 ExtendedCss 不再支持:if()
和 :if-not()
这个脚本的用户面非常窄 ... 因为:
如果你非常幸运,不属于上面所有情况,可以试试它 :)
目前内置由 @大萌主 提供的两套规则,十分感谢 :)
此脚本引用了 AdGuard 的解析库 ExtendedCss,
附 ExtendedCss 许可声明:
(文件注释)
/**
* @adguard/extended-css - v2.0.56 - Tue Nov 28 2023
* https://github.com/AdguardTeam/ExtendedCss#homepage
* Copyright (c) 2023 AdGuard. Licensed GPL-3.0
*/
(标准声明填充)
ExtendedCss
Copyright (C) 2023 AdGuard
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
从 2.1.2 开始,此脚本不再直接引用 bext-lib ,
而是抽取了其中的两个函数,并做了修改。
从 2.3.0 开始,不再使用 runNeed,只使用 runOnce。
附 bext-lib 许可声明 :
MIT License
Copyright (c) 2022 ikkz
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
对于 Tampermonkey 篡改猴:
对于 脚本猫:
通用:可以在脚本 52 行那里添加规则,保存以后在任意页面刷新即可生效。
请务必确认添加的规则在下面 "支持的语法" 中。
给它取个英文单词的名字,然后需要修改三个地方 :
脚本头 资源 加一行
// @resource 名字 规则地址
脚本头 跨域白名单 加一行
// @connect 规则地址的域名
OnlineRules 里面加个对象
{
标识: "名字",
地址: "规则地址",
在线更新: !!1, // 1 开启 0 关闭
筛选后存储: !!1,
},
注意,只有最后一个对象末尾可以不加逗号 添加以后需要清空 Values 并且刷新才能生效
! 一般的元素规则
###id
example.com###id
! 多域名
example.com,example.org###id
! 排除子域名
example.com,~www.example.com###id
! TLD 通配
example.*###id
! 域名修饰符 $domain
[$domain=example.com]###id
隐藏 | 放行 | 内容 | ExtendedCss |
---|---|---|---|
## | #@# | 标准 CSS 选择器 | 否 |
#?# | #@?# | 扩充的 CSS 选择器 | 是 |
#$# | #@$# | 标准 CSS 规则 | 否 |
#$?# | #@$?# | 扩充的 CSS 规则 | 是 |
只支持单独的 $domain 当前不打算支持 $path
[$domain=example.com]###id
! 在匹配地址 禁用 通用隐藏规则
@@||example.com$generichide
@@||example.com$ghide
! 在匹配地址 禁用 特定隐藏规则
@@||example.com$specifichide
@@||example.com$shide
! 在匹配地址 禁用 所有隐藏规则
@@||example.com$elemhide
@@||example.com$ehide
! 支持以下写法
@@$generichide,domain=example.com
! 支持禁用规则,添加以下规则后
@@||example.com$ghide,badfilter
! 以下规则无效
@@||example.com$ghide
通用隐藏规则 : 没有限制特定域名应用的规则
特定隐藏规则 : 限制特定域名应用的规则
! 通用规则
###ok
! 只有排除域名也是通用规则
~ok.com###ok
! 特定规则
ok.com###ok
ok.com,~www.ok.com###ok
[$path="/index"]###id