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

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

module.exports = Ferdium => {
  const getMessages = () => {
    // get unread messages
    let directCount = 0;
    for (const node of document.querySelectorAll('div.unread-indicator')) {
      directCount += Ferdium.safeParseInt(node.textContent);
    }

    const channelMentionCount =
      document.querySelectorAll('.mention-indicator').length;

    // set Ferdium badge
    Ferdium.setBadge(directCount, channelMentionCount);
  };

  Ferdium.loop(getMessages);

  // Hide download message
  Ferdium.injectCSS(_path.default.join(__dirname, 'service.css'));
};