From 2b0b77ab13f457b51cb0f3dc5602ffea1abc6801 Mon Sep 17 00:00:00 2001 From: MikeDabrowski Date: Fri, 26 Jan 2024 07:42:19 +0000 Subject: [PATCH] fix: gmail notifications doubled --- recipes/gmail/webview.js | 45 ++++++---------------------------------- 1 file changed, 6 insertions(+), 39 deletions(-) diff --git a/recipes/gmail/webview.js b/recipes/gmail/webview.js index bfa2e0668..78a681919 100644 --- a/recipes/gmail/webview.js +++ b/recipes/gmail/webview.js @@ -15,47 +15,14 @@ module.exports = Ferdium => { } const getMessages = () => { - let countImportant = 0; - let countNonImportant = 0; - const inboxLinks = document.querySelectorAll('.J-Ke.n0'); - const spaceAndChatBadges = document.querySelectorAll( - 'div.Xa.bSyoAf span.XU', - ); - - if (inboxLinks.length > 0) { - const { parentNode } = inboxLinks[0]; - if (parentNode) { - const parentNodeOfParentNode = parentNode.parentNode; - if (parentNodeOfParentNode) { - const unreadCounts = parentNodeOfParentNode.querySelectorAll('.bsU'); - if (unreadCounts.length > 0) { - const unreadCount = unreadCounts[0].textContent; - if (unreadCount.includes(':')) { - const counts = unreadCount - .split(':') - .map(s => Ferdium.safeParseInt(s.replaceAll(/[^\p{N}]/gu, ''))); - countImportant = counts[0]; - countNonImportant = counts[1] - counts[0]; - } else { - countImportant = Ferdium.safeParseInt( - unreadCount.replaceAll(/[^\p{N}]/gu, ''), - ); - } - } - } - } - } + const mailChatMeetBadges = document.querySelectorAll('span.XU.aH6'); - if (spaceAndChatBadges.length > 0) { - const arr = [...spaceAndChatBadges]; - const spaceAndChatCount = arr.reduce( - (acc, e) => Ferdium.safeParseInt(e.getInnerHTML()) + acc, - 0, - ); - countImportant += spaceAndChatCount; - } + const mailChatMeetCounts = [...mailChatMeetBadges].reduce( + (acc, e) => Ferdium.safeParseInt(e.getInnerHTML()) + acc, + 0, + ); - Ferdium.setBadge(countImportant, countNonImportant); + Ferdium.setBadge(mailChatMeetCounts); }; Ferdium.loop(getMessages);