Skip to content

Instantly share code, notes, and snippets.

@BohdanTkachenko
Created June 12, 2015 20:15
Show Gist options
  • Save BohdanTkachenko/1d4e0c12186f8a33b1e1 to your computer and use it in GitHub Desktop.
Save BohdanTkachenko/1d4e0c12186f8a33b1e1 to your computer and use it in GitHub Desktop.
Fluid - Google Inbox - Badge
function getMessagesCount() {
var re = /\((\d+)\)/;
var count = 0;
Array.prototype.slice.call(document.querySelectorAll('.scroll-list-item.top-level-item')).forEach(function (el) {
if (el.attributes.class.value.split(' ').indexOf('scroll-list-item-cluster') >= 0 && re.test(el.innerText)) {
count += parseInt(/\((\d+)\)/.exec(el.innerText)[1], 10);
} else {
count++;
}
});
return '' + (count || '');
}
function updateBadge() {
window.fluid.dockBadge = getMessagesCount();
}
window.fluid.dockBadge = getMessagesCount();
setInterval(updateBadge, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment