Skip to content

Commit

Permalink
fix: gmail notifications doubled
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeDabrowski committed Jan 26, 2024
1 parent 4d8bf13 commit 2b0b77a
Showing 1 changed file with 6 additions and 39 deletions.
45 changes: 6 additions & 39 deletions recipes/gmail/webview.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 2b0b77a

Please sign in to comment.