Last active
August 29, 2015 14:21
-
-
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.
This file contains 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
/** | |
* 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