I’ve been enjoying using a Fluid App for my Google Mail account and I bought the Pro version for $5, primarily so I could get a badge in my dock with a count of unread messages. Unfortunately, the script that ships with the app to display this account no longer works, likely due to changes in Gmail itself. The original script parses the very complex markup to get the inbox value. My simplified script just reads the window title to determine the unread count. Here’s how to install the script:
- Window > Userscripts
- Create a new script
- Pattern: “*mail.google.com*”
- Script:
window.fluid.dockBadge = ''; setTimeout(updateDockBadge, 3000); setInterval(updateDockBadge, 15000); function updateDockBadge() { var title = document.title; var regex = /s*Inboxs*((d+))[^d]*/; var res = title.match(regex); if (res && res.length > 1) { var newBadge = res[1]; window.fluid.dockBadge = newBadge; } else { regex = /^Inbox -/; if(regex.test(title)){ window.fluid.dockBadge = ''; } } }
How it works:
It reads the window title and detects if you’re in the inbox and if there’s a number representing unread messages.
- If so, it puts that number in the badge
- If not, but you are in the inbox, it clears the badge
- If you are viewing a message it does nothing to the badge since the unread count only shows on the inbox
This is obviously less technically clever than a script that reads the inbox count from the page markup directly, but it’s much less likely to break with changes to Google Mail, and much easier to understand and therefore fix if something does break.
As an aside, if you’re looking for a fancy Gmail icon, check out this set in the flickr Fluid Icon Pool.
Update: This works if you use English language settings for Gmail. Otherwise, you’ll have to change the word “inbox” to whatever is appropriate in your language.
Thanks man, works perfect.
Hey, your approach didn’t seem to work anymore (for me at least), so I tweaked it to read the count from the Inbox link in the sidebar. You can grab the updated code from this Gist:
https://gist.github.com/jakebellacera/4772194