Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

On an active website I go to, there is this javascript code that is displayed on every page.

<script type="text/javascript">
(function(){var d=document;var i=d.getElementsByTagName('iframe');if(google_ad_client!=null||(window.getComputedStyle?d.defaultView.getComputedStyle(i[i.length-1],null).getPropertyValue('display'):i[i.length-1].currentStyle['display'])=='none'){

alert('Adblock detected, please consider disabling it')

}})()
</script>

Is there any way that I could get my adblock -- or any other type of plugin -- to disable that specific code without disabling all javascript?

share|improve this question
    
On a side note, I had disabled my adblock entirely. The script continues to display the alert. Maybe it's in the cause of my OS being a Linux Distribution.. –  D-Vee Oct 26 '13 at 13:58
    
Regardless of your comment, these links may be helpful: 1, 2. Basically, there is no easy way to disable an inline script (which is in the HTML), but you can block an external script. If the code you posted is an external script, it's a duplicate of this question: superuser.com/q/278590/138020 –  amiregelz Oct 26 '13 at 14:05
    
You may be able to override the alert using a userscript (depending on when each piece is loaded in the DOM). Something as simple as alert = function() {}; may work. –  nerdwaller Oct 26 '13 at 14:13
    
@nerdwaller Would it be possible to use something like Stylish to edit the HTML page so that the script does nothing? Secondly, how would I write that as a userscript? I have little to none experience with javascript, but I am able to read it. –  D-Vee Oct 26 '13 at 14:14
    
After a little more research, Userscripts are run after everything else, so that solution doesn't work. I'm not familiar with Stylish enough to give you anything good on that, sorry! –  nerdwaller Oct 26 '13 at 14:17
show 2 more comments

1 Answer

You can use the Greasemonkey add-on to rewrite the alert function:

// ==UserScript==
// @name        Catch JS Alert
// @namespace   http://igalvez.net
// @include     http://*
// @version     1
// @grant       none
// @run-at      document-start
// ==/UserScript==

window.alert = function(message) {
    if(message == 'Adblock detected, please consider disabling it') {
        console.log(message);
    } else {
        confirm(message);
    }
}

The way this works is as follows:

If the alert box's message matches "Adblock detected, please consider disabling it", then discard it to the JS console (it will not be displayed). Otherwise, display the alert box as a confirm box.

share|improve this answer
    
Why not just keep a reference to the original alert? –  minitech Oct 26 '13 at 17:33
1  
Interesting, did not know of the @run-at option. Great intel, +1. –  nerdwaller Oct 26 '13 at 17:52
    
Sorry, but that does not seem to work. o_O –  D-Vee Oct 26 '13 at 22:52
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.