aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/telegram-react/webview.js
blob: c17b2005375c0aa00e096662a707682cb14e4e59 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
module.exports = Ferdi => {
  const getMessages = () => {
    let count = 0;
    const elements = document.querySelectorAll('.chatlist > li:not(.is-muted)');
    if (elements) {
      for (const element of elements) {
        if (
          element.querySelector('.unread') &&
          element.querySelector('.unread').textContent !== 0
        ) {
          count += Ferdi.safeParseInt(
            element.querySelector('.unread').textContent,
          );
        }
      }
    }
    Ferdi.setBadge(count);
  };

  Ferdi.loop(getMessages);
};