Skip to content

Instantly share code, notes, and snippets.

@kirbysayshi
Forked from itod/fluid_gmail.js
Created April 10, 2013 17:19
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save kirbysayshi/5356592 to your computer and use it in GitHub Desktop.
Save kirbysayshi/5356592 to your computer and use it in GitHub Desktop.
window.fluid.dockBadge = '';
setTimeout(updateDockBadge, 1000);
setTimeout(updateDockBadge, 3000);
setInterval(updateDockBadge, 5000);
function updateDockBadge() {
var navigation = document.querySelector('[role=navigation]')
var doc = navigation.contentDocument || navigation.ownerDocument;
if (!doc) { return; }
var anchors = [].slice.call(doc.querySelectorAll('a'))
var result = anchors.reduce(function(prev, curr, i) {
var match = curr.innerText.match(/\s*Inbox\s*\((\d+)\)[^\d]*/)
if (match) return match;
else return prev;
}, null);
if (result && result[1]) {
window.fluid.dockBadge = result[1];
}
}
@piranha
Copy link

piranha commented Jan 2, 2016

Just in case anybody looks at this: loop at line 15 is really inefficient and something like this will eat much less CPU.

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