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/chatwork/webview.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 recipes/chatwork/webview.js (limited to 'recipes/chatwork/webview.js') diff --git a/recipes/chatwork/webview.js b/recipes/chatwork/webview.js new file mode 100644 index 0000000..48a3fbf --- /dev/null +++ b/recipes/chatwork/webview.js @@ -0,0 +1,38 @@ +'use strict'; + +module.exports = (Franz, options) => { + function getMessages() { + let groupCount = 0; + let individualCount = 0; + let directCount = 0; + let indirectCount = 0; + let roomInfoContainer = document.querySelectorAll('li.sc-dnqmqq'); + Array.prototype.forEach.call(roomInfoContainer, function (room) { + let count = 0; + let unreadBadge = room.querySelector("span.sc-kAzzGY"); + let unreadBadgeHasMention = room.querySelector("li._unreadBadge.sc-cSHVUG"); + + if (unreadBadge && unreadBadge.innerText) { + count = parseInt(unreadBadge.innerText); + } + + if (0 < count) { + if (room.querySelector("img.sc-gqjmRU").getAttribute('src').indexOf('avatar') < 0) { + groupCount += count; + + if (unreadBadgeHasMention) { + directCount++; + } else { + indirectCount++; + } + } else { + individualCount += count; + directCount++; + } + } + }); + Franz.setBadge(directCount, indirectCount); + } + + Franz.loop(getMessages); +}; \ No newline at end of file -- cgit v1.2.3-54-g00ecf