Abp2dnr
Script to produce chrome.declarativeNetRequest rules from an Adblock Plus filter list. Based upon abp2blocklist.
Install / Use
/learn @kzar/Abp2dnrREADME
abp2dnr
This is a script to convert Adblock Plus filter lists to chrome.declarativeNetRequest rulesets as far as is possible.
See also Chromium's built-in filter list converter.
Requirements
Before you begin, make sure to install Node.js version 16 or higher.
Then the required packages can be installed via Git and npm:
npm install
The declarativeNetRequest rulesets generated by this script require Chrome >= 101 to function correctly. (See this announcement for context.)
Usage
Command line interface
Create a declarativeNetRequest ruleset output.json from an Adblock Plus
filter list input.txt:
node abp2dnr.js < input.txt > output.json
JavaScript API
Behind that, there's a JavaScript API which the command line interface uses. It works something like this:
const {convertFilter, compressRules} = require("./lib/abp2dnr");
let rules = []
// Convert the filters to declarativeNetRequest rules.
for (let filter of filters)
rules.push(await convertFilter(filter));
// Optionally combine rules where possible.
rules = compressRules(rules)
// Assign the rules an ID (must not be before compressRules()).
let id = 1;
for (let rule of rules)
rule.id = id++;
It's important to note that convertFilter expects a Filter Object and not
a string containing the filter's text. To parse filter text you'll need to
do something like this first:
const {Filter} = require("adblockpluscore/lib/filterClasses");
Filter.fromText(Filter.normalize(filterText));
Tests
Unit tests live in the tests/ directory. You can run them by typing this command:
npm test
Linting
You can lint the code by typing this command:
npm run lint
Related Skills
node-connect
349.9kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
109.8kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
349.9kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
349.9kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
