Created
March 10, 2018 15:37
-
-
Save vitalybe/c628824855f94da6381a0f6903da0dc3 to your computer and use it in GitHub Desktop.
"Remember the Milk" Fluid app script for bouncing icons and badge
This file contains hidden or 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
function findClassNames() { | |
var results = [].slice.call(document.querySelectorAll("div")).filter(function(o) {return o.innerText == "_Helper_"}); | |
if(results.length == 1) { | |
nameNode = results[0]; | |
nameClass = nameNode.classList[0] | |
countNode = [].slice.call(nameNode.parentNode.querySelectorAll("div")).filter(function(o) {return o.innerText == "1"})[0] | |
countClass = countNode.classList[0] | |
return { | |
nameClass: "." + nameClass, | |
countClass: "." + countClass | |
} | |
} else { | |
alert("Failed to find helper list"); | |
} | |
} | |
var TARGET_LIST = "Now" | |
var LONG_WAIT = 10000; | |
var SHORT_WAIT = 10000; | |
var CLASS_LIST_NAME = null | |
var CLASS_LIST_COUNT = null | |
window.fluid.dockBadge = ''; | |
setTimeout(updateDockBadge, LONG_WAIT); | |
function updateDockBadge() { | |
if(!CLASS_LIST_NAME) { | |
var names = findClassNames() | |
CLASS_LIST_NAME = names["nameClass"]; | |
CLASS_LIST_COUNT = names["countClass"]; | |
} | |
try { | |
var newBadge = ''; | |
var listNameNodes = [].slice.call(document.querySelectorAll(CLASS_LIST_NAME)) | |
var nowNode = listNameNodes.filter(function(node) { return node.outerText == TARGET_LIST })[0] | |
var countNode = nowNode.parentNode.querySelector(CLASS_LIST_COUNT) | |
window.fluid.dockBadge = countNode.outerText; | |
if(countNode.outerText) { | |
window.fluid.requestUserAttention(); | |
setTimeout(updateDockBadge, SHORT_WAIT); | |
} else { | |
setTimeout(updateDockBadge, LONG_WAIT); | |
} | |
} catch(err) { | |
alert("Failed to show badge: " + err) | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment