aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/outlook/webview.js
blob: 123158ea462f5571f359f76e66453512bf02f3a9 (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
27
28
29
30
31
32
33
module.exports = Ferdi => {
  function getMessages() {
    let unreadMail = 0;

    if (location.pathname.match(/\/owa/)) {
      // classic app
      unreadMail = parseInt(
        jQuery("span[title*='Inbox'] + div > span")
          .first()
          .text(),
        10,
      );
    } else {
      // new app
      const favorites = document.querySelector('div[title="Favorites"]');
      if (!favorites) {
        return;
      }
      const folders = Array.from(favorites.nextSibling.childNodes);

      unreadMail = folders.reduce((count, child) => {
        const unread = child.querySelector('.screenReaderOnly');
        return unread && unread.textContent === 'unread'
          ? count + parseInt(unread.previousSibling.textContent, 10)
          : count;
      }, 0);
    }

    Ferdi.setBadge(unreadMail);
  }

  Ferdi.loop(getMessages);
};