Created
January 14, 2019 19:03
-
-
Save xealgo/25fbd574e85d1a48a87ee712dd3f9376 to your computer and use it in GitHub Desktop.
Simple adblock detection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Ad Block Test</title> | |
<style> | |
.ad { | |
color: #333; | |
background: #fff; | |
width: 790px; | |
height: 130px; | |
text-align: center; | |
border: 1px solid #333; | |
margin-bottom: 10px; | |
} | |
.blocked { | |
color: red; | |
} | |
</style> | |
</head> | |
<body> | |
<h1>Ad Block Detection Tester</h1> | |
<div> | |
<div class="ad ad1"><h1>Amazing Ad 1</h1></div> | |
<h1 id="ad1blocked" class="blocked" style="display: none;">Ad 1 (.ad) blocked</h1> | |
<div class="ad ad-text"><h1>Amazing Ad 2</h1></div> | |
<h1 id="ad2blocked" class="blocked" style="display: none;">Ad 2 (.ad, .ad-text) blocked</h1> | |
<div class="ad text-ad"><h1>Amazing Ad 3</h1></div> | |
<h1 id="ad3blocked" class="blocked" style="display: none;">Ad 3 (.ad, .text-ad) blocked</h1> | |
</div> | |
<script> | |
setTimeout(function() { | |
var ad = document.getElementsByClassName("ad1"); | |
var adtext = document.getElementsByClassName("ad-text"); | |
var textad = document.getElementsByClassName("text-ad"); | |
if (ad.length >= 1) { | |
if (ad[0].clientWidth === 0 || ad[0].offsetParent === null) { | |
document.getElementById("ad1blocked").style.display = "block"; | |
} | |
} | |
if (adtext.length >= 1) { | |
if (adtext[0].clientWidth === 0 || adtext[0].offsetParent === null) { | |
document.getElementById("ad2blocked").style.display = "block"; | |
} | |
} | |
if (textad.length >= 1) { | |
if (textad[0].clientWidth === 0 || textad[0].offsetParent === null) { | |
document.getElementById("ad3blocked").style.display = "block"; | |
} | |
} | |
}, 500); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment