aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/telegram/webview.js
blob: 7d2c8e3b1c31af9f624f5bc28b9d717818db9cb5 (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
42
43
// 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 direct = 0;
    let indirect = 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) {
          direct += parsedValue;
        } else {
          indirect += parsedValue;
        }
      }
    }

    Ferdi.setBadge(direct, indirect);
  };

  const getActiveDialogTitle = () => {
    const element = document.querySelector('.top .peer-title');

    Ferdi.setDialogTitle(element ? element.textContent : '');
  };

  const loopFunc = () => {
    getMessages();
    getActiveDialogTitle();
  };

  Ferdi.loop(loopFunc);

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