1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. This forum is for release discussion only. Discussions that do not relate specifically to the resource release should be discussed in another, more appropriate forum.
    Dismiss Notice
  3. This forum has been archived. New threads and replies may not be made. All add-ons/resources that are active should be migrated to the Resource Manager. See this thread for more information.

Adblock replacement Script

Discussion in 'Template Modifications [Archive]' started by bogus, May 26, 2011.

  1. bogus

    bogus Guest

    This is a very small modification Script, originaly not by me, but because the Howto is written in german i would like to share it.
    This script replaces the blocked adsense code in different ways. In the following example i am using a picture.

    We are using it because we are paying our servers with the income from Adsense. It´s not that much but at least we can half the costs with it.
    Adblockers may help to get rid off annoying Adverts but these so annoying ads helps surviving some ppl ;)

    Please remember that i am no coder also not a native English. If you know how to optimize the Code or know a better way or find some spelling error just let me know or post it here;)

    Well... Start with uploading the adframe.js (rename the adframe.js.txt to adframe.js) to the folder you want.

    Open your ACP and head to your Template Section
    Appearance -> Styles -> Your Style ->Templates (left side in ACP menu)
    • Click to "Create new Template"
    • under "Template Name: Must be unique" just enter what you want and what makes it easier for you to identify. In this example we call it adblock_replacement
    • into the empty, bigger, Field copy the following Code
    Code:
    <script type="text/javascript">
    <!--
        var adblock = true;
    //-->
    </script>
    <script type="text/javascript" src="path.to.the/adframe.js"></script>
    <script type="text/javascript">
    <!--
        if(adblock) {
          var allElements = document.getElementsByTagName('div');
          for (var i = 0; i < allElements.length; i++) {
                if (allElements[i].className == 'a') {
                    allElements[i].innerHTML = '<img src="path.to.your.image/image.jpg" width="700px" height="110px "border="0">';
                }
            }
        }
    //-->
    </script>
    
    width, height and border can be deleted or replaced with what you want and/or need.
    Save and Exit

    For the Advert i am using the ad_above_top_breadcrumb Template

    Click to "Search Templates" in the ACP menu and search for ad_above_top_breadcrumb,
    open the Template and replace "all" with

    Code:
    <xen:hook name="ad_above_top_breadcrumb" />
    
    <div style="text-align: center;">
        <div class="a">
    YOUR ADSENSE CODE
            </div>
        <xen:include template="adblock_replacement" />
    </div>
    As written on top call the adblock_replacement to what you want.
    If you dont want the adsense to be centered, delete <div style="text-align: center;"> and the </div> after YOUR ADSENSE CODE
    Save and Exit

    Here are some more replacement options you can use.

    Paypal Button

    replace
    Code:
    allElements[i].innerHTML = '<img src="path.to.your.image/image.jpg" width="700px" height="110px "border="0">';
    with your Paypal generated Code
    Code:
    allElements[i].innerHTML = '<form action="https://www.paypal.com/your_generated_paypal_code</form><div style="font-size:x-small; font-family:Verdana; width:575px; padding:3px 10px 9px 0; text-align:justify;">This website is funded by advertising. If you like it, you can donate  once a small amount to secure the future of this page.</div>';
    
    Redirection

    replace
    Code:
    allElements[i].innerHTML = '<img src="path.to.your.image/image.jpg" width="700px" height="110px "border="0">';
    with
    Code:
    window.location.href = "blocker.html";
    Different replacements for each adsense

    If you are using the image replacement Code, delete
    Code:
          var allElements = document.getElementsByTagName('div');
    
          for (var i = 0; i < allElements.length; i++) {
    
                if (allElements[i].className == 'a') {
    
                    allElements[i].innerHTML = '<img src="path.to.your.image/image.jpg" width="700px" height="110px "border="0">';
    
                }
            }
      }
    and insert
    Code:
            document.getElementById("a1").innerHTML = 'Alternative code 1';
            document.getElementById("a2").innerHTML = 'Alternative code 2';
        }
    Important! To get this working you must replace <div class="a"> with <div class="a1"> or <div class="a2"> depending what ad_ Template you are using and what you want to replace. You can add as much classes as you want from a1 to ax where x is the number. a1 can also be a name but I will not go further to confuse anyone ;)

    For a live view click here. Just turn on/off your Adblocker
    Sure, you can block this too, but just let me tell you that i am connected to a stats side and since we are using this, more then 30% of Adblock Users turned it off. Better then nothing.
     

    Attached Files:

    Archet, AzzidReign, Feedback and 2 others like this.

Share This Page