Bookmarklet to enable debug on a webpage

Often when working on a webpage in either PHP or Javascript I'll want to enable some form of debug mode. Usually this involves adding (or removing) debug=1 to the end of the URL. I created a simple bookmarklet to automate this process. I call it debugify. Drag the link to your quick launch bar to add it to your browser.

Here is the raw code which I then run through Bookmarklet Crunchinator

var url = location.href;
var new_url = '';
var match = url.match(/debug=(\d)/);
var url_char = '?';

if (url.match(/\?/)) {
	url_char = '&';
}

var current_debug = 0;
if (match) {
	current_debug = match[1];
	var new_debug = 1;

	if (current_debug > 0) {
		new_debug = 0;
	}

	new_url = url.replace(/debug=(\d)/, 'debug=' + new_debug);
} else if (url.match(/#/)) {
	new_url = url.replace(/#/, url_char + 'debug=1#');
} else {
	new_url = url + url_char + 'debug=1';
}

location.href = new_url;


Note: Replies will be formatted with PHP Markdown Extra syntax.

Name: Email (Not Required):
 
Logged IP: 54.166.111.111
To prevent spam please submit by clicking the kitten: