aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/kimai-cloud/webview.js
blob: 8baf00864999cc75d3bda2797de36eff7e92bfa7 (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
module.exports = (Franz) => {
  const getMessages = function getMessages() {
    let count = 0;

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

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

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

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

  // check for new messages every second and update Franz badge
  Franz.loop(getMessages);
};