Skip to content

Instantly share code, notes, and snippets.

@kevshub
Forked from kirbysayshi/fluid_gmail.js
Last active November 21, 2016 03:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kevshub/5593897 to your computer and use it in GitHub Desktop.
Save kevshub/5593897 to your computer and use it in GitHub Desktop.
- Removed duplicate timers - Added a remove badge option - Added (Advanced) Growl Notifications, # of new emails and # of unread messages. - Only notify when email counter goes up not down - Added sound notification
window.fluid.dockBadge = '';
function updateDockBadge() {
console.log('check new messages');
var navigation = document.querySelector('[role=navigation]')
var doc = navigation.contentDocument || navigation.ownerDocument;
if (!doc) { return; }
var anchors = [].slice.call(doc.querySelectorAll('a'))
var result = anchors.reduce(function(prev, curr, i) {
var match = curr.innerText.match(/\s*Inbox\s*\((\d+)\)[^\d]*/)
if (match) return match;
else return prev;
}, null);
if (result && result[1]) {
if (window.fluid.dockBadge < result[1]) {
var extraess = "", extraessb = "";
if (result[1] != 1) { extraess = "s"; }
var extramessages = result[1] - window.fluid.dockBadge;
if (extramessages > 1) { extraessb = "s"; }
window.fluid.showGrowlNotification({
title: extramessages+" New Email"+extraessb,
description: "You have "+result[1]+" unread message"+extraess,
sticky: false,
onclick: function() {
console.log("Show Window"); //doesnt work
},
identifier: "gmail"
});
window.fluid.playSound("Purr");
}
window.fluid.dockBadge = result[1];
} else {
window.fluid.dockBadge = '';
}
}
setInterval(updateDockBadge, 10000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment