aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/element
diff options
context:
space:
mode:
authorLibravatar Stanislav N <pztrn@pztrn.name>2022-06-27 03:11:55 +0500
committerLibravatar GitHub <noreply@github.com>2022-06-26 22:11:55 +0000
commita361fd8ca2a31382820f8904d1220d381784eb1a (patch)
tree24613be7221d98eff0890c7aab43dd3476f4bb4d /recipes/element
parentNew recipe: 'pushover' (#80) (diff)
downloadferdium-recipes-a361fd8ca2a31382820f8904d1220d381784eb1a.tar.gz
ferdium-recipes-a361fd8ca2a31382820f8904d1220d381784eb1a.tar.zst
ferdium-recipes-a361fd8ca2a31382820f8904d1220d381784eb1a.zip
Switch from counting of space-badges to room tile badges for Element (#79)
Diffstat (limited to 'recipes/element')
-rw-r--r--recipes/element/package.json2
-rw-r--r--recipes/element/webview.js41
2 files changed, 15 insertions, 28 deletions
diff --git a/recipes/element/package.json b/recipes/element/package.json
index 6f13983..58ca48d 100644
--- a/recipes/element/package.json
+++ b/recipes/element/package.json
@@ -1,7 +1,7 @@
1{ 1{
2 "id": "element", 2 "id": "element",
3 "name": "Element", 3 "name": "Element",
4 "version": "1.2.0", 4 "version": "1.3.0",
5 "license": "MIT", 5 "license": "MIT",
6 "aliases": [ 6 "aliases": [
7 "Riot.im", 7 "Riot.im",
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 @@
1module.exports = Ferdium => { 1module.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