Simple Ad-Blocker Detection Script (Only For Adsense)

Hello everyone, this is my first contribution towards Flarum. Hope it works fine 🙂

How to install the anti-ad-blocker?

Just add the below script in Administration > Appearance > Custom Header

<script>
function isSiteOnline(o,e){var t=setTimeout((function(){e(!1)}),5e3),n=document.createElement("img");n.onload=function(){clearTimeout(t),e(!0)},n.onerror=function(){clearTimeout(t),e(!1)},n.src=o+"/favicon.ico"}function check(){isSiteOnline("https://doubleclick.net",(function(o){0==o&&(console.error("Ad-Blocker Detected"),document.getElementById("app").innerHTML='<br><br><div class="info"> We have noticed that you have enabled Ad-Blocker. Please support this forum for free just by disabling your Ad-Blocker!</div><div class="buttons"> <div class="button button-primary" onClick="window.location.reload();">Ok I Disabled It</div></div><style>@import url("https://fonts.googleapis.com/css2?family=Source+Sans+Pro:wght@400;700&display=swap");body{align-items: center; background-color: #eef0f6; display: flex; font-family: "Source Sans Pro", sans-serif; justify-content: center; height: 100vh;}.info{color: #64686b;}.buttons{display: flex; margin-top: 15px; width: 100%;}.button{align-items: center; background: #edf1f7; border-radius: 10px; cursor: pointer; display: flex; height: 50px; justify-content: center; margin: 0 5px 28px 20px; width: 100%;}.button:last-child{margin: 0 20px 20px 5px;}.button-primary{background-color: #0060f6; color: #fff;}</style>')}))}check();
</script>

How it works?

Well, it's simple. On page load, the javascript code will check for if https://pagead2.googlesyndication.com/ is reachable or not. If reachable, then it will not do anything. If not, it will delete all content of <div id="app"></div> and show warning of ad-blocker.

Demonstration Video

Hope it helps 😊

    Your script is working and I couldn’t open your website on my iPhone with AdGuard running (of course without creating a custom rule to remove the script that you have introduced).

    So, I disabled AdGuard and I can now open it:

    However since it’s Safari on iOS (my iPhone) the browser itself blocks trackers and I have this reported by the browser:

    It’s the same on my Mac. Basically Google tracking is still disabled. I guess you're OK with that since ads will be visible, only the tracking is disabled which means the users won't see personalized/targeted ads and so it's still less likely that they click on ads.

    • mys replied to this.
    • mys likes this.

      One more Ad blocker script -

      <style>
              #adblockbyspider {
                  backdrop-filter: blur(5px);
                  background: rgba(0, 0, 0, 0.25);
                  padding: 20px 19px;
                  border: 1px solid #ebeced;
                  border-radius: 10px;
                  color: #ebeced;
                  overflow: hidden;
                  position: fixed;
                  margin: auto;
                  left: 10;
                  right: 10;
                  top: 0;
                  width: 100%;
                  height: 100%;
                  overflow: auto;
                  z-index: 999999
              }
      
              #adblockbyspider .inner {
                  background: #f5f2f2;
                  color: #000;
                  box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
                  text-align: center;
                  width: 600px;
                  padding: 40px;
                  margin: 80px auto
              }
      
              #adblockbyspider button {
                  padding: 10px 20px;
                  border: 0;
                  background: #e9e9e9;
                  margin: 20px;
                  box-shadow: 0 5px 10px rgba(0, 0, 0, 0.3);
                  cursor: pointer;
                  transition: all .2s
              }
      
              #adblockbyspider button.active {
                  background: #fff
              }
      
              #adblockbyspider .tutorial {
                  background: #fff;
                  text-align: left;
                  color: #000;
                  padding: 20px;
                  height: 250px;
                  overflow: auto;
                  line-height: 30px
              }
      
              #adblockbyspider .tutorial div {
                  display: none
              }
      
              #adblockbyspider .tutorial div.active {
                  display: block
              }
      
              #adblockbyspider ol {
                  margin-left: 20px
              }
      
              @media(max-width:680px) {
                  #adblockbyspider .inner {
                      width: calc(100% - 80px);
                      margin: auto
                  }
              }
          </style>
          <script src='https://raw.githack.com/Ashwathnrayana/SpiderBlogging/main/antiadblock/2.0/code.min.js' />
          </script>
      4 days later

      CyberGene Yes ads will show but will receive less interstitial ads and hence less CPC 🙁

      4 months later

      mys It works perfectly.
      Could you write/modify this script to work on any page, like a wordpress site or any other html page