Skip to content

Instantly share code, notes, and snippets.

@mikegreiling
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikegreiling/e2ac00a45b9994adebda to your computer and use it in GitHub Desktop.
Save mikegreiling/e2ac00a45b9994adebda to your computer and use it in GitHub Desktop.
Xdebug Toggle Bookmarklet (With WebKit Notifications)
/*
Adapted from http://pollinimini.net/blog/xdebug-bookmarklet/
WebKit notifications added
©2014 PixelCog Inc. MIT License
*/
(function() {
var idekey = '',
minutes = 10,
exp = new Date(),
enabled = false;
if (0 !== window.webkitNotifications.checkPermission()) {
window.webkitNotifications.requestPermission();
} else {
if (document.cookie.match(/(^|;)\s*XDEBUG_SESSION=/)) {
minutes = -minutes;
} else {
if (!idekey) idekey = prompt('Set the IDE key for this debugging session if needed (cancel to disable)', 'default');
if (idekey === null) {
minutes = -minutes;
} else {
enabled = true;
}
}
exp.setTime(exp.getTime() + minutes * 60 * 1000);
document.cookie = 'XDEBUG_SESSION=' + (idekey ? idekey : 'default') + ';expires=' + exp.toGMTString()
if (0 === window.webkitNotifications.checkPermission()) {
var notification = window.webkitNotifications.createNotification(null,
'Xdebug ' + (enabled ? 'Enabled' : 'Disabled'),
'Xdebug has been ' + (enabled ? 'enabled (key = "' + idekey + '")' : 'disabled'));
notification.onclick = function() {
window.focus()
notification.close()
}
notification.show()
}
}
}())
javascript:(function(){var e="",t=10,n=new Date,r=false;if(0!==window.webkitNotifications.checkPermission()){window.webkitNotifications.requestPermission()}else{if(document.cookie.match(/(^|;)\s*XDEBUG_SESSION=/)){t=-t}else{if(!e)e=prompt("Set the IDE key for this debugging session if needed (cancel to disable)","default");if(e===null){t=-t}else{r=true}}n.setTime(n.getTime()+t*60*1e3);document.cookie="XDEBUG_SESSION="+(e?e:"default")+";expires="+n.toGMTString();if(0===window.webkitNotifications.checkPermission()){var i=window.webkitNotifications.createNotification(null,"Xdebug "+(r?"Enabled":"Disabled"),"Xdebug has been "+(r?'enabled (key = "'+e+'")':"disabled"));i.onclick=function(){window.focus();i.close()};i.show()}}})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment