Warning, /plasma/aura-browser/app/third-party/ad-block/README.md is written in an unsupported language. File is not indexed.

0001 Deprecated and no longer maintained, use https://github.com/brave/adblock-rust instead!
0002 
0003 [![Build Status](https://travis-ci.org/brave/ad-block.svg?branch=master)](https://travis-ci.org/brave/ad-block)
0004 
0005 # Brave Ad Block
0006 
0007 Native node module, and C++ library for Adblock Plus filter parsing for lists like EasyList.
0008 
0009 It uses a bloom filter and Rabin-Karp algorithm to be super fast.
0010 
0011 ## Compatibility
0012 
0013 This project supports almost all of the
0014 [EasyList](https://adblockplus.org/filters) rule formats.  It also supports
0015 some rule formats specific to other projects, like [uBlock](https://github.com/gorhill/uBlock/)
0016 and [AdGuard](https://adguard.com/en/welcome.html). For more details on
0017 what rule formats are supported, please see 
0018  [compatibility wiki page](https://github.com/brave/ad-block/wiki/Filter-List-Format-Compatibility).
0019 
0020 ## To include brave/ad-block in your project:
0021 
0022 ```
0023 npm install --save ad-block
0024 ```
0025 
0026 ## JS Sample
0027 
0028 ```javascript
0029 
0030 const { AdBlockClient, FilterOptions } = require('ad-block')
0031 const client = new AdBlockClient()
0032 client.parse('/public/ad/*$domain=slashdot.org')
0033 client.parse('/public/ad3/*$script')
0034 var b1 = client.matches('http://www.brianbondy.com/public/ad/some-ad', FilterOptions.script, 'slashdot.org')
0035 var b2 = client.matches('http://www.brianbondy.com/public/ad/some-ad', FilterOptions.script, 'digg.com')
0036 console.log('public/ad/* should match b1.  Actual: ', b1)
0037 console.log('public/ad/* should not match b2.  Actual: ', b2)
0038 ```
0039 
0040 ## C++ Sample
0041 
0042 ```c++
0043 #include "ad_block_client.h"
0044 #include <algorithm>
0045 #include <iostream>
0046 #include <fstream>
0047 #include <sstream>
0048 #include <string>
0049 
0050 using namespace std;
0051 
0052 string getFileContents(const char *filename)
0053 {
0054   ifstream in(filename, ios::in);
0055   if (in) {
0056     ostringstream contents;
0057     contents << in.rdbuf();
0058     in.close();
0059     return(contents.str());
0060   }
0061   throw(errno);
0062 }
0063 
0064 void writeFile(const char *filename, const char *buffer, int length)
0065 {
0066   ofstream outFile(filename, ios::out | ios::binary);
0067   if (outFile) {
0068     outFile.write(buffer, length);
0069     outFile.close();
0070     return;
0071   }
0072   throw(errno);
0073 }
0074 
0075 
0076 int main(int argc, char**argv) {
0077   std::string &&easyListTxt = getFileContents("./test/data/easylist.txt");
0078   const char *urlsToCheck[] = {
0079     // ||pagead2.googlesyndication.com^$~object-subrequest
0080     "http://pagead2.googlesyndication.com/pagead/show_ads.js",
0081     // Should be blocked by: ||googlesyndication.com/safeframe/$third-party
0082     "http://tpc.googlesyndication.com/safeframe/1-0-2/html/container.html",
0083     // Should be blocked by: ||googletagservices.com/tag/js/gpt_$third-party
0084     "http://www.googletagservices.com/tag/js/gpt_mobile.js",
0085     // Shouldn't be blocked
0086     "http://www.brianbondy.com"
0087   };
0088 
0089   // This is the site who's URLs are being checked, not the domain of the URL being checked.
0090   const char *currentPageDomain = "slashdot.org";
0091 
0092   // Parse easylist
0093   AdBlockClient client;
0094   client.parse(easyListTxt.c_str());
0095 
0096   // Do the checks
0097   std::for_each(urlsToCheck, urlsToCheck + sizeof(urlsToCheck) / sizeof(urlsToCheck[0]), [&client, currentPageDomain](std::string const &urlToCheck) {
0098     if (client.matches(urlToCheck.c_str(), FONoFilterOption, currentPageDomain)) {
0099       cout << urlToCheck << ": You should block this URL!" << endl;
0100     } else {
0101       cout << urlToCheck << ": You should NOT block this URL!" << endl;
0102     }
0103   });
0104 
0105   int size;
0106   // This buffer is allocate on the heap, you must call delete[] when you're done using it.
0107   char *buffer = client.serialize(&size);
0108   writeFile("./ABPFilterParserData.dat", buffer, size);
0109 
0110   AdBlockClient client2;
0111   // Deserialize uses the buffer directly for subsequent matches, do not free until all matches are done.
0112   client2.deserialize(buffer);
0113   // Prints the same as client.matches would
0114   std::for_each(urlsToCheck, urlsToCheck + sizeof(urlsToCheck) / sizeof(urlsToCheck[0]), [&client2, currentPageDomain](std::string const &urlToCheck) {
0115     if (client2.matches(urlToCheck.c_str(), FONoFilterOption, currentPageDomain)) {
0116       cout << urlToCheck << ": You should block this URL!" << endl;
0117     } else {
0118       cout << urlToCheck << ": You should NOT block this URL!" << endl;
0119     }
0120   });
0121   delete[] buffer;
0122   return 0;
0123 }
0124 ```
0125 
0126 
0127 ## Util for checking URLs
0128 
0129 - Basic checking a URL:
0130   `node scripts/check.js  --host www.cnet.com --location https://s0.2mdn.net/instream/html5/ima3.js`
0131 - Checking a URL with discovery:
0132   `node scripts/check.js  --host www.cnet.com --location "https://slashdot.org?t=1&ad_box_=2" --discover`
0133 - Checking a URL against a particular adblock list:
0134   `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`
0135 - Checking a URL from a loaded DAT file:
0136   `node scripts/check.js --dat ./out/SafeBrowsingData.dat --host excellentmovies.net --location https://excellentmovies.net`
0137 - Checking a list of URLs:
0138   `node scripts/check.js  --host www.cnet.com --list ./test/data/sitelist.txt`
0139 - Checking a list of URLS with discovery:
0140   `node scripts/check.js  --host www.cnet.com --list ./test/data/sitelist.txt --discover`
0141 
0142 
0143 ## Developing brave/ad-block
0144 
0145 1. Clone the git repository from GitHub:
0146 
0147     `git clone --recursive https://github.com/brave/ad-block`
0148 
0149 2. Open the working directory:
0150 
0151     `cd ad-block`
0152 
0153 3. Install the Node (v5+) dependencies:
0154 
0155     `npm install`
0156 
0157 4. Install ninja:
0158         ##### MAC
0159              brew install ninja
0160 
0161         ##### WINDOWS
0162 
0163         Go to the releases page of the Ninja build tool, and download a suitable binary for Windows. Place ninja.exe in a suitable spot. For example, C:\Ninja. Now make sure that CMake can find ninja.exe by adding C:\Ninja to your %PATH%.
0164 
0165 ## Make the node module
0166 
0167 ```
0168 make
0169 ```
0170 
0171 ## Running sample (which also generates a .dat file for deserializing)
0172 
0173 ```
0174 make sample
0175 ```
0176 
0177 ## Running tests
0178 
0179 ```
0180 make test
0181 ```
0182 
0183 ## Clearing build files
0184 ```
0185 make clean
0186 ```