Created
June 12, 2012 13:29
-
-
Save RonnyO/2917512 to your computer and use it in GitHub Desktop.
Mute alert() calls when not in debug mode; Enter & exit debug mode via url/cookie; Throttles alerts when active
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
// warning - This gist is probably be 'too clever', and has two side effects which you might not want: | |
// - It doesn't queue alerts but silents them, so you may miss some calls | |
// - You might forget about it or another developer won't know about it, and won't have a clue why alert() calls don't work | |
(function(){ | |
window.debugMode = false; | |
if(/startdebug/.test(location.href)) document.cookie = 'debug=true'; | |
if(/stopdebug/.test(location.href)) document.cookie = 'debug=false'; | |
if(document.cookie.indexOf('debug=true') > -1) debugMode = true; | |
var _alert = alert; | |
var lastExec = +new Date(); | |
window.alert = function(msg){ | |
if(debugMode) { | |
var now = +new Date(); | |
if(now - lastExec > 2000) { | |
_alert.call(window, msg); | |
lastExec = now; | |
} | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment