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

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

module.exports = Ferdium => {
  let latestStatement = $('.status time').attr('datetime');
  let latestNotify = $($('.notification__message span').get(0)).text();

  $($('div.column div.scrollable').get(0)).on('scroll', () => {
    latestStatement = $('.status time').attr('datetime');
  });
  $($('div.column div.scrollable').get(1)).on('scroll', () => {
    latestNotify = $($('.notification__message span').get(0)).text();
  });

  const getMessages = () => {
    let reply = 0;
    const ln = $($('.notification__message span').get(0)).text();
    if (ln !== latestNotify) {
      reply = 1;
    }
    let unread = 0;
    const ls = $('.status time').attr('datetime');
    if (ls !== latestStatement) {
      unread = 1;
    }

    Ferdium.setBadge(reply, unread);
  };

  Ferdium.loop(getMessages);

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