diff options
Diffstat (limited to 'recipes/office365-owa/webview.js')
-rw-r--r-- | recipes/office365-owa/webview.js | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/recipes/office365-owa/webview.js b/recipes/office365-owa/webview.js index 0ac258c..b897c8d 100644 --- a/recipes/office365-owa/webview.js +++ b/recipes/office365-owa/webview.js | |||
@@ -1,4 +1,18 @@ | |||
1 | module.exports = Ferdi => { | 1 | module.exports = (Ferdi, settings) => { |
2 | const collectCounts = (selector) => { | ||
3 | let unreadCount = 0; | ||
4 | const foldersElement = document.querySelector(selector); | ||
5 | if (foldersElement) { | ||
6 | const allScreenReaders = foldersElement.querySelectorAll('span.screenReaderOnly'); | ||
7 | for (const child of allScreenReaders) { | ||
8 | if (child.previousSibling) { | ||
9 | unreadCount += Ferdi.safeParseInt(child.previousSibling.innerText); | ||
10 | } | ||
11 | } | ||
12 | } | ||
13 | return unreadCount; | ||
14 | }; | ||
15 | |||
2 | const getMessages = () => { | 16 | const getMessages = () => { |
3 | let directUnreadCount = 0; | 17 | let directUnreadCount = 0; |
4 | let indirectUnreadCount = 0; | 18 | let indirectUnreadCount = 0; |
@@ -8,25 +22,13 @@ module.exports = Ferdi => { | |||
8 | directUnreadCount = Ferdi.safeParseInt(jQuery("span[title*='Inbox'] + div > span").first().text()); | 22 | directUnreadCount = Ferdi.safeParseInt(jQuery("span[title*='Inbox'] + div > span").first().text()); |
9 | } else { | 23 | } else { |
10 | // new app | 24 | // new app |
11 | const foldersElement = document.querySelector('div[role=tree]:nth-child(3)'); | 25 | if (settings.onlyShowFavoritesInUnreadCount === true) { |
12 | if (foldersElement) { | 26 | directUnreadCount = collectCounts('div[role=tree]:nth-child(2)'); // favorites |
13 | const allScreenReaders = foldersElement.querySelectorAll('span.screenReaderOnly'); | 27 | } else { |
14 | for (const child of allScreenReaders) { | 28 | directUnreadCount = collectCounts('div[role=tree]:nth-child(3)'); // folders |
15 | if (child.previousSibling) { | ||
16 | directUnreadCount += Ferdi.safeParseInt(child.previousSibling.innerText); | ||
17 | } | ||
18 | } | ||
19 | } | 29 | } |
20 | 30 | ||
21 | const groupsElement = document.querySelector('div[role=tree]:nth-child(4)'); | 31 | indirectUnreadCount = collectCounts('div[role=tree]:nth-child(4)'); // groups |
22 | if (groupsElement) { | ||
23 | const allScreenReaders = groupsElement.querySelectorAll('span.screenReaderOnly'); | ||
24 | for (const child of allScreenReaders) { | ||
25 | if (child.previousSibling) { | ||
26 | indirectUnreadCount += Ferdi.safeParseInt(child.previousSibling.innerText); | ||
27 | } | ||
28 | } | ||
29 | } | ||
30 | } | 32 | } |
31 | 33 | ||
32 | Ferdi.setBadge(directUnreadCount, indirectUnreadCount); | 34 | Ferdi.setBadge(directUnreadCount, indirectUnreadCount); |