blob: 70790f06d18bb44cb243cbe5091e72e2e9b7ff1e (
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
|
module.exports = (Ferdium, settings) => {
const collectCounts = selector => {
let unreadCount = 0;
const foldersElement = document.querySelector(selector);
if (foldersElement) {
const allScreenReaders = foldersElement.querySelectorAll(
'span.screenReaderOnly',
);
for (const child of allScreenReaders) {
if (child.previousSibling) {
unreadCount += Ferdium.safeParseInt(child.previousSibling.textContent);
}
}
}
return unreadCount;
};
const getMessages = () => {
let directUnreadCount = 0;
let indirectUnreadCount = 0;
if (/\/owa/.test(location.pathname)) {
// classic app
directUnreadCount = Ferdium.safeParseInt(
document.querySelectorAll("span[title*='Inbox'] + div > span")[0]
.textContent,
);
} else {
// new app
directUnreadCount =
settings.onlyShowFavoritesInUnreadCount === true
? collectCounts('div[role=tree]:nth-child(2)')
: collectCounts('div[role=tree]:nth-child(3)');
indirectUnreadCount = collectCounts('div[role=tree]:nth-child(4)'); // groups
}
Ferdium.setBadge(directUnreadCount, indirectUnreadCount);
};
Ferdium.loop(getMessages);
};
|