meetfranz / recipe-whatsapp

Official Franz Recipe for WhatsApp
6 stars 25 forks source link

Identify unread messages with more reability #17

Open JCKodel opened 3 years ago

JCKodel commented 3 years ago

Change way of determining unread badges from Whatsapp.

Whatsapp uses generated class names, so very often they change and then the recipe stops working.

What I did was to find all spans with aria-label attribute (there are 3 of them: the "your phone is low on battery" close button, the "mark as unread" badge (the badge without a counter) and the threads with unread counters.

The difference between those spans is that only the unread badges has background-color: var(--unread-marker-background);.

I could not find a way to read the var(--unread-marker-background) from JS, so I get the color from both light and dark theme and using them to find the unread badges.

Finally, I try to parse the contents of the badge (for example: in portuguese, when a badge have (1), the aria-label is "1 mensagem não lida").

So I add that parse + 1 for each "marked as unread" (which have no counter nor aria-label content) and voi-la. A reliable counter that don't depend on Whatsapp class names anymore.

speakthinker commented 3 years ago

Thanks for the solutions Actually worked for me and the notifications are back. (First comment ever here on Git, but thought to leave a small thank you message here.)

JCKodel commented 3 years ago

Added fix for full width on thread list and status list.