-
-
Save mhaylock/e592a2145d585a806c68 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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. | |
*/ | |
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 { | |
//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(); | |
} |
@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
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 :(