Last active
July 9, 2020 10:42
-
-
Save itod/3808583 to your computer and use it in GitHub Desktop.
Gmail Fluid App Userscript
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
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; | |
} | |
} |
Could not get your versions working, mine is just a few lines at https://gist.github.com/tordans/85cbaa856b93b52e9a1465004569218e
FYI, this is no longer necessary with Version 2+ of the Fluid app.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.