Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Userscript for Fluid App (http://fluidapp.com) to enable dock count and desktop notifications for Google Inbox
window.fluid.dockBadge = '';
// for tracking when to notify
var previousUnreadCount = 0;
// Main polling
var readyStateCheckInterval = setInterval(function() {
if(document.readyState === "complete") {
setInterval(updateDockBadge, 3000);
clearInterval(readyStateCheckInterval);
}
}, 3000);
function updateDockBadge() {
var currentUnreadCount = 0;
var badge = document.getElementsByClassName('qG').length;
if (badge) {
if(parseInt(badge) > 0) {
currentUnreadCount += parseInt(badge);
}
}
if(currentUnreadCount == 0) {
window.fluid.dockBadge = '';
previousUnreadCount = 0;
} else {
// update dock with new count
window.fluid.dockBadge = currentUnreadCount;
// determine how many new mails there are and notify
var unreadMailCount = currentUnreadCount - previousUnreadCount;
if(unreadMailCount > 0) {
notify(unreadMailCount);
previousUnreadCount = currentUnreadCount;
}
}
}
// Creates a Notification Center message, if supported
function notify(count) {
var supportsWebkitNotifications = ('webkitNotifications' in window);
if(count > 0 && supportsWebkitNotifications) {
if(webkitNotifications.checkPermission() == 0) {
body = (count == 1) ? '1 new message' : count + ' new messages';
webkitNotifications.createNotification(
null,
'You got mail',
body
).show();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.