Remove AdBlock Tags

Discussion in 'Programming' started by ToddMicheau, Jun 6, 2008.

  1. #1
    Just finished coding this and figured I would share-
    It's a simple javascript function that removes the tags placed on the page by FireFox's addon called Adblock.
    This is handy in cases where the tags are making your page look ugly (my case), or you just don't want users to easily block your ad's. (Though users can of course just right click on the image and block it that way, but blocking flash without the little tags being there is a more difficult.)

    This script works at removing the tags from both Adblock and Adblock Plus.

    
    /*
    Original Code - Todd Micheau
    ----------------
    http://bubblecoder.com/
    */
    function removeAdblock(){
    	var userAgent=navigator.userAgent;
    	if(userAgent.search(/Firefox/i) != -1){
    		var linkTitle = "";
    		var x=document.getElementsByTagName("a");
    		for(var i = 0; i < x.length; i++){
    			for( var j = 0; j < x[i].attributes.length; j++ ){
    				if( x[i].attributes[j].nodeName.toLowerCase() == 'title' ){
    					linkTitle = x[i].attributes[j].nodeValue;
    					if(linkTitle.search(/Adblock/i) != -1){
    						x[i].attributes[3].nodeValue = "";
    					}
    				}
    			}
    		}
    	}
    }
    
    window.onload = function () {
    	setTimeout("removeAdblock()",1250);
    }
    
    Code (markup):
    I'm sure the code isn't as optimized as it can be, so feel free to make changes- let me know if you come up with a better way =]
     
    ToddMicheau, Jun 6, 2008 IP