aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/kimaicloud/webview.js
blob: 90ff71089ee34b156bfce32f95d8c14930b36f7c (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
function _interopRequireDefault(obj) {
  return obj && obj.__esModule ? obj : { default: obj };
}

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

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

    // get amount of running timesheets
    const label = document.querySelector(
      '.main-header .navbar .dropdown.messages-menu .ticktac span.label',
    );
    if (label !== undefined) {
      count = Ferdium.safeParseInt(label.textContent);
    }

    // set Ferdium badge
    Ferdium.setBadge(count);
  };

  document.addEventListener('click', e => {
    const { tagName, target, href } = e.target;

    if (tagName === 'A' && target === '_blank') {
      e.preventDefault();
      e.stopImmediatePropagation();
      window.open(href);
    }
  });

  Ferdium.loop(getMessages);

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