aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/telegram/webview.js
blob: a2be19b23e65609538fe5fc1e24f1cbeba3891f3 (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
// 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 = function getMessages() {
    let count = 0;
    let count_sec = 0;
    const elements = document.querySelectorAll('.rp');
    for (let i = 0; i < elements.length; i += 1) {
      const subtitleBadge = elements[i].querySelector('.dialog-subtitle-badge');
      if (subtitleBadge) {
        const parsedValue = Ferdi.safeParseInt(subtitleBadge.innerText);
        if (elements[i].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'));
};