blob: 7d906155bc1ebcc129d7ea0bbd91dbd5d5416561 (
plain) (
blame)
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
|
"use strict";
module.exports = Ferdium => {
const _notificationCategory = new URL(window.location.href).searchParams.get("ferdiumNotificationCategory");
const getMessages = function getMessages() {
if (_notificationCategory) {
countMessagesUnderCategory(_notificationCategory);
} else {
countMessages();
}
};
const countMessagesUnderCategory = (notificationCategory) => {
var elements = document.querySelectorAll(".dijitTreeIsRoot")
var directMessages = 0;
var indirectMessages = 0;
for (var element of elements) {
var label = element.querySelectorAll(".dijitTreeLabel")[0];
var unreadNode = element.querySelectorAll(".unread")[0];
var unreadAmount = Ferdium.safeParseInt(unreadNode.textContent);
if (label.textContent === notificationCategory) {
directMessages += unreadAmount;
} else {
indirectMessages += unreadAmount;
}
}
Ferdium.setBadge(directMessages, indirectMessages);
};
const _countMessagesFromTitle = () => {
var match = document.title.match(/^\((\d+)\) Tiny Tiny RSS$/);
var count = match != null && match.length > 0 ? match[1] : 0;
return Ferdium.safeParseInt(count);
}
const countMessages = () => {
Ferdium.setBadge(_countMessagesFromTitle());
};
const loopFunc = () => {
getMessages();
};
Ferdium.loop(loopFunc);
};
|