aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/yammer/webview.js
blob: d3a94da6fa4f3d53e03f35892728bcbdbf911c60 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
module.exports = Ferdi => {
  const getMessages = () => {
    let directMessages = 0;
    let indirectMessages = 0;
    const notificationElement = document.querySelector('.yj-notifications-indicator-count');
    const newMessagesElement = document.querySelector('.yj-thread-list--new-messages-notice:not(.is-hidden) .yj-thread-list--new-message-text');

    if (notificationElement) {
      directMessages = Ferdi.safeParseInt(notificationElement.innerHTML);
    }

    if (newMessagesElement) {
      indirectMessages = Ferdi.safeParseInt(newMessagesElement.innerHTML.match(/\d+/)[0]);
    }

    Ferdi.setBadge(directMessages, indirectMessages);
  };

  Ferdi.loop(getMessages);
};