diff options
author | 2021-08-29 16:14:40 +0530 | |
---|---|---|
committer | 2021-08-29 16:18:17 +0530 | |
commit | 7a3d8fa7f56986e0394e93ebbcb3d0a47785d737 (patch) | |
tree | 6348dac06399ac67a935d83034e3178a4df018ac /recipes/office365-owa/webview.js | |
parent | cleanup: Remove duplicated recipes for Outlook Web App and Enterprise OWA. Fi... (diff) | |
download | ferdium-recipes-7a3d8fa7f56986e0394e93ebbcb3d0a47785d737.tar.gz ferdium-recipes-7a3d8fa7f56986e0394e93ebbcb3d0a47785d737.tar.zst ferdium-recipes-7a3d8fa7f56986e0394e93ebbcb3d0a47785d737.zip |
fix: Fix unread count in outlook (fixes #1808)
Diffstat (limited to 'recipes/office365-owa/webview.js')
-rw-r--r-- | recipes/office365-owa/webview.js | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/recipes/office365-owa/webview.js b/recipes/office365-owa/webview.js index 123158e..0309488 100644 --- a/recipes/office365-owa/webview.js +++ b/recipes/office365-owa/webview.js | |||
@@ -1,10 +1,11 @@ | |||
1 | module.exports = Ferdi => { | 1 | module.exports = Ferdi => { |
2 | function getMessages() { | 2 | function getMessages() { |
3 | let unreadMail = 0; | 3 | let directUnreadCount = 0; |
4 | let indirectUnreadCount = 0; | ||
4 | 5 | ||
5 | if (location.pathname.match(/\/owa/)) { | 6 | if (location.pathname.match(/\/owa/)) { |
6 | // classic app | 7 | // classic app |
7 | unreadMail = parseInt( | 8 | directUnreadCount = parseInt( |
8 | jQuery("span[title*='Inbox'] + div > span") | 9 | jQuery("span[title*='Inbox'] + div > span") |
9 | .first() | 10 | .first() |
10 | .text(), | 11 | .text(), |
@@ -12,21 +13,28 @@ module.exports = Ferdi => { | |||
12 | ); | 13 | ); |
13 | } else { | 14 | } else { |
14 | // new app | 15 | // new app |
15 | const favorites = document.querySelector('div[title="Favorites"]'); | 16 | const foldersElement = document.querySelector('div[role=tree]:nth-child(3)'); |
16 | if (!favorites) { | 17 | if (foldersElement) { |
17 | return; | 18 | const allScreenReaders = foldersElement.querySelectorAll('span.screenReaderOnly'); |
19 | for (const child of allScreenReaders) { | ||
20 | if ((child.innerText === 'unread' || child.innerText === 'item') && child.previousSibling) { | ||
21 | directUnreadCount += parseInt(child.previousSibling.innerText, 10); | ||
22 | } | ||
23 | } | ||
18 | } | 24 | } |
19 | const folders = Array.from(favorites.nextSibling.childNodes); | ||
20 | 25 | ||
21 | unreadMail = folders.reduce((count, child) => { | 26 | const groupsElement = document.querySelector('div[role=tree]:nth-child(4)'); |
22 | const unread = child.querySelector('.screenReaderOnly'); | 27 | if (groupsElement) { |
23 | return unread && unread.textContent === 'unread' | 28 | const allScreenReaders = groupsElement.querySelectorAll('span.screenReaderOnly'); |
24 | ? count + parseInt(unread.previousSibling.textContent, 10) | 29 | for (const child of allScreenReaders) { |
25 | : count; | 30 | if ((child.innerText === 'unread' || child.innerText === 'item') && child.previousSibling) { |
26 | }, 0); | 31 | indirectUnreadCount += parseInt(child.previousSibling.innerText, 10); |
32 | } | ||
33 | } | ||
34 | } | ||
27 | } | 35 | } |
28 | 36 | ||
29 | Ferdi.setBadge(unreadMail); | 37 | Ferdi.setBadge(directUnreadCount, indirectUnreadCount); |
30 | } | 38 | } |
31 | 39 | ||
32 | Ferdi.loop(getMessages); | 40 | Ferdi.loop(getMessages); |