Skip to content

Commit

Permalink
Fix indirect notifications badge for GitHub
Browse files Browse the repository at this point in the history
Selector for finding out whether an indirect notification is present was
updated.
  • Loading branch information
eandersons committed Dec 8, 2023
1 parent 0ece08f commit 3a59ba8
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 3a59ba8

Please sign in to comment.