aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/element/webview.js
blob: 18bb7ada8cec35dbda70743f11db6ea6bfdb98ab (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
module.exports = Ferdi => {
  function getMessages() {
    const badges = document.querySelectorAll('.mx_RoomSublist:not(.mx_RoomSublist_hidden) .mx_RoomSublist_badgeContainer');

    // Number of messages from People
    let direct_count = 0;
    if (badges.length > 0 && badges[0].children.length > 0) {
      direct_count = parseInt(badges[0].textContent);
    }

    // Number of messages from Rooms
    let indirect_count = 0;
    if (badges.length > 1 && badges[1].children.length > 0) {
      indirect_count = parseInt(badges[1].textContent);
    }

    // set Ferdi badge
    Ferdi.setBadge(direct_count, indirect_count);
  }

  Ferdi.loop(getMessages);
};