-
Notifications
You must be signed in to change notification settings - Fork 1
/
fastmail-beta.js
65 lines (54 loc) · 1.82 KB
/
fastmail-beta.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
Fluid App Userscript
FastMail web interface
URL pattern: *fastmail.com/mail/*
*/
setTimeout(updateDockBadge, 3000);
setInterval(updateDockBadge, 10000);
INBOX_ONLY = false;
FILTERED = [ "Drafts", "Trash", "Spam" ];
function updateDockBadge()
{
var count = 0;
var tree = document.getElementsByClassName("v-FolderTree")[0];
if (!tree)
return;
for (i = 0; i < tree.childNodes.length; i++)
{
name = tree.childNodes[i].getElementsByClassName("v-FolderSource-name")[0].innerText;
badge = tree.childNodes[i].getElementsByClassName("v-FolderSource-badge")[0].innerText;
// console.log("name: " + name + ", badge: " + badge);
if (badge)
{
if (! INBOX_ONLY || name == "Inbox")
{
if (FILTERED.indexOf(name) == -1)
{
count += parseInt(badge);
} else {
// console.log("filtered: " + name);
}
}
}
}
// console.log("new count: " + count + ", current count: " + window.fluid.dockBadge);
if (count > window.fluid.dockBadge)
{
notification = {
title: "FastMail",
description: "You have " + count + " unread message" + ((count > 1) ? "s" : ""),
priority: 1,
sticky: false,
identifier: "fastmail",
icon: window.fluid.resourcePath + "appl.icns",
// icon: "https://www.fastmail.com/static/favicons/touch-icon-196x196.png",
};
// window.fluid.showGrowlNotification(notification);
window.fluid.showUserNotification(notification);
window.fluid.dockBadge = count;
} else if (count > 0) {
window.fluid.dockBadge = count;
} else {
window.fluid.dockBadge = "";
}
}