aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/twitter/webview.js
blob: d88e3e4976946e394f4ea250f7721f467cf654e9 (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
module.exports = Ferdi => {
  const getMessages = () => {
    let direct = 0;

    // "Notifications" and "Messages" - aria-label ending in
    // "unread items". Sum the values for direct badge.
    const notificationsElement = document.querySelector(
      '[data-testid=AppTabBar_Notifications_Link] div div div',
    );
    if (notificationsElement) {
      direct += Ferdi.safeParseInt(notificationsElement.textContent);
    }
    const DMElement = document.querySelector(
      '[data-testid=AppTabBar_DirectMessage_Link] div div div',
    );
    if (DMElement) {
      direct += Ferdi.safeParseInt(DMElement.textContent);
    }

    Ferdi.setBadge(direct);
  };

  Ferdi.loop(getMessages);
};