aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/telegram/webview.js
blob: 358bdaaf64f19fbdf17792ac14ea057462362292 (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
// Code copied from: https://gitlab.com/gortega4/ferdi_recipes

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

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

module.exports = Ferdi => {
  const getMessages = () => {
    let count = 0;
    let count_sec = 0;
    const elements = document.querySelectorAll('.rp');
    for (const element of elements) {
      const subtitleBadge = element.querySelector('.dialog-subtitle-badge');
      if (subtitleBadge) {
        const parsedValue = Ferdi.safeParseInt(subtitleBadge.textContent);
        if (element.dataset.peerId > 0) {
          count += parsedValue;
        } else {
          count_sec += parsedValue;
        }
      }
    }

    Ferdi.setBadge(count, count_sec);
  };

  Ferdi.loop(getMessages);

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