aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/rainloop/webview.js
blob: 6b0c3d6e4c6494d19324866323e87ec7de032190 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
module.exports = Ferdium => {
  const getMessages = () => {
    let messages = 0;

    // Let's only loop through user folders, as all system folders are duplicated there
    for (const obj of document.querySelectorAll('.b-folders-user .ui-droppable')) {
      const countEl = obj.querySelector('.count');
      const countText = countEl ? countEl.innerHTML : '';

      if (countText != '') {
        if (obj.classList.contains('system')) {
          // Only count the Inbox system folder and ignore Archive, Trash, Drafts, Spam, Sent
          if (obj.classList.contains('i-am-inbox')) {
            messages += Ferdium.safeParseInt(countText);
          }
        } else {
          messages += Ferdium.safeParseInt(countText);
        }
      }
    }

    Ferdium.setBadge(messages);
  };

  Ferdium.loop(getMessages);
};