Code Monkey home page Code Monkey logo

ab2cb's Introduction

ab2cb: convert AdBlock Plus content filters to Safari Content Blockers

This is a work in progress! It is not perfect.

The ab2cb script reads filter lists as used by AdBlock Plus and produces a JSON Content Blocker file.

Documentation on Content Blockers is a bit sparse. The best source seems to be reading the Safari test source code.

Examples

Convert A File

$ ab2cb -o blockList.json easylist.txt

Read From stdin and Write To stdout

$ curl -s https://easylist-downloads.adblockplus.org/easylist.txt | ab2cb > blockList.json

Usage

$ ab2cb -h
usage: ab2cb [options] [File ...]

ab2cb: convert AdBlock content filters to Safari Content Blockers

positional arguments:
  File                  Files to extract from. If not given read from stdin.

optional arguments:
  -h, --help            show this help message and exit
  --version             show program's version number and exit
  --debug               Turn on debug logging.
  --debug-log FILE      Save debug logging to FILE.
  -o FILE, --output FILE
                        Save converted text to FILE. If not given, output to
                        stdout.
  --no-white            Do not produce white list rules.

To Run Without Installing

  1. Clone this repo
  2. cd to the repo
  3. Activate with the command: . bin/activate.sh
  4. Make the dev environment with the command: make dev
  5. Run ab2cb -h

Testing

Assuming you have tox and pytest installed, just type tox in this directory.

Testing filters

Currently this is manual: you have to load the content blocker json into Safari, navigate to a test page and check the blocking using the web inspector. I'm working on automating this.

There is a small JavaScript file in the test directory called check.js that will load a json file and check the regex compiles.

References

Safari Extensibility: Content Blocking and Shared Links
WWDC 2015 Video
https://developer.apple.com/videos/wwdc/2015/?id=511

EasyList
https://easylist.adblockplus.org/en/

Writing Adblock Plus filters
https://adblockplus.org/en/filters

Introduction to WebKit Content Blockers Surfin' Safari Blog
https://www.webkit.org/blog/3476/content-blockers-first-look/

AdBlock Plus
filterClasses.js
https://github.com/adblockplus/adblockplus/blob/master/lib/filterClasses.js

WebKit Tests
ContentExtensions.cpp
http://trac.webkit.org/browser/trunk/Tools/TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp

ab2cb's People

Contributors

bnomis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

ab2cb's Issues

covert result not work at demo app

hello,I use ad2cb covert AdBlock Plus easylist.txt to Safari Content Blocker JSON but result not work at my demo app , I found it exist many "\" in trigger content,like this:
{
"action": {
"type": "block"
},
"trigger": {
"url-filter": "^https?:.*\.com/java/shang1\.js"
}
},
should your adjust some covert rules? or how can I fix it?
thanks~

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.