diff options
author | Edgars <eandersons@users.noreply.github.com> | 2023-12-13 15:35:10 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-13 06:35:10 -0700 |
commit | d05588b1dc4462a6279c581a34fff0fdbe53e842 (patch) | |
tree | 6c5e433adf2422eb517f6b44155007a027a8e378 /recipes/github/webview.js | |
parent | Add Wakapi recipe (#474) (diff) | |
download | ferdium-recipes-d05588b1dc4462a6279c581a34fff0fdbe53e842.tar.gz ferdium-recipes-d05588b1dc4462a6279c581a34fff0fdbe53e842.tar.zst ferdium-recipes-d05588b1dc4462a6279c581a34fff0fdbe53e842.zip |
Fix indirect notifications badge for GitHub (#476)
Diffstat (limited to 'recipes/github/webview.js')
-rw-r--r-- | recipes/github/webview.js | 38 |
1 files changed, 11 insertions, 27 deletions
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) { | |||
5 | const _path = _interopRequireDefault(require('path')); | 5 | const _path = _interopRequireDefault(require('path')); |
6 | 6 | ||
7 | module.exports = Ferdium => { | 7 | module.exports = Ferdium => { |
8 | const _parseNewCount = text => { | 8 | const newCountMatch = document |
9 | const match = text.match(/\d+/); | 9 | .querySelector('a.h6[href="/notifications?query="]') |
10 | return match ? Ferdium.safeParseInt(match[0]) : 0; | 10 | ?.textContent?.match(/\d+/); |
11 | }; | ||
12 | |||
13 | const getMessages = () => { | 11 | const getMessages = () => { |
14 | const directCountElement = document.querySelector( | 12 | Ferdium.setBadge( |
15 | '.filter-list.js-notification-inboxes .count', | 13 | Ferdium.safeParseInt( |
16 | ); | 14 | document.querySelector('.filter-list.js-notification-inboxes .count') |
17 | let directCount = directCountElement | 15 | ?.textContent, |
18 | ? Ferdium.safeParseInt(directCountElement.textContent) | 16 | ) + Ferdium.safeParseInt(newCountMatch ? newCountMatch[0] : 0), |
19 | : 0; | 17 | document.querySelectorAll( |
20 | 18 | '#AppHeader-notifications-button.AppHeader-button--hasIndicator', | |
21 | const newCountElement = document.querySelector( | 19 | ).length, |
22 | 'a.h6[href="/notifications?query="]', | ||
23 | ); | 20 | ); |
24 | const newCount = newCountElement | ||
25 | ? _parseNewCount(newCountElement.textContent) | ||
26 | : 0; | ||
27 | directCount += newCount; | ||
28 | |||
29 | const indirectCount = document.querySelector( | ||
30 | '[class*="mail-status unread"]:not([hidden])', | ||
31 | ) | ||
32 | ? 1 | ||
33 | : 0; | ||
34 | Ferdium.setBadge(directCount, indirectCount); | ||
35 | }; | 21 | }; |
36 | |||
37 | Ferdium.loop(getMessages); | 22 | Ferdium.loop(getMessages); |
38 | |||
39 | Ferdium.injectCSS(_path.default.join(__dirname, 'service.css')); | 23 | Ferdium.injectCSS(_path.default.join(__dirname, 'service.css')); |
40 | }; | 24 | }; |