Skip to content

Instantly share code, notes, and snippets.

@johanoloflindberg
Forked from itod/gmail_userscript.js
Created November 21, 2016 03:14
Show Gist options
  • Save johanoloflindberg/c02d57758e5c19b2d5d069a5759e2475 to your computer and use it in GitHub Desktop.
Save johanoloflindberg/c02d57758e5c19b2d5d069a5759e2475 to your computer and use it in GitHub Desktop.
Fluid Gmail Userscript
window.fluid.dockBadge = '';
setTimeout(updateDockBadge, 1000);
setTimeout(updateDockBadge, 3000);
setInterval(updateDockBadge, 5000);
function updateDockBadge() {
var newBadge = '';
// loop thru anchor tags
var anchorEls = document.getElementsByTagName('a');
//console.log('anchors: ' + anchorEls.length);
var regex = /\s*Inbox\s*\((\d+)\)[^\d]*/;
for (var i = 0; i < anchorEls.length; i++) {
var anchorEl = anchorEls[i];
//console.log('anchorEl: '+ anchorEl);
var text = '' + anchorEl.innerText;
if (!text.length) continue;
if (-1 == text.indexOf('(')) continue;
var res = text.match(regex);
if (res && res.length > 1) {
//console.log('res: '+ res);
newBadge = res[1];
break;
}
}
window.fluid.dockBadge = newBadge;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment