Skip to content

Instantly share code, notes, and snippets.

@chroder
Created February 1, 2014 16:54
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chroder/8755101 to your computer and use it in GitHub Desktop.
Save chroder/8755101 to your computer and use it in GitHub Desktop.
/*
Fluid App Userscript
FastMail web interface
URL pattern: *fastmail.fm/mail/*
*/
setTimeout(updateDockBadge, 3000);
setInterval(updateDockBadge, 5000);
INBOX_ONLY = true;
FILTERED = [ "Drafts", "Trash", "Spam" ];
function updateDockBadge() {
var count = 0;
var tree = document.getElementsByClassName("FolderTree")[0];
for (i = 0; i < tree.childNodes.length; i++) {
name = tree.childNodes[i].getElementsByClassName("name")[0].innerText;
badge = tree.childNodes[i].getElementsByClassName("badge")[0].innerText;
if (badge) {
if (!INBOX_ONLY || name == "Inbox") {
if (FILTERED.indexOf(name) == -1) {
count += parseInt(badge);
}
}
}
}
if (count > window.fluid.dockBadge) {
notification = {
title: "FastMail",
description: "You have " + count + " unread message(s)",
priority: 1,
sticky: false,
identifier: "fastmail",
icon: window.fluid.resourcePath + 'app.icns'
};
window.fluid.showGrowlNotification(notification);
window.fluid.dockBadge = count;
} else if (count > 0) {
window.fluid.dockBadge = count;
} else {
window.fluid.dockBadge = "";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment