From 88b09033d1ecd84ef77f7ba1297fbfd6f884fc96 Mon Sep 17 00:00:00 2001 From: Bernhard Date: Tue, 7 Jun 2022 13:58:02 +0200 Subject: [Gmail] Add support for priority inbox --- recipes/gmail/package.json | 2 +- recipes/gmail/webview.js | 21 +++++++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) (limited to 'recipes') diff --git a/recipes/gmail/package.json b/recipes/gmail/package.json index dfbb834..518f856 100644 --- a/recipes/gmail/package.json +++ b/recipes/gmail/package.json @@ -1,7 +1,7 @@ { "id": "gmail", "name": "Gmail", - "version": "1.5.0", + "version": "1.5.1", "license": "MIT", "config": { "serviceURL": "https://mail.google.com" diff --git a/recipes/gmail/webview.js b/recipes/gmail/webview.js index be22b66..fb8cf76 100644 --- a/recipes/gmail/webview.js +++ b/recipes/gmail/webview.js @@ -15,8 +15,8 @@ module.exports = Ferdium => { } const getMessages = () => { - let count = 0; - + let countImportant = 0; + let countNonImportant = 0; const inboxLinks = document.querySelectorAll('.J-Ke.n0'); if (inboxLinks.length > 0) { let parentNode = inboxLinks[0].parentNode; @@ -25,14 +25,23 @@ module.exports = Ferdium => { if (parentNodeOfParentNode) { const unreadCounts = parentNodeOfParentNode.querySelectorAll('.bsU'); if (unreadCounts.length > 0) { - count = Ferdium.safeParseInt(unreadCounts[0].textContent.replace(/[^\p{N}]/gu, '')); + let unreadCount = unreadCounts[0].textContent; + if (unreadCount.includes(':')) { + let counts = unreadCount + .split(':') + .map(s => Ferdium.safeParseInt(s.replace(/[^\p{N}]/gu, ''))); + countImportant = counts[0]; + countNonImportant = counts[1] - counts[0]; + } else { + countImportant = Ferdium.safeParseInt( + unreadCount.replace(/[^\p{N}]/gu, ''), + ); + } } } } } - - // set Ferdium badge - Ferdium.setBadge(count); + Ferdium.setBadge(countImportant, countNonImportant); }; Ferdium.loop(getMessages); -- cgit v1.2.3-70-g09d2