Skip to content

Instantly share code, notes, and snippets.

@pascalpp
Last active June 22, 2016 21:17
Show Gist options
  • Save pascalpp/9521278 to your computer and use it in GitHub Desktop.
Save pascalpp/9521278 to your computer and use it in GitHub Desktop.
A userscript for Pivotal Tracker (http://www.pivotaltracker.com) as a Fluid app (http://fluidapp.com).
(function() {
'use strict';
var exports = this, tracker = _.namespace(exports, 'tracker');
/////////////////////////////
// automatically resize all open panels to fill the window when resizing
// or when toggling the side bar
var resizePanels = function() {
tracker.$('.table').trigger('fit:panels');
}
$(window).on('resize', resizePanels);
$('body').on('click', 'aside.sidebar .toggle_sidebar', function() {
resizePanels();
});
resizePanels();
/////////////////////////////
// update the dock badge when new notifications arrive
// and send a Mac OS X notification
function updateDockBadge() {
console.log(window.fluid.applicationPath)
var lastbadge = window.fluid.dockBadge;
var badge = $('.menu.notifications .counter').text();
//badge = 3;
window.fluid.dockBadge = Number(badge) || "";
var newnotes = badge - lastbadge;
if (newnotes > 0) {
var o = {};
o.identifier = 'Pivotal Tracker';
o.sticky = true;
o.icon = "http://www.pascal.com/misc/fluidicons/pivotaltracker.png";
if (newnotes === 1) {
var node = $('.menu.notifications .notification').first();
o.title = node.find('.details').text();
o.description = node.find('.message').text();
if (node.find('.message').hasClass('with_context')) {
o.description += "\n“"+$.trim(node.find('.context').text())+"”";
}
} else {
o.title = "You have "+newnotes+" new notifications.";
o.description = "Click for details.";
}
//window.fluid.showGrowlNotification(o);
var notification = window.webkitNotifications.createNotification(o.icon, o.title, o.description);
notification.onclick = function() {
$('.menu.notifications a.bell').click();
window.fluid.activate();
}
notification.show();
}
}
// reset the dock badge on start up and update it every 5 seconds
window.fluid.dockBadge = "";
setInterval(updateDockBadge, 5000);
/////////////////////////////
// check for notification permissions
if (window.webkitNotifications.checkPermission() === 1) {
$('body').one('click', '.menu.notifications', function() {
console.log('webkitNotifications.requestPermission');
window.webkitNotifications.requestPermission();
});
}
}).call(this);
@latel
Copy link

latel commented Mar 13, 2014

why not add some comment so we can know what this code's capability? : )

@pascalpp
Copy link
Author

done.

@charlotte-miller
Copy link

This is great - thanks for sharing!
I had an issue with line 3 (_ is undefined), but everything worked after commenting it out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment