Skip to content

Commit

Permalink
Fix indirect notifications badge for GitHub (#476)
Browse files Browse the repository at this point in the history
  • Loading branch information
eandersons authored Dec 13, 2023
1 parent 0ece08f commit d05588b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 28 deletions.
2 changes: 1 addition & 1 deletion recipes/github/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "github",
"name": "GitHub",
"version": "2.6.0",
"version": "2.6.1",
"license": "MIT",
"config": {
"serviceURL": "https://github.com/notifications",
Expand Down
38 changes: 11 additions & 27 deletions recipes/github/webview.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
};

0 comments on commit d05588b

Please sign in to comment.