From d05588b1dc4462a6279c581a34fff0fdbe53e842 Mon Sep 17 00:00:00 2001 From: Edgars Date: Wed, 13 Dec 2023 15:35:10 +0200 Subject: Fix indirect notifications badge for GitHub (#476) --- recipes/github/package.json | 2 +- recipes/github/webview.js | 38 +++++++++++--------------------------- 2 files changed, 12 insertions(+), 28 deletions(-) diff --git a/recipes/github/package.json b/recipes/github/package.json index 8788aad..e077f8d 100644 --- a/recipes/github/package.json +++ b/recipes/github/package.json @@ -1,7 +1,7 @@ { "id": "github", "name": "GitHub", - "version": "2.6.0", + "version": "2.6.1", "license": "MIT", "config": { "serviceURL": "https://github.com/notifications", diff --git a/recipes/github/webview.js b/recipes/github/webview.js index 3068b80..c3f653f 100644 --- a/recipes/github/webview.js +++ b/recipes/github/webview.js @@ -5,36 +5,20 @@ function _interopRequireDefault(obj) { const _path = _interopRequireDefault(require('path')); module.exports = Ferdium => { - const _parseNewCount = text => { - const match = text.match(/\d+/); - return match ? Ferdium.safeParseInt(match[0]) : 0; - }; - + const newCountMatch = document + .querySelector('a.h6[href="/notifications?query="]') + ?.textContent?.match(/\d+/); const getMessages = () => { - const directCountElement = document.querySelector( - '.filter-list.js-notification-inboxes .count', - ); - let directCount = directCountElement - ? Ferdium.safeParseInt(directCountElement.textContent) - : 0; - - const newCountElement = document.querySelector( - 'a.h6[href="/notifications?query="]', + Ferdium.setBadge( + Ferdium.safeParseInt( + document.querySelector('.filter-list.js-notification-inboxes .count') + ?.textContent, + ) + Ferdium.safeParseInt(newCountMatch ? newCountMatch[0] : 0), + document.querySelectorAll( + '#AppHeader-notifications-button.AppHeader-button--hasIndicator', + ).length, ); - const newCount = newCountElement - ? _parseNewCount(newCountElement.textContent) - : 0; - directCount += newCount; - - const indirectCount = document.querySelector( - '[class*="mail-status unread"]:not([hidden])', - ) - ? 1 - : 0; - Ferdium.setBadge(directCount, indirectCount); }; - Ferdium.loop(getMessages); - Ferdium.injectCSS(_path.default.join(__dirname, 'service.css')); }; -- cgit v1.2.3-54-g00ecf