Skip to content

Instantly share code, notes, and snippets.

@mhaylock
Forked from aaronn/google-inbox-userscript.js
Last active August 29, 2015 14:17
Show Gist options
  • Save mhaylock/e592a2145d585a806c68 to your computer and use it in GitHub Desktop.
Save mhaylock/e592a2145d585a806c68 to your computer and use it in GitHub Desktop.
/* This is a FluidApp userscript for Google Inbox on the desktop.
Includes options for total badge count and unread badge count.
1) You need the paid version of FluidApp (http://fluidapp.com/)
2) Point Fluid to https://inbox.google.com (I recommend the icon from here: https://medium.com/@chrismessina/create-an-icon-for-google-inbox-in-your-dock-ed269312e3bc)
3) Set the user-agent to Chrome
4) Go to window -> userscript and add click the plus sign under the first table (on the left). Name the item 'Inbox'.
5) In the second table (on the right) click the plus and type in "*inbox.google.com*".
6) Paste the contents of this document into the script area below that.
7) Configure badge count (for total or unread only in the code below).
8) Refresh your FluidApp.
Some Caveats:
- This doesn't update the badge unless it's looking at the inbox.
- The workaround is to only show the badge count when looking at the inbox, otherwise it shows '?'
TODO: Update count on item removal / read.
*/
window.fluid.dockBadge = '';
setTimeout(updateDockBadge, 3000);
setInterval(updateDockBadge, 15000);
function updateDockBadge() {
// Inbox title will always be the first item in the D4 Class. It's shown and unshown depending on the selected folder (snoozed, etc)
var inboxTabSpan = document.getElementsByClassName('d4')[0].getElementsByTagName('span')[0];
var inboxTabTitle = inboxTabSpan.getAttribute('title');
var inboxTabStyle = inboxTabSpan.getAttribute('style');
if (inboxTabStyle == "display: none;") {
// If the first item isn't being shown we know that inbox is hidden-- so we should reset the badge to remind the user to swap it out.
// Kind of shitty solution, yeah.
window.fluid.dockBadge = '?';
} else {
// We know the user has the inbox visible so we can start scraping for the badge count.
var unreadEmails = document.getElementsByClassName('bX oD');
var totalEmails = document.getElementsByClassName('scroll-list-item');
// CUSTOMIZE HERE
/////////////////////////////
/////////////////////////////
// totalEmails = ALL EMAILS IN INBOX
// OR
// unreadEmails = ONLY UNREAD ITEMS IN INBOX
var count = totalEmails;
/////////////////////////////
/////////////////////////////
if (count) {
window.fluid.dockBadge = count.length;
} else {
window.fluid.dockBadge = '';
}
}
}
@cooperaj
Copy link

Thankyou for fixing this. Just got my invite to Inbox and bought the Fluid app based on the article that had the original. Was very sad to see it broken :(

@mhaylock
Copy link
Author

mhaylock commented Jun 8, 2015

@cooperaj oh thanks, sorry I missed your comment. Only saw it now as I've just updated this to keep it working with the latest changes :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment