Skip to content

Instantly share code, notes, and snippets.

@wichaksono
Created March 8, 2019 12:51
Show Gist options
  • Save wichaksono/ce7d020c11df12dcf876827e7aa7232e to your computer and use it in GitHub Desktop.
Save wichaksono/ce7d020c11df12dcf876827e7aa7232e to your computer and use it in GitHub Desktop.
<script>
document.addEventListener('DOMContentLoaded', init, false);
function init(){
adsBlocked(function(blocked){
if(blocked){
var adblocker = document.getElementById('adblocker-detected');
adblocker.classList.add('show');
}
})
}
function adsBlocked(callback){
var testURL = 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js'
var myInit = {
method: 'HEAD',
mode: 'no-cors'
};
var myRequest = new Request(testURL, myInit);
fetch(myRequest).then(function(response) {
return response;
}).then(function(response) {
//console.log(response);
callback(false)
}).catch(function(e){
//console.log(e)
callback(true)
});
}
</script>
<style>
#adblocker-detected {display:none;position: fixed;top: 0px;padding: 10px;background: #2196F3;right: 0;left: 0;text-align: center; color: #fff;font-size: 0.9rem;z-index:9999}
#adblocker-detected.show{display:block; line-height: 50px;}
</style>
<div id="adblocker-detected"><strong>Adblocker Detected : </strong>Dukung ONPHPID dengan menonaktifkan Adblock-mu (^_^) Terima Kasih.
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment