aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/teamleader/webview.js
blob: f530549019741a926bad2c637ed35fcb6adbc8e4 (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
const _path = _interopRequireDefault(require('path'));

function _interopRequireDefault(obj) {
  return obj && obj.__esModule ? obj : { default: obj };
}

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

    const notification_element = document.querySelector(
      '#notifications_amount',
    );
    const ticket_element = document.querySelector(
      "a[href='tickets.php'] > span",
    );
    const call_element = document.querySelector('#queue_amount');

    if (notification_element) {
      notifications = Ferdium.safeParseInt(
        notification_element.getAttribute('datacount'),
      );
    }

    if (ticket_element != null) {
      indirectNotifications = Ferdium.safeParseInt(ticket_element.textContent);
    }

    if (call_element) {
      indirectNotifications += Ferdium.safeParseInt(
        call_element.getAttribute('datacount'),
      );
    }

    Ferdium.setBadge(notifications, indirectNotifications);
  };

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