Giter Site home page Giter Site logo

abp2dnr's Introduction

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.