aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/redditchat/webview.js
blob: 8b29861be80a8c73ace87c451fa083b8bb990d05 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
module.exports = Franz => {
  // Regular expression for (*) or (1), will extract the asterisk or the number
  const titleRegEx = /^\(([\*\d])\)/;
  const getMessages = function unreadCount() {
    let directCount = 0;
    let indirectCount = 0;

    const matchArr = document.title.match(titleRegEx);
    if (matchArr) {
      if (matchArr[1] === '*') {
        indirectCount = 1;
      } else {
        directCount = Number(matchArr[1]);
      }
    }

    Franz.setBadge(directCount, indirectCount);
  };

  Franz.loop(getMessages);
};