Skip to content

Instantly share code, notes, and snippets.

@aaronn
Last active April 11, 2019 15:24
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save aaronn/3dd4bc8f9b70b9e0a06c to your computer and use it in GitHub Desktop.
Save aaronn/3dd4bc8f9b70b9e0a06c to your computer and use it in GitHub Desktop.
Google Inbox for Desktop (Fluid Userscript)
/* This is a FluidApp userscript for Google Inbox for Mac.
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. (CMD + R)
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 the inbox tab is active, otherwise it shows '?' as a reminder on other tabs (snoozed, etc).
- No idea how well this works with more than one tab open.
TODO: Update count on item removal / read.
*/
window.fluid.dockBadge = '';
setTimeout(updateBadge, 5000);
setInterval(updateBadge, 5000);
function updateBadge() {
// 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('bl')[0].getElementsByTagName('span')[0];
var inboxTabTitle = inboxTabSpan.getAttribute('title');
var inboxTabStyle = inboxTabSpan.getAttribute('style');
if (inboxTabStyle === 'display: none;') {
// Inbox hidden.
window.fluid.dockBadge = '?';
} else {
//Check for Inbox Zero
var inboxZero = document.getElementsByClassName('j');
if (inboxZero.length >= 1) {
window.fluid.dockBadge = '';
} else {
// Inbox visible
var unreadEmails = document.getElementsByClassName('ss');
var totalEmails = document.getElementsByClassName('scroll-list-item');
/////////////////////////////
// totalEmails.length = ALL EMAILS IN INBOX
// OR
// unreadEmails.length = ONLY UNREAD ITEMS IN INBOX
var count = unreadEmails.length;
/////////////////////////////
if (count >= 1) {
window.fluid.dockBadge = count;
} else {
window.fluid.dockBadge = '';
}
}
}
}
@dotconor
Copy link

dotconor commented Jan 8, 2015

from

            var unreadEmails = document.getElementsByClassName('bX oD');

to:

            var unreadEmails = document.getElementsByClassName('bX oH');

That Unread Count line didn't work for me, but this one seems to.

@ashmckenzie
Copy link

Here's a condensed version that waits 3 secs before checking, then checks every 3 secs:

updateBadge();
setTimers();

function setTimers() {
  setTimeout(checkUnread, 3000);
  setInterval(checkUnread, 3000);    
}

function checkUnread() {
  updateBadge(document.getElementsByClassName('qu').length);
}

function updateBadge(count) {
  window.fluid.dockBadge = (count >= 1) ? count : '';
}

@cooperaj
Copy link

Just thought I'd leave a note that the 'qu' class has now changed to 'ju'.

@eirikora
Copy link

Seems as if these methods of identifying inbox size are not stable... I have tried to debug, but I'm not able to identify the new class name... :-/

@aaronn
Copy link
Author

aaronn commented May 22, 2015

Yep-- definitely not stable / sustainable. No other way to scrape though :\

@shaunbrazier
Copy link

Class name of 'qG' works nicely right now.

@shaunbrazier
Copy link

... which means a slight tweak to ashmckenzie's condensed version above:

updateBadge();
setTimers();

function setTimers() {
  setTimeout(checkUnread, 3000);
  setInterval(checkUnread, 3000);    
}

function checkUnread() {
  updateBadge(document.getElementsByClassName('qG').length);
}

function updateBadge(count) {
  window.fluid.dockBadge = (count >= 1) ? count : '';
}

@cooperaj
Copy link

Having taken a look through it appears they are attempting to make thing accessible. This means lots of aria items. One of which appears to be aria="listitem". This only appears, from my brief look to correspond to actual mails. Might help?

@jramapuram
Copy link

Is there a way to update the pinned status bar icon instead of the dock badge?

@bohitomi
Copy link

+1 for status bar question!

(by the way the bad icon counter doesn't work for me :/)

@mykecheckonetwo
Copy link

Any reason why when I do this, the badge just flickers? It properly displays the unread amount but it flashes every few seconds. Probably in the same interval as the checkunread interval.

I'm using the condensed version from the latest comment.

@pedromarins
Copy link

@aaronn do you have any update on this? looks like this code doesn't work!

Thanks for your effort though!

@jtomka
Copy link

jtomka commented Dec 9, 2015

This seems to be working for me right now:

/* This is a FluidApp userscript for Google Inbox for Mac. 
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. (CMD + R)

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 the inbox tab is active, otherwise it shows '?' as a reminder on other tabs (snoozed, etc).
- No idea how well this works with more than one tab open.

TODO: Update count on item removal / read.
*/
window.fluid.dockBadge = '';
setTimeout(updateBadge, 1000);
setInterval(updateBadge, 5000);

function updateBadge() {
    // 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('bl')[0];
    var inboxTabTitle = inboxTabSpan.getAttribute('title');
    var inboxTabStyle = inboxTabSpan.getAttribute('style');

    if (inboxTabTitle != 'Inbox') {
        // Inbox hidden.
        window.fluid.dockBadge = '?';
    } else {
        //Check for Inbox Zero
        var inboxZero = document.getElementsByClassName('j');
        if (inboxZero.length >= 1) {
            window.fluid.dockBadge = '';
        } else {
            // Inbox visible
            var unreadEmails = document.getElementsByClassName('ss');
            var totalEmails = document.getElementsByClassName('scroll-list-item');

            /////////////////////////////
            // totalEmails.length = ALL EMAILS IN INBOX
            // OR
            // unreadEmails.length = ONLY UNREAD ITEMS IN INBOX
            var count = unreadEmails.length;
            /////////////////////////////

            if (count >= 1) {
                window.fluid.dockBadge = count;
            } else {
                window.fluid.dockBadge = '';
            }
        }
    }
}

@YoungCatChen
Copy link

FYI, a working (for now) script can be found at https://github.com/YoungCatChen/fluid-inbox-userscript.
My script doesn't use classNames that change now and then. It finds elements by attributes instead.
Hopefully it can last longer.

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