diff options
Diffstat (limited to 'recipes/element/webview.js')
-rw-r--r-- | recipes/element/webview.js | 41 |
1 files changed, 14 insertions, 27 deletions
diff --git a/recipes/element/webview.js b/recipes/element/webview.js index 5e83ec1..ebe557f 100644 --- a/recipes/element/webview.js +++ b/recipes/element/webview.js | |||
@@ -1,38 +1,25 @@ | |||
1 | module.exports = Ferdium => { | 1 | module.exports = Ferdium => { |
2 | function getMessages() { | 2 | function getMessages() { |
3 | // const badges = document.querySelectorAll('.mx_RoomSublist:not(.mx_RoomSublist_hidden) .mx_RoomSublist_badgeContainer'); | 3 | const badges = document.querySelectorAll('.mx_RoomList .mx_RoomSublist_tiles .mx_NotificationBadge'); |
4 | const spaceBadges = document.querySelectorAll('.mx_SpacePanel_badgeContainer .mx_NotificationBadge .mx_NotificationBadge_count'); | 4 | // Number of messages from rooms which has "All Messages" notifications enabled. |
5 | const avatarBadges = document.querySelectorAll('.mx_DecoratedRoomAvatar .mx_NotificationBadge .mx_NotificationBadge_count'); | 5 | // Always incremented for private rooms by default, incremented for group chats if |
6 | // Number of messages from People / Number of messages appearing Red in the Room List | 6 | // "All Messages" is selected for them in notifications settings. |
7 | let directCount = 0; | 7 | let directCount = 0; |
8 | // Number of messages from Rooms / Number of messages appearing Grey in the Room List | 8 | // Number of messages for rooms which has "Only Highlights" notifications level set. |
9 | // Appears in rooms list with dots on right. | ||
9 | let indirectCount = 0; | 10 | let indirectCount = 0; |
10 | // Count Badges depending on Element Settings | 11 | |
11 | if (avatarBadges.length > 0) { | 12 | for (const badge of badges) { |
12 | for (const badge of avatarBadges) { | 13 | if (badge.classList.contains('mx_NotificationBadge_dot')) { |
13 | if (badge.parentElement.getAttribute('class').includes('mx_NotificationBadge_highlighted')) { | 14 | indirectCount++; |
14 | directCount = directCount + Ferdium.safeParseInt(badge.textContent); | 15 | } else { |
15 | } else if (badge.parentElement.previousSibling != null && badge.parentElement.previousSibling.getAttribute('class').includes('mx_DecoratedRoomAvatar_icon_online')) { | 16 | directCount += Ferdium.safeParseInt(badge.childNodes[0].textContent); |
16 | directCount = directCount + Ferdium.safeParseInt(badge.textContent); | ||
17 | } else if (badge.parentElement.getAttribute('class').includes('mx_NotificationBadge_dot')) { | ||
18 | indirectCount = indirectCount + 1; // there might be dragons: incrementing does not work here? | ||
19 | } else { | ||
20 | indirectCount = indirectCount + Ferdium.safeParseInt(badge.textContent); | ||
21 | } | ||
22 | } | ||
23 | } else { | ||
24 | for (const badge of spaceBadges) { | ||
25 | if (badge.parentElement.getAttribute('class').includes('mx_NotificationBadge_highlighted')) { | ||
26 | directCount = directCount + Ferdium.safeParseInt(badge.textContent); | ||
27 | } else if (badge.parentElement.getAttribute('class').includes('mx_NotificationBadge_dot')) { | ||
28 | indirectCount = indirectCount + Ferdium.safeParseInt(1); // there might be dragons: incrementing does not work here? | ||
29 | } else { | ||
30 | indirectCount = indirectCount + Ferdium.safeParseInt(badge.textContent); | ||
31 | } | ||
32 | } | 17 | } |
33 | } | 18 | } |
19 | |||
34 | // set Ferdium badge | 20 | // set Ferdium badge |
35 | Ferdium.setBadge(directCount, indirectCount); | 21 | Ferdium.setBadge(directCount, indirectCount); |
36 | } | 22 | } |
37 | Ferdium.loop(getMessages); | 23 | Ferdium.loop(getMessages); |
38 | }; | 24 | }; |
25 | |||