diff options
author | 2021-03-05 05:34:45 -0500 | |
---|---|---|
committer | 2021-03-05 11:34:45 +0100 | |
commit | 99d1452db8112addb9d864a56a38a787286540ed (patch) | |
tree | c936b0d3148f1f031f293bb505d0eeffe9c0a993 /recipes/whatsapp/webview.js | |
parent | Add recipe for Webex Teams (#435) (diff) | |
download | ferdium-recipes-99d1452db8112addb9d864a56a38a787286540ed.tar.gz ferdium-recipes-99d1452db8112addb9d864a56a38a787286540ed.tar.zst ferdium-recipes-99d1452db8112addb9d864a56a38a787286540ed.zip |
Fix WhatsApp unread notification badge with new method (#446)
Diffstat (limited to 'recipes/whatsapp/webview.js')
-rw-r--r-- | recipes/whatsapp/webview.js | 25 |
1 files 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 () => { | |||
28 | 28 | ||
29 | module.exports = Franz => { | 29 | module.exports = Franz => { |
30 | const getMessages = function getMessages() { | 30 | const getMessages = function getMessages() { |
31 | const elements = document.querySelectorAll('._31gEB, .CxUIE, .unread, ._0LqQ, .m61XR, .ZKn2B, .VOr2j'); | ||
32 | var count = 0; | 31 | var count = 0; |
33 | var indirectCount = 0; | 32 | var indirectCount = 0; |
34 | 33 | ||
35 | for (var i = 0; i < elements.length; i += 1) { | 34 | var parentChatElem = document.querySelector("#pane-side").children[0].children[0].children[0]; |
36 | var countValue = parseInt(elements[i].textContent || '0', 10); | 35 | var chatElems = parentChatElem.children; |
37 | 36 | for (var i = 0; i < chatElems.length; i++) { | |
38 | if (elements[i].parentNode.previousElementSibling === null || elements[i].parentNode.previousElementSibling.querySelectorAll("[data-icon=muted]").length === 0) { | 37 | var chatElem = chatElems[i]; |
38 | var unreadElem = chatElem.children[0].children[0].children[1].children[1].children[1]; | ||
39 | |||
40 | var countValue = parseInt(unreadElem.textContent) || 0; // Returns 0 in case of isNaN | ||
41 | |||
42 | if (unreadElem.querySelectorAll("[data-icon=muted]").length === 0) { | ||
39 | count += countValue; | 43 | count += countValue; |
40 | } | 44 | } else { |
41 | else { | 45 | indirectCount += countValue; |
42 | indirectCount += countValue; | 46 | } |
43 | } | ||
44 | } | 47 | } |
45 | 48 | ||
46 | Franz.setBadge(count, indirectCount); | 49 | Franz.setBadge(count, indirectCount); |
47 | }; | 50 | }; |
48 | 51 | ||