
Each ad will be different, so we basically need a different case for each provider.
#Adblock ultimate add a blocked site code#
The element referred to in that code is the original ad - by inserting the new image directly before it, we ensure that it appears in the same place in the document as the original.įinally, if the response is JavaScript, we need to parse and evaluate that code. Img.setAttribute('src', 'data:image/gif base64,' + request.responseText) Į(img, element) If it’s image data we base64 encode it, so that on the client side we can use the data to create a new image with a data URI, which has no external resource and therefore doesn’t get blocked: If it’s HTML that would be because the original ad was an, so in that case we simply change the iframe’s SRC to point to the PHP script, and we’re done: Depending on what the ad code spits out, we might get JavaScript, HTML or image data in response. The PHP script decodes that URI and then grabs its contents using fopen() into a buffer (other approaches are possible, but this seemed like the most straightforward note that the PHP script itself is validated to prevent injection attacks, and disallow requests that don’t come from specified hosts). Request.open('GET', 'draino.php?encuri=uggc:///nqf/cebzb.wf', true) It doesn’t need to be fancy, so Rot13 encoding is quite sufficient, and we’ll end up making requests like this: We need to prevent our requests from being blocked, so to do that we encode the addresses so that the filters don’t pick them up. However it isn’t quite that straightforward, because even XHR requests are affected by Adblock. Now we have a list of addresses, we need to be able to request that data manually, which we can do by calling a PHP script via XMLHttpRequest - the server can request data from any domain and then pass it back up to the client. Each instance of a target element is tested against the filters to see if it might be blocked, and if so we remember its address.

The script defines a subset of URI filters (similar to Adblock itself, but limited to the ads we know we’re running), and a list of elements to check (scripts, images and iframes). Once we’ve established that Adblock is running we can begin to look for blockable content. Of course if the test image isn’t blocked, then the rest of the script won’t run, but given the obviousness of the target URI, it’s pretty likely that it will. (The empty source element is also undisplayed with a dynamically-generated user stylesheet, which can’t be overriden by any styling on the document, because user stylesheets always have precedence). Adblock hooks into Firefox’s content policy API, which controls allowable content at the level of HTTP requests, which means that blocked content is never even requested. One of the clever things about Adblock is the fact that it doesn’t actually remove things from the document at all - it never lets them get to the document in the first place. Here we’re assuming that Adblock’s filters will match a URI containing /ads, because if it does then we’ll never be able to load that image, and that’s how we know Adblock is running. Var self = this, tester = document.createElement('img') ĭocument.getElementsByTagName('body').item(0).appendChild(tester) There used to be a Firefox bug that exposed information about installed extensions, but that’s long since fixed. To begin with we need to establish that Adblock is actually running - we don’t want to run the script if it isn’t or we’ll end up duplicating all our ads.
#Adblock ultimate add a blocked site free#
But don’t make it superficially free and then try to make me feel guilty when it costs you something. The hypochrisy of that is pretty insulting, in my view - if your content is free, make it free if it’s not free then charge for it. In any case it isn’t really the ad-blocking that’s the issue, it’s business models that refuse to acknowledge human nature, and content providers who want to make money while pretending that’s not their motive. It’s all the same, and objecting to one is objecting to all of them (which is why the law would never be able to intervene - making the activity of ad-blocking illegal would make all user-modification illegal, including the use of assistive technologies, user CSS and user scripting, and other extensions). Any part of the web is customisable for you - you can make sites have a high-contrast color scheme because you need that to read, or you can filter out all images because you don’t have the bandwidth to load them, or you can selectively remove particular types of content because you simply don’t want to see it.

I know there are some who think that blocking ads is tantamount to theft, but I think their arguments are entirely specious. I’m no fan of ads myself, and I really don’t have an issue with people using ad-blocking software.
