Skip to content

Instantly share code, notes, and snippets.

@nrutman
Last active August 29, 2015 14:21
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 nrutman/bf139fedd2ecb28900ec to your computer and use it in GitHub Desktop.
Save nrutman/bf139fedd2ecb28900ec to your computer and use it in GitHub Desktop.
A Fluid userscript to show the unread message count for a Gmail SSB.
/**
* A userscript for Fluid. This script updates the dock badge for a Gmail SSB
* to the number of unread messages in the Inbox.
*
* NOTE: For best results, make sure the User Agent is set to a Safari agent.
*/
initialize();
function initialize() {
updateDockBadge();
}
function getUnreadBadge() {
var regex = /\s*Inbox\s*\((\d+)\)[^\d]*/;
var inboxLink = document.querySelectorAll('[role=navigation] a');
if (!inboxLink.length) {
return '';
}
var matches = inboxLink[0].innerText.match(regex);
if (!matches || matches.length < 2) {
return '';
}
return matches[1];
}
function updateDockBadge() {
window.fluid.dockBadge = getUnreadBadge();
setTimeout(updateDockBadge, 1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment