-
-
Save johanoloflindberg/4c28adfe8bf21abc4124 to your computer and use it in GitHub Desktop.
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment