Last active
June 22, 2016 21:17
-
-
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).
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
(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); |
done.
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
why not add some comment so we can know what this code's capability? : )