From 99d1452db8112addb9d864a56a38a787286540ed Mon Sep 17 00:00:00 2001 From: Boro Vukovic Date: Fri, 5 Mar 2021 05:34:45 -0500 Subject: Fix WhatsApp unread notification badge with new method (#446) --- recipes/whatsapp/webview.js | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/recipes/whatsapp/webview.js b/recipes/whatsapp/webview.js index 26839d3..169b54c 100644 --- a/recipes/whatsapp/webview.js +++ b/recipes/whatsapp/webview.js @@ -28,21 +28,24 @@ window.addEventListener('beforeunload', async () => { module.exports = Franz => { const getMessages = function getMessages() { - const elements = document.querySelectorAll('._31gEB, .CxUIE, .unread, ._0LqQ, .m61XR, .ZKn2B, .VOr2j'); var count = 0; - var indirectCount = 0; + var indirectCount = 0; - for (var i = 0; i < elements.length; i += 1) { - var countValue = parseInt(elements[i].textContent || '0', 10); - - if (elements[i].parentNode.previousElementSibling === null || elements[i].parentNode.previousElementSibling.querySelectorAll("[data-icon=muted]").length === 0) { + var parentChatElem = document.querySelector("#pane-side").children[0].children[0].children[0]; + var chatElems = parentChatElem.children; + for (var i = 0; i < chatElems.length; i++) { + var chatElem = chatElems[i]; + var unreadElem = chatElem.children[0].children[0].children[1].children[1].children[1]; + + var countValue = parseInt(unreadElem.textContent) || 0; // Returns 0 in case of isNaN + + if (unreadElem.querySelectorAll("[data-icon=muted]").length === 0) { count += countValue; - } - else { - indirectCount += countValue; - } + } else { + indirectCount += countValue; + } } - + Franz.setBadge(count, indirectCount); }; -- cgit v1.2.3-70-g09d2