diff options
Diffstat (limited to 'recipes/redditchat/webview.js')
-rw-r--r-- | recipes/redditchat/webview.js | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/recipes/redditchat/webview.js b/recipes/redditchat/webview.js new file mode 100644 index 0000000..7e209da --- /dev/null +++ b/recipes/redditchat/webview.js | |||
@@ -0,0 +1,23 @@ | |||
1 | 'use strict'; | ||
2 | |||
3 | module.exports = Franz => { | ||
4 | // Regular expression for (*) or (1), will extract the asterisk or the number | ||
5 | const titleRegEx = /^\(([\*\d])\)/; | ||
6 | const getMessages = function unreadCount() { | ||
7 | var directCount = 0; | ||
8 | var indirectCount = 0; | ||
9 | |||
10 | var matchArr = document.title.match(titleRegEx); | ||
11 | if (matchArr) { | ||
12 | if (matchArr[1] === '*') { | ||
13 | indirectCount = 1; | ||
14 | } else { | ||
15 | directCount = Number(matchArr[1]); | ||
16 | } | ||
17 | } | ||
18 | |||
19 | Franz.setBadge(directCount, indirectCount); | ||
20 | } | ||
21 | |||
22 | Franz.loop(getMessages); | ||
23 | }; | ||