Created
March 4, 2015 14:40
-
-
Save jgimenez/da69495b2ce30f96a065 to your computer and use it in GitHub Desktop.
Asana notifications for FluidApp
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
// For use with fluidapp.com (pro version) | |
// For Google Chrome/Firefox/Safari: https://greasyfork.org/en/scripts/6118-asana-notifications-favicon | |
(function() { | |
// changes the favicon. avoids setting the same favicon twice. | |
function updateFavicon(unread) { | |
if(this.lastState != unread) { // ensures we're not changing the icon all the time | |
window.fluid.dockBadge = unread ? '★' : ''; | |
this.lastState = unread; | |
} | |
} | |
// checks read count and updates favicon if necessary | |
function updateRead(title) { | |
var unread = title.indexOf("●") == 0; | |
updateFavicon(unread); | |
} | |
// observes any changes in the title and checks for the unread mark | |
function install() { | |
var titleNode = document.querySelector('head > title'); | |
this.observer = new MutationObserver(function(mutations) { | |
mutations.forEach(function(mutation) { | |
var newTitle = mutation.target.textContent; | |
updateRead(newTitle); | |
}); | |
}); | |
observer.observe(titleNode, { subtree: true, characterData: true, childList: true }); // options counter-intuitive to me, but are required, not too expensive | |
updateRead(document.title); // make sure it's up to date before first event | |
} | |
install(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how to use it?