0

I'm trying to develop an add-on to block a list of urls (facebook, twitter, etc.) on a certain website (e.g. mydomain.com).

I'd also like to block ads... Do you know if it's possible to extend adblock plus?

Where should I start? I can't find much info on google.

Many thanks in advance,

Eamorr
  • 9,872
  • 34
  • 125
  • 209

1 Answers1

2

The usual approach would be to create an XPCOM component (note: the examples are outdated, you have to consider this as well) implementing nsIContentPolicy interface and register it in the content-policy category. The component's shouldLoad() method will be called for each load attempt - you can look at aContentLocation and aRequestOrigin parameters to decide whether you want to block the requests.

Same is possible with Adblock Plus filters of course, e.g. to block Facebook on mydomain.com you use this filter:

||facebook.com^$domain=mydomain.com

Adblock Plus allows other extensions to communicate with it. To add a bunch of filters your extension would do the following on startup:

var filters = [
                "||facebook.com^$domain=mydomain.com",
                "||twitter.com^$domain=mydomain.com"
              ];
AdblockPlus.updateExternalSubscription("FooExtension",
                                       "Filters from Foo Extension",
                                       filters);
Wladimir Palant
  • 56,865
  • 12
  • 98
  • 126
  • Really useful info. Many thanks. I'll give that a try. Currently, I'm just following https://developer.mozilla.org/en/XUL_School/Intercepting_Page_Loads#page-files – Eamorr Mar 02 '12 at 11:39
  • Do I have to do a `var AdblockPlus=require('AdblockPlus')`? – Eamorr Mar 02 '12 at 11:43
  • @Eamorr: No, the Adblock Plus documentation I linked to explains how you access the API. If you are using the Add-on SDK then you will also need [chrome authority](https://addons.mozilla.org/en-US/developers/docs/sdk/1.5/dev-guide/module-development/chrome.html). – Wladimir Palant Mar 02 '12 at 11:50
  • Really struggling with this here... I've figured out how to do a chrome authority import (`var {Cc, Ci,Cu,Cr,Cm} = require("chrome");`), but how to view the api and start blocking urls? – Eamorr Mar 02 '12 at 12:04
  • 1
    @Eamorr: `if ("@adblockplus.org/abp/public;1" in Cc) { var abpURL = Cc["@adblockplus.org/abp/public;1"].getService(Ci.nsIURI); AdblockPlus = Cu.import(abpURL.spec, null).AdblockPlus; }` – Wladimir Palant Mar 02 '12 at 12:07
  • Greetings, it's all working very nicely now. You've been such a great help! ONe more question - can I package AdBlockPlus inside my addon or does the user *have* to download both addons? – Eamorr Mar 02 '12 at 12:26
  • You've really been a great help today. It's quite hard to google this stuff cos keywords like "addon" and "Firefox" are dominated by non-codey sites. – Eamorr Mar 02 '12 at 14:43
  • Is there an example of the former approach, using nsiContentPolicy to access 'shouldLoad'? Would be a big help, as the ABP interface only provides a few functions, mostly dealing with subscriptions (https://adblockplus.org/en/IAdblockPlus). Thanks – rednoyz Feb 06 '14 at 07:10
  • @rednoyz: The question here was about extending Adblock Plus. On the topic on `nsIContentPolicy` see http://stackoverflow.com/a/10788836/785541. – Wladimir Palant Feb 06 '14 at 09:57
  • Thanks for the quick reply. I did see that post, and I am talking about AdBlock-Plus (ABP). What I'm attempting is to have my addon's version of shouldLoad() called instead of ABP's version. Then, depending on the arguments, I call the ABP version of shouldLoad() myself. But maybe I should post this as a separate question? – rednoyz Feb 07 '14 at 09:36
  • @rednoyz: Yes, you probably want to create a new question - and explain what you are trying to achieve and why (you seem to be heading in the wrong direction). – Wladimir Palant Feb 07 '14 at 11:21