/* 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 = ''; } } }