Name: ad-block
Owner: Brave Software
Description: Ad block engine used in the Brave browser for ABP filter syntax based lists like EasyList.
Created: 2015-10-13 23:12:15.0
Updated: 2018-05-24 15:26:23.0
Pushed: 2018-05-24 15:26:21.0
Homepage: https://www.brave.com
Size: 2439
Language: C
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Native node module, and C++ library for Adblock Plus filter parsing for lists like EasyList.
It uses a bloom filter and Rabin-Karp algorithm to be super fast.
install --save ad-block
t {AdBlockClient, FilterOptions} = require('ad-block')
t client = new AdBlockClient()
nt.parse('/public/ad/*$domain=slashdot.org')
nt.parse('/public/ad3/*$script')
b1 = client.matches('http://www.brianbondy.com/public/ad/some-ad', FilterOptions.script, 'slashdot.org')
b2 = client.matches('http://www.brianbondy.com/public/ad/some-ad', FilterOptions.script, 'digg.com')
ole.log('public/ad/* should match b1. Actual: ', b1)
ole.log('public/ad/* should not match b2. Actual: ', b2)
lude "ad_block_client.h"
lude <algorithm>
lude <iostream>
lude <fstream>
lude <sstream>
lude <iostream>
lude <string>
g namespace std;
ng getFileContents(const char *filename)
stream in(filename, ios::in);
(in) {
ostringstream contents;
contents << in.rdbuf();
in.close();
return(contents.str());
row(errno);
writeFile(const char *filename, const char *buffer, int length)
stream outFile(filename, ios::out | ios::binary);
(outFile) {
outFile.write(buffer, length);
outFile.close();
return;
row(errno);
main(int argc, char**argv) {
d::string &&easyListTxt = getFileContents("./test/data/easylist.txt");
nst char *urlsToCheck[] = {
// ||pagead2.googlesyndication.com^$~object-subrequest
"http://pagead2.googlesyndication.com/pagead/show_ads.js",
// Should be blocked by: ||googlesyndication.com/safeframe/$third-party
"http://tpc.googlesyndication.com/safeframe/1-0-2/html/container.html",
// Should be blocked by: ||googletagservices.com/tag/js/gpt_$third-party
"http://www.googletagservices.com/tag/js/gpt_mobile.js",
// Shouldn't be blocked
"http://www.brianbondy.com"
This is the site who's URLs are being checked, not the domain of the URL being checked.
nst char *currentPageDomain = "slashdot.org";
Parse easylist
BlockClient client;
ient.parse(easyListTxt.c_str());
Do the checks
d::for_each(urlsToCheck, urlsToCheck + sizeof(urlsToCheck) / sizeof(urlsToCheck[0]), [&client, currentPageDomain](std::string const &urlToCheck) {
if (client.matches(urlToCheck.c_str(), FONoFilterOption, currentPageDomain)) {
cout << urlToCheck << ": You should block this URL!" << endl;
} else {
cout << urlToCheck << ": You should NOT block this URL!" << endl;
}
;
t size;
This buffer is allocate on the heap, you must call delete[] when you're done using it.
ar *buffer = client.serialize(size);
iteFile("./ABPFilterParserData.dat", buffer, size);
BlockClient client2;
Deserialize uses the buffer directly for subsequent matches, do not free until all matches are done.
ient2.deserialize(buffer);
Prints the same as client.matches would
d::for_each(urlsToCheck, urlsToCheck + sizeof(urlsToCheck) / sizeof(urlsToCheck[0]), [&client2, currentPageDomain](std::string const &urlToCheck) {
if (client2.matches(urlToCheck.c_str(), FONoFilterOption, currentPageDomain)) {
cout << urlToCheck << ": You should block this URL!" << endl;
} else {
cout << urlToCheck << ": You should NOT block this URL!" << endl;
}
;
lete[] buffer;
turn 0;
node scripts/check.js --host www.cnet.com --location https://s0.2mdn.net/instream/html5/ima3.js
node scripts/check.js --host www.cnet.com --location "https://slashdot.org?t=1&ad_box_=2" --discover
node scripts/check.js --uuid 03F91310-9244-40FA-BCF6-DA31B832F34D --host slashdot.org --location https://s.yimg.jp/images/ds/ult/toppage/rapidjp-1.0.0.js
node scripts/check.js --dat ./out/SafeBrowsingData.dat --host excellentmovies.net --location https://excellentmovies.net
node scripts/check.js --host www.cnet.com --list ./test/data/sitelist.txt
node scripts/check.js --host www.cnet.com --list ./test/data/sitelist.txt --discover
Clone the git repository from GitHub:
git clone --recursive https://github.com/brave/ad-block
Open the working directory:
cd ad-block
Install the Node (v5+) dependencies:
npm install
sample
test
clean