aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/zalo/webview.js
blob: 3c432a661552badb568bf1f01c25a8196f11c026 (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
function _interopRequireDefault(obj) {
  return obj && obj.__esModule ? obj : { default: obj };
}

const _path = _interopRequireDefault(require('path'));

module.exports = Ferdium => {
  const getMessages = () => {
    let count = 0;

    const unreadRed = document.querySelector('.unread-red');
    if (unreadRed !== null) {
      switch (unreadRed.classList[1]) {
        case 'fa-num1': {
          count = 1;
          break;
        }
        case 'fa-num2': {
          count = 2;
          break;
        }
        case 'fa-num3': {
          count = 3;
          break;
        }
        case 'fa-num4': {
          count = 4;
          break;
        }
        case 'fa-num5': {
          count = 5;
          break;
        }
        default: {
          // fa-num5plus
          const convUnread = document.querySelectorAll(
            '.conv-unread:not(.func-unread__muted)',
          );
          if (convUnread.length === 0) count = 6; // 5+
          else
            for (const convUnreadItem of convUnread) {
              switch (convUnreadItem.classList[1]) {
                case 'fa-1_24_Line': {
                  count += 1;
                  break;
                }
                case 'fa-2_24_Line': {
                  count += 2;
                  break;
                }
                case 'fa-3_24_Line': {
                  count += 3;
                  break;
                }
                case 'fa-4_24_Line': {
                  count += 4;
                  break;
                }
                case 'fa-5_24_Line': {
                  count += 5;
                  break;
                }
                default: {
                  // fa-5plus_24_Line
                  count += 6;
                }
              }
            }
        }
      }
    }
    Ferdium.setBadge(count);
  };
  Ferdium.loop(getMessages);

  Ferdium.injectCSS(_path.default.join(__dirname, 'service.css'));
};