aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/hey/webview.js
blob: 67e87d49a0b8016d2149cd87badca5b5af3021b1 (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
34
module.exports = Ferdi => {
  const getMessages = () => {
    if (document.location.href == 'https://app.hey.com/') {
      let screener = 0;
      let unread = 0;

      if (document.querySelectorAll('.btn--icon-screener').length > 0) {
        let text = document.querySelectorAll('.btn--icon-screener')[0]
          .textContent;
        if (text) {
          const parsedText = Ferdi.safeParseInt(/\d+/.exec(text));
          screener = parsedText[0];
        }
      }

      let postings = document.querySelectorAll('.posting');

      if (postings.length > 0) {
        for (const p of postings) {
          if (
            p.nodeName == 'ARTICLE' &&
            p.getAttribute('data-seen') !== 'true'
          ) {
            unread++;
          }
        }
      }

      Ferdi.setBadge(unread, screener);
    }
  };

  Ferdi.loop(getMessages);
};