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.

Revisions

  1. mhaylock revised this gist Jun 8, 2015. 1 changed file with 58 additions and 35 deletions.
    93 changes: 58 additions & 35 deletions google-inbox-userscript.js
    Original file line number Diff line number Diff line change
    @@ -17,45 +17,68 @@ Some Caveats:
    TODO: Update count on item removal / read.
    */
    window.fluid.dockBadge = '';
    setTimeout(updateBadge, 5000);
    setInterval(updateBadge, 10000);

    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.querySelector('[jsaction="global.navigate_and_refresh"] > span:first-child'),
    inboxTabTitle = '',
    inboxTabStyle = 'display: none;';
    if (inboxTabSpan) {
    inboxTabTitle = inboxTabSpan.getAttribute('title');
    inboxTabStyle = inboxTabSpan.getAttribute('style');
    }

    if (inboxTabStyle === 'display: none;') {
    // Inbox hidden.
    window.fluid.dockBadge = '?';
    } else {
    //Check for Inbox Zero Sunrise Image
    var inboxZero = document.getElementsByClassName('j');
    if (inboxZero.length >= 1) {
    window.fluid.dockBadge = '';
    function loadScript(url, onload) {
    var element = document.createElement('script');
    element.type = 'text/javascript';
    element.src = url;
    element.onload = onload;
    document.getElementsByTagName("head")[0].appendChild(element);
    }

    function onload() {
    window.fluid.dockBadge = '';
    setTimeout(updateBadge, 5000);
    setInterval(updateBadge, 10000);

    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.querySelector('[jsaction="global.navigate_and_refresh"]'),
    inboxTabTitle = '',
    inboxTabStyle = 'display: none;';
    if (inboxTabSpan) {
    inboxTabTitle = inboxTabSpan.getAttribute('title');
    inboxTabStyle = inboxTabSpan.getAttribute('style');
    }

    if (inboxTabStyle === 'display: none;') {
    // Inbox hidden.
    window.fluid.dockBadge = '?';
    } else {
    // Inbox visible
    var unreadEmails = document.getElementsByClassName('qu');
    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 {
    //Check for Inbox Zero Sunrise Image
    var inboxZero = $('.j');
    if (inboxZero.length >= 1) {
    window.fluid.dockBadge = '';
    } else {
    // Inbox visible
    var allEmails = $('.scroll-list-item');
    var unreadEmails = allEmails.find('div:contains("Unread"):not(:has(*)):visible');

    var count = 0;

    unreadEmails.each(function ($row) {

    });

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

    if (typeof window.jQuery === 'undefined') {
    loadScript('//ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js', onload);
    } else {
    onload();
    }
  2. mhaylock revised this gist Mar 18, 2015. 1 changed file with 7 additions and 3 deletions.
    10 changes: 7 additions & 3 deletions google-inbox-userscript.js
    Original file line number Diff line number Diff line change
    @@ -23,9 +23,13 @@ setInterval(updateBadge, 10000);

    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.querySelector('[jsaction="global.navigate_and_refresh"] > span:first-child');
    var inboxTabTitle = inboxTabSpan.getAttribute('title');
    var inboxTabStyle = inboxTabSpan.getAttribute('style');
    var inboxTabSpan = document.querySelector('[jsaction="global.navigate_and_refresh"] > span:first-child'),
    inboxTabTitle = '',
    inboxTabStyle = 'display: none;';
    if (inboxTabSpan) {
    inboxTabTitle = inboxTabSpan.getAttribute('title');
    inboxTabStyle = inboxTabSpan.getAttribute('style');
    }

    if (inboxTabStyle === 'display: none;') {
    // Inbox hidden.
  3. mhaylock revised this gist Mar 18, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions google-inbox-userscript.js
    Original file line number Diff line number Diff line change
    @@ -23,7 +23,7 @@ setInterval(updateBadge, 10000);

    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('d4')[0].getElementsByTagName('span')[0];
    var inboxTabSpan = document.querySelector('[jsaction="global.navigate_and_refresh"] > span:first-child');
    var inboxTabTitle = inboxTabSpan.getAttribute('title');
    var inboxTabStyle = inboxTabSpan.getAttribute('style');

    @@ -37,7 +37,7 @@ function updateBadge() {
    window.fluid.dockBadge = '';
    } else {
    // Inbox visible
    var unreadEmails = document.getElementsByClassName('bX oD');
    var unreadEmails = document.getElementsByClassName('qu');
    var totalEmails = document.getElementsByClassName('scroll-list-item');

    /////////////////////////////
  4. @aaronn aaronn revised this gist Nov 21, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion google-inbox-userscript.js
    Original file line number Diff line number Diff line change
    @@ -31,7 +31,7 @@ function updateBadge() {
    // Inbox hidden.
    window.fluid.dockBadge = '?';
    } else {
    //Check for Inbox Zero
    //Check for Inbox Zero Sunrise Image
    var inboxZero = document.getElementsByClassName('j');
    if (inboxZero.length >= 1) {
    window.fluid.dockBadge = '';
  5. @aaronn aaronn revised this gist Nov 21, 2014. 1 changed file with 20 additions and 15 deletions.
    35 changes: 20 additions & 15 deletions google-inbox-userscript.js
    Original file line number Diff line number Diff line change
    @@ -17,7 +17,6 @@ Some Caveats:
    TODO: Update count on item removal / read.
    */

    window.fluid.dockBadge = '';
    setTimeout(updateBadge, 5000);
    setInterval(updateBadge, 10000);
    @@ -32,21 +31,27 @@ function updateBadge() {
    // Inbox hidden.
    window.fluid.dockBadge = '?';
    } else {
    // Inbox visible
    var unreadEmails = document.getElementsByClassName('bX oD');
    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 {
    //Check for Inbox Zero
    var inboxZero = document.getElementsByClassName('j');
    if (inboxZero.length >= 1) {
    window.fluid.dockBadge = '';
    } else {
    // Inbox visible
    var unreadEmails = document.getElementsByClassName('bX oD');
    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 = '';
    }
    }
    }
    }
  6. @aaronn aaronn revised this gist Nov 21, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion google-inbox-userscript.js
    Original file line number Diff line number Diff line change
    @@ -32,7 +32,7 @@ function updateBadge() {
    // Inbox hidden.
    window.fluid.dockBadge = '?';
    } else {
    // Inbox visible.
    // Inbox visible
    var unreadEmails = document.getElementsByClassName('bX oD');
    var totalEmails = document.getElementsByClassName('scroll-list-item');

  7. @aaronn aaronn revised this gist Nov 21, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion google-inbox-userscript.js
    Original file line number Diff line number Diff line change
    @@ -40,7 +40,7 @@ function updateBadge() {
    // totalEmails.length = ALL EMAILS IN INBOX
    // OR
    // unreadEmails.length = ONLY UNREAD ITEMS IN INBOX
    var count = totalEmails.length;
    var count = unreadEmails.length;
    /////////////////////////////

    if (count >= 1) {
  8. @aaronn aaronn revised this gist Nov 21, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion google-inbox-userscript.js
    Original file line number Diff line number Diff line change
    @@ -28,7 +28,7 @@ function updateBadge() {
    var inboxTabTitle = inboxTabSpan.getAttribute('title');
    var inboxTabStyle = inboxTabSpan.getAttribute('style');

    if (inboxTabStyle == 'display: none;') {
    if (inboxTabStyle === 'display: none;') {
    // Inbox hidden.
    window.fluid.dockBadge = '?';
    } else {
  9. @aaronn aaronn revised this gist Nov 21, 2014. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions google-inbox-userscript.js
    Original file line number Diff line number Diff line change
    @@ -28,7 +28,7 @@ function updateBadge() {
    var inboxTabTitle = inboxTabSpan.getAttribute('title');
    var inboxTabStyle = inboxTabSpan.getAttribute('style');

    if (inboxTabStyle == "display: none;") {
    if (inboxTabStyle == 'display: none;') {
    // Inbox hidden.
    window.fluid.dockBadge = '?';
    } else {
    @@ -37,9 +37,9 @@ function updateBadge() {
    var totalEmails = document.getElementsByClassName('scroll-list-item');

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

  10. @aaronn aaronn revised this gist Nov 21, 2014. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions google-inbox-userscript.js
    Original file line number Diff line number Diff line change
    @@ -19,8 +19,8 @@ TODO: Update count on item removal / read.
    */

    window.fluid.dockBadge = '';
    setTimeout(updateBadge, 2500);
    setInterval(updateBadge, 5000);
    setTimeout(updateBadge, 5000);
    setInterval(updateBadge, 10000);

    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)
  11. @aaronn aaronn revised this gist Nov 21, 2014. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions google-inbox-userscript.js
    Original file line number Diff line number Diff line change
    @@ -19,8 +19,8 @@ TODO: Update count on item removal / read.
    */

    window.fluid.dockBadge = '';
    setTimeout(updateBadge, 5000);
    setInterval(updateBadge, 10000);
    setTimeout(updateBadge, 2500);
    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)
    @@ -40,11 +40,11 @@ function updateBadge() {
    // totalEmails = ALL EMAILS IN INBOX
    // OR
    // unreadEmails = ONLY UNREAD ITEMS IN INBOX
    var count = totalEmails;
    var count = totalEmails.length;
    /////////////////////////////

    if (count >= 1) {
    window.fluid.dockBadge = count.length;
    window.fluid.dockBadge = count;
    } else {
    window.fluid.dockBadge = '';
    }
  12. @aaronn aaronn revised this gist Nov 21, 2014. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions google-inbox-userscript.js
    Original file line number Diff line number Diff line change
    @@ -13,6 +13,7 @@ Includes options for total badge count and unread badge count.
    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.
    */
  13. @aaronn aaronn revised this gist Nov 21, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion google-inbox-userscript.js
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,7 @@ Includes options for total badge count and unread badge count.
    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 '?' as a reminder.
    - 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).
    TODO: Update count on item removal / read.
    */
  14. @aaronn aaronn revised this gist Nov 21, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion google-inbox-userscript.js
    Original file line number Diff line number Diff line change
    @@ -28,7 +28,7 @@ function updateBadge() {
    var inboxTabStyle = inboxTabSpan.getAttribute('style');

    if (inboxTabStyle == "display: none;") {
    // Inbox hidden, don't scrape. (Kind of shitty solution, yeah.)
    // Inbox hidden.
    window.fluid.dockBadge = '?';
    } else {
    // Inbox visible.
  15. @aaronn aaronn revised this gist Nov 21, 2014. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions google-inbox-userscript.js
    Original file line number Diff line number Diff line change
    @@ -16,6 +16,7 @@ Some Caveats:
    TODO: Update count on item removal / read.
    */

    window.fluid.dockBadge = '';
    setTimeout(updateBadge, 5000);
    setInterval(updateBadge, 10000);
  16. @aaronn aaronn revised this gist Nov 21, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion google-inbox-userscript.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    /* This is a FluidApp userscript for Google Inbox on the desktop.
    /* 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/)
  17. @aaronn aaronn revised this gist Nov 21, 2014. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions google-inbox-userscript.js
    Original file line number Diff line number Diff line change
    @@ -17,10 +17,10 @@ Some Caveats:
    TODO: Update count on item removal / read.
    */
    window.fluid.dockBadge = '';
    setTimeout(updateDockBadge, 3000);
    setInterval(updateDockBadge, 15000);
    setTimeout(updateBadge, 5000);
    setInterval(updateBadge, 10000);

    function updateDockBadge() {
    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('d4')[0].getElementsByTagName('span')[0];
    var inboxTabTitle = inboxTabSpan.getAttribute('title');
  18. @aaronn aaronn revised this gist Nov 21, 2014. 1 changed file with 2 additions and 3 deletions.
    5 changes: 2 additions & 3 deletions google-inbox-userscript.js
    Original file line number Diff line number Diff line change
    @@ -27,11 +27,10 @@ function updateDockBadge() {
    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.
    // Inbox hidden, don't scrape. (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.
    // Inbox visible.
    var unreadEmails = document.getElementsByClassName('bX oD');
    var totalEmails = document.getElementsByClassName('scroll-list-item');

  19. @aaronn aaronn revised this gist Nov 21, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion google-inbox-userscript.js
    Original file line number Diff line number Diff line change
    @@ -42,7 +42,7 @@ function updateDockBadge() {
    var count = totalEmails;
    /////////////////////////////

    if (count) {
    if (count >= 1) {
    window.fluid.dockBadge = count.length;
    } else {
    window.fluid.dockBadge = '';
  20. @aaronn aaronn revised this gist Nov 21, 2014. 1 changed file with 0 additions and 3 deletions.
    3 changes: 0 additions & 3 deletions google-inbox-userscript.js
    Original file line number Diff line number Diff line change
    @@ -35,15 +35,12 @@ function updateDockBadge() {
    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;
  21. @aaronn aaronn revised this gist Nov 21, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion google-inbox-userscript.js
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,7 @@ Includes options for total badge count and unread badge count.
    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 '?'
    - The workaround is to only show the badge count when looking at the inbox, otherwise it shows '?' as a reminder.
    TODO: Update count on item removal / read.
    */
  22. @aaronn aaronn revised this gist Nov 21, 2014. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions google-inbox-userscript.js
    Original file line number Diff line number Diff line change
    @@ -7,8 +7,8 @@ Includes options for total badge count and unread badge count.
    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.
    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.
  23. @aaronn aaronn revised this gist Nov 21, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion google-inbox-userscript.js
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@ Includes options for total badge count and unread badge count.
    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 this document into the script area below that.
    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.
  24. @aaronn aaronn revised this gist Nov 21, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion google-inbox-userscript.js
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    /* 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
    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'.
  25. @aaronn aaronn revised this gist Nov 21, 2014. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion google-inbox-userscript.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,6 @@
    /* This is a FluidApp userscript for Google Inbox on the desktop. Includes options for total badge count and unread badge count.
    /* 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
    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
  26. @aaronn aaronn revised this gist Nov 21, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion google-inbox-userscript.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    /* This is a FluidApp userscript for Google Inbox on the 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
    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
  27. @aaronn aaronn revised this gist Nov 21, 2014. 1 changed file with 13 additions and 3 deletions.
    16 changes: 13 additions & 3 deletions google-inbox-userscript.js
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,16 @@
    /* 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 a 'Go To Inbox' message.
    The idea here is it's better to show an explicitly 'bad count' than a wrong count if it's sitting in the dock for a while and you're expecting an email.
    /* This is a FluidApp userscript for Google Inbox on the desktop.
    1) You need the paid version of FluidApp
    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 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.
    */
  28. @aaronn aaronn renamed this gist Nov 21, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  29. @aaronn aaronn created this gist Nov 21, 2014.
    42 changes: 42 additions & 0 deletions google-inbox-userscript
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    /* 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 a 'Go To Inbox' message.
    The idea here is it's better to show an explicitly 'bad count' than a wrong count if it's sitting in the dock for a while and you're expecting an email.

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