diff options
author | beerpsi <92439990+beerpiss@users.noreply.github.com> | 2022-10-17 19:46:23 +0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-17 13:46:23 +0100 |
commit | 78d581191ef89e81dca73d34ad16115a6b9314fc (patch) | |
tree | 6c0547f953761b505e08164928f9d4235c4876f1 /recipes/messenger/webview.js | |
parent | add jkischel as a contributor for code (#203) [skip ci] (diff) | |
download | ferdium-recipes-78d581191ef89e81dca73d34ad16115a6b9314fc.tar.gz ferdium-recipes-78d581191ef89e81dca73d34ad16115a6b9314fc.tar.zst ferdium-recipes-78d581191ef89e81dca73d34ad16115a6b9314fc.zip |
Fix getting badge count on messenger (#145)
* Simplify getting badge count
* Increment version
* add fallback for badge count and fix style
* fix boolean comparison
Co-authored-by: Alphrag <34252790+Alphrag@users.noreply.github.com>
Diffstat (limited to 'recipes/messenger/webview.js')
-rw-r--r-- | recipes/messenger/webview.js | 48 |
1 files changed, 32 insertions, 16 deletions
diff --git a/recipes/messenger/webview.js b/recipes/messenger/webview.js index f7bc85b..7fc8ed6 100644 --- a/recipes/messenger/webview.js +++ b/recipes/messenger/webview.js | |||
@@ -10,27 +10,43 @@ function hideInstallMessage() { | |||
10 | 10 | ||
11 | module.exports = Ferdium => { | 11 | module.exports = Ferdium => { |
12 | const getMessages = () => { | 12 | const getMessages = () => { |
13 | /*let count = [...document.querySelectorAll('.bp9cbjyn.j83agx80.owycx6da:not(.btwxx1t3)')] | ||
14 | .map(elem => { | ||
15 | const hasPing = !!elem.querySelector('.pq6dq46d.is6700om.qu0x051f.esr5mh6w.e9989ue4.r7d6kgcz.s45kfl79.emlxlaya.bkmhp75w.spb7xbtv.cyypbtt7.fwizqjfa'); | ||
16 | const isMuted = !!elem.querySelector('.a8c37x1j.ms05siws.l3qrxjdp.b7h9ocf4.trssfv1o'); | ||
17 | |||
18 | return hasPing && !isMuted; | ||
19 | }) | ||
20 | .reduce((prev, curr) => prev + curr, 0);*/ | ||
21 | let count = 0; | 13 | let count = 0; |
22 | for (const node of document.querySelectorAll( | 14 | let newMessengerUI = false; |
23 | '[data-testid="mwthreadlist-item"]', | 15 | |
24 | )) { | 16 | /* |
25 | if (node.querySelector('.lrazzd5p, .is6700om, .o48pnaf2')) count += 1; | 17 | * try the counting with the new UI |
18 | */ | ||
19 | for (let href of ['/', '/requests/', '/marketplace/']) { | ||
20 | const elem = document.querySelector(`a[href^='${href}t/'][role='link'][tabindex='0']`).ariaLabel; | ||
21 | if (elem) { | ||
22 | newMessengerUI = true; | ||
23 | const match = elem.match(/(\d+)/g); | ||
24 | if (match) { | ||
25 | count += Ferdium.safeParseInt(match[0]); | ||
26 | } | ||
27 | } | ||
26 | } | 28 | } |
27 | 29 | ||
28 | /* | 30 | /* |
29 | * add count of message requests on top of notification counter | 31 | * do the old counting if the interface is not the last one |
30 | */ | 32 | */ |
31 | const messageRequestsElement = document.querySelector('._5nxf'); | 33 | if (!newMessengerUI) { |
32 | if (messageRequestsElement) { | 34 | count = [...document.querySelectorAll('.bp9cbjyn.j83agx80.owycx6da:not(.btwxx1t3)')] |
33 | count += Ferdium.safeParseInt(messageRequestsElement.textContent); | 35 | .map(elem => { |
36 | const hasPing = !!elem.querySelector('.pq6dq46d.is6700om.qu0x051f.esr5mh6w.e9989ue4.r7d6kgcz.s45kfl79.emlxlaya.bkmhp75w.spb7xbtv.cyypbtt7.fwizqjfa'); | ||
37 | const isMuted = !!elem.querySelector('.a8c37x1j.ms05siws.l3qrxjdp.b7h9ocf4.trssfv1o'); | ||
38 | |||
39 | return hasPing && !isMuted; | ||
40 | }) | ||
41 | .reduce((prev, curr) => prev + curr, 0); | ||
42 | |||
43 | /* | ||
44 | * add count of message requests on top of notification counter | ||
45 | */ | ||
46 | const messageRequestsElement = document.querySelector('._5nxf'); | ||
47 | if (messageRequestsElement) { | ||
48 | count += Ferdium.safeParseInt(messageRequestsElement.textContent); | ||
49 | } | ||
34 | } | 50 | } |
35 | 51 | ||
36 | Ferdium.setBadge(count); | 52 | Ferdium.setBadge(count); |