diff options
author | 2021-10-16 03:40:12 +0200 | |
---|---|---|
committer | 2021-10-16 07:10:12 +0530 | |
commit | 2dcc204502ecbbcac39b667a37ffe36c45f33d6e (patch) | |
tree | 06f8bbf05d24e075967526e59bb9c82eefa25fcf /recipes | |
parent | Add new service: Netlify (#746) (diff) | |
download | ferdium-recipes-2dcc204502ecbbcac39b667a37ffe36c45f33d6e.tar.gz ferdium-recipes-2dcc204502ecbbcac39b667a37ffe36c45f33d6e.tar.zst ferdium-recipes-2dcc204502ecbbcac39b667a37ffe36c45f33d6e.zip |
mostly tested with custom homeserver, not a public matrix server
Diffstat (limited to 'recipes')
-rw-r--r-- | recipes/element/webview.js | 42 |
1 files changed, 29 insertions, 13 deletions
diff --git a/recipes/element/webview.js b/recipes/element/webview.js index 7baa623..771c758 100644 --- a/recipes/element/webview.js +++ b/recipes/element/webview.js | |||
@@ -1,22 +1,38 @@ | |||
1 | module.exports = Ferdi => { | 1 | module.exports = Ferdi => { |
2 | const getMessages = () => { | 2 | function getMessages() { |
3 | const badges = document.querySelectorAll('.mx_RoomSublist:not(.mx_RoomSublist_hidden) .mx_RoomSublist_badgeContainer'); | 3 | // const badges = document.querySelectorAll('.mx_RoomSublist:not(.mx_RoomSublist_hidden) .mx_RoomSublist_badgeContainer'); |
4 | 4 | const spaceBadges = document.querySelectorAll('.mx_SpacePanel_badgeContainer .mx_NotificationBadge .mx_NotificationBadge_count'); | |
5 | // Number of messages from People | 5 | const avatarBadges = document.querySelectorAll('.mx_DecoratedRoomAvatar .mx_NotificationBadge .mx_NotificationBadge_count'); |
6 | // Number of messages from People / Number of messages appearing Red in the Room List | ||
6 | let directCount = 0; | 7 | let directCount = 0; |
7 | if (badges.length > 0) { | 8 | // Number of messages from Rooms / Number of messages appearing Grey in the Room List |
8 | directCount = Ferdi.safeParseInt(badges[0].textContent); | ||
9 | } | ||
10 | |||
11 | // Number of messages from Rooms | ||
12 | let indirectCount = 0; | 9 | let indirectCount = 0; |
13 | if (badges.length > 1) { | 10 | // Count Badges depending on Element Settings |
14 | indirectCount = Ferdi.safeParseInt(badges[1].textContent); | 11 | if (avatarBadges.length > 0) { |
12 | avatarBadges.forEach(function(badge) { | ||
13 | if (badge.parentElement.getAttribute('class').includes('mx_NotificationBadge_highlighted')) { | ||
14 | directCount = directCount + Ferdi.safeParseInt(badge.textContent); | ||
15 | } else if (badge.parentElement.previousSibling != null && badge.parentElement.previousSibling.getAttribute('class').includes('mx_DecoratedRoomAvatar_icon_online')) { | ||
16 | directCount = directCount + Ferdi.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 + Ferdi.safeParseInt(badge.textContent); | ||
21 | } | ||
22 | }); | ||
23 | } else { | ||
24 | spaceBadges.forEach(function(badge) { | ||
25 | if (badge.parentElement.getAttribute('class').includes('mx_NotificationBadge_highlighted')) { | ||
26 | directCount = directCount + Ferdi.safeParseInt(badge.textContent); | ||
27 | } else if (badge.parentElement.getAttribute('class').includes('mx_NotificationBadge_dot')) { | ||
28 | indirectCount = indirectCount + Ferdi.safeParseInt(1); // there might be dragons: incrementing does not work here? | ||
29 | } else { | ||
30 | indirectCount = indirectCount + Ferdi.safeParseInt(badge.textContent); | ||
31 | } | ||
32 | }); | ||
15 | } | 33 | } |
16 | |||
17 | // set Ferdi badge | 34 | // set Ferdi badge |
18 | Ferdi.setBadge(directCount, indirectCount); | 35 | Ferdi.setBadge(directCount, indirectCount); |
19 | } | 36 | } |
20 | |||
21 | Ferdi.loop(getMessages); | 37 | Ferdi.loop(getMessages); |
22 | }; | 38 | }; |