Created
August 28, 2019 02:25
-
-
Save trungx/2057cb86446791eea48771e364d87285 to your computer and use it in GitHub Desktop.
adblock_prevent.js
This file contains hidden or 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
| 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