blob: 96136365a8da8630f380813735f6bde45014942c (
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
|
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);
};
|