aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/chatwork/webview.js
blob: 48a3fbf61d3cab6a8a1253eb5e0f49d6ede68f74 (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
35
36
37
38
'use strict';

module.exports = (Franz, options) => {
  function getMessages() {
    let groupCount = 0;
    let individualCount = 0;
    let directCount = 0;
    let indirectCount = 0;
    let roomInfoContainer = document.querySelectorAll('li.sc-dnqmqq');
    Array.prototype.forEach.call(roomInfoContainer, function (room) {
      let count = 0;
      let unreadBadge = room.querySelector("span.sc-kAzzGY");
      let unreadBadgeHasMention = room.querySelector("li._unreadBadge.sc-cSHVUG");

      if (unreadBadge && unreadBadge.innerText) {
        count = parseInt(unreadBadge.innerText);
      }

      if (0 < count) {
        if (room.querySelector("img.sc-gqjmRU").getAttribute('src').indexOf('avatar') < 0) {
          groupCount += count;

          if (unreadBadgeHasMention) {
            directCount++;
          } else {
            indirectCount++;
          }
        } else {
          individualCount += count;
          directCount++;
        }
      }
    });
    Franz.setBadge(directCount, indirectCount);
  }

  Franz.loop(getMessages);
};