Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Gmail Fluid App Userscript
window.fluid.dockBadge = '';
setTimeout(updateDockBadge, 1000);
setTimeout(updateDockBadge, 3000);
setInterval(updateDockBadge, 5000);
function updateDockBadge() {
var newBadge = '';
var res = findInboxAnchorMatchResult();
if (res) {
newBadge = res[1];
}
window.fluid.dockBadge = newBadge;
}
function findInboxAnchorMatchResult() {
var xpathType = XPathResult.FIRST_ORDERED_NODE_TYPE;
var xpathResult = document.evaluate('//div[@role="navigation"]', document, null, xpathType, null);
var canvas = xpathResult.singleNodeValue;
//console.log('canvas: ' + canvas);
if (!canvas) return null;
// get document
var doc = canvas.contentDocument || canvas.ownerDocument;
//console.log('doc: ' + doc);
if (!doc) return null;
// loop thru anchor tags
var anchorEls = doc.getElementsByTagName('a');
//console.log('anchors: ' + anchorEls.length);
if (!anchorEls || !anchorEls.length) return null;
for (var i = 0; i < anchorEls.length; i++) {
var anchorEl = anchorEls[i];
//console.log('anchorEl: '+ anchorEl);
var res = matchInAnchorEl(anchorEl);
if (res) {
//console.log('res: '+ res);
return res;
}
}
return null;
}
function matchInAnchorEl(anchorEl) {
var text = '' + anchorEl.innerText;
if (!text.length) return null;
if (-1 == text.indexOf('(')) return null;
var regex = /\s*Inbox\s*\((\d+)\)[^\d]*/;
var res = text.match(regex);
if (res && res.length > 1) {
//console.log('res: '+ res);
return res;
} else {
return null;
}
}
@kirbysayshi

I made a fork of this and greatly simplified this. It works for me. https://gist.github.com/kirbysayshi/5356592

This script was failing if I had more than one window open, such as another message. In that case, scripts in both windows would try to set the badge count, resulting in it flickering.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.