- Edited
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