Differences

This shows you the differences between two versions of the page.

adblock.js [2010/07/28 18:50] (current)
jake created
Line 1: Line 1:
 +====adblock.js====
 +adblocker that uses beforeload to keep images/scripts/etc from even being retrieved.
 +matches any given attribute with a regex and blocks the matches.
 +while it will keep the ad/flash from loading, it might leave a square so you might still want to use [[adblock]] or a custom css to get rid of it.
 +
 +==script==
 +<code javascript>
 +var blocklist = new Array();
 +blocklist["IMG"] = [["src", /.*doubleclick.net.*/],
 +                    ["src", /.*last.fm\/adserver.*/]];
 +
 +blocklist["SCRIPT"] = [["src", /.*doubleclick.net.*/]];
 +
 +blocklist["IFRAME"] = [["name", /.*google_ads.*/],
 +                       ["id", /.*ad-google.*/]];
 +
 +
 +
 +
 +function adblock(event)
 +{
 +    var tag = event.target.tagName;
 +    for(var i = 0; i < blocklist[tag].length; i++) {
 +        if (event.target.getAttribute(blocklist[tag][i][0]).match(blocklist[tag][i][1])) {
 +            event.preventDefault();
 +        }
 +    }    
 +};
 +
 +document.addEventListener("beforeload", adblock, true);
 +
 +</code>
 +
 +==config==
 +<code>
 +@on_event   LOAD_COMMIT    script @sdir/adblock.js
 +</code>
 
adblock.js.txt · Last modified: 2010/07/28 18:50 by jake
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki