Skip to content

Instantly share code, notes, and snippets.

@RonnyO
Created June 12, 2012 13:29
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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
// 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