Skip to content

Instantly share code, notes, and snippets.

@trungx
Created August 28, 2019 02:25
Show Gist options
  • Save trungx/2057cb86446791eea48771e364d87285 to your computer and use it in GitHub Desktop.
Save trungx/2057cb86446791eea48771e364d87285 to your computer and use it in GitHub Desktop.
adblock_prevent.js
document.addEventListener('DOMContentLoaded', init, false);
function init(){
adsBlocked(function(blocked){
if(blocked){
document.getElementById('result').innerHTML = 'ads are blocked';
} else {
document.getElementById('result').innerHTML = 'ads are not blocked';
}
})
}
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)
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment