README
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 10 or higher) and whatever node-gyp requires to compile RE2 on your system.
Then the required packages can be installed via Git and npm:
git submodule update --init
npm install
Usage
Command line interface
Create a chrome.declarativeNetRequest
rule list output.json
from the
Adblock Plus filter list input.txt
:
node abp2dnr.js < input.txt > output.json
API
Behind that, there's an API which the command line interface uses. It works something like this:
const {convertFilter} = require("./lib/abp2dnr");
let nextId = 1;
let rules = [];
for (let filter in filters)
{
for (let rule of await convertFilter(filter))
{
rule.id = nextId++;
rules.push(rule);
}
}
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