From 6f5e4a00588aefdda7a5a1cfe70935870e7e234a Mon Sep 17 00:00:00 2001 From: Bennett Date: Tue, 22 Sep 2020 20:56:48 +0200 Subject: Unpack recipes and update recipes icons (#292) Co-authored-by: Amine Mouafik --- recipes/redditchat/webview.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 recipes/redditchat/webview.js (limited to 'recipes/redditchat/webview.js') 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 @@ +'use strict'; + +module.exports = Franz => { + // Regular expression for (*) or (1), will extract the asterisk or the number + const titleRegEx = /^\(([\*\d])\)/; + const getMessages = function unreadCount() { + var directCount = 0; + var indirectCount = 0; + + var matchArr = document.title.match(titleRegEx); + if (matchArr) { + if (matchArr[1] === '*') { + indirectCount = 1; + } else { + directCount = Number(matchArr[1]); + } + } + + Franz.setBadge(directCount, indirectCount); + } + + Franz.loop(getMessages); +}; -- cgit v1.2.3-54-g00ecf