diff options
author | Edgars <Edgars+GitHub@gaitenis.id.lv> | 2022-07-13 09:16:50 +0300 |
---|---|---|
committer | Vijay Aravamudhan <vraravam@users.noreply.github.com> | 2022-07-13 12:14:59 +0530 |
commit | a0555503af19a4c940243fbe777ce939a266fa23 (patch) | |
tree | 47eec566b345a53e209f026faf64a6ff77fe5c77 /recipes | |
parent | Update documentation [skip ci] (diff) | |
download | ferdium-recipes-a0555503af19a4c940243fbe777ce939a266fa23.tar.gz ferdium-recipes-a0555503af19a4c940243fbe777ce939a266fa23.tar.zst ferdium-recipes-a0555503af19a4c940243fbe777ce939a266fa23.zip |
Simplify GitHub badge count detection
GitHub badge count detection was simplified to:
- avoid `if`s;
- improve selector for indirect count element so additional JavaScript
content checking would not be necessary.
Diffstat (limited to 'recipes')
-rw-r--r-- | recipes/github/webview.js | 19 |
1 files changed, 6 insertions, 13 deletions
diff --git a/recipes/github/webview.js b/recipes/github/webview.js index ab55792..1023975 100644 --- a/recipes/github/webview.js +++ b/recipes/github/webview.js | |||
@@ -3,19 +3,12 @@ module.exports = Ferdium => { | |||
3 | const directCountElement = document.querySelector( | 3 | const directCountElement = document.querySelector( |
4 | '.filter-list.js-notification-inboxes .count', | 4 | '.filter-list.js-notification-inboxes .count', |
5 | ); | 5 | ); |
6 | let directCount = 0; | 6 | const directCount = directCountElement |
7 | if (directCountElement) { | 7 | ? Ferdium.safeParseInt(directCountElement.textContent) |
8 | directCount = Ferdium.safeParseInt(directCountElement.textContent); | 8 | : 0; |
9 | } | 9 | const indirectCount = document.querySelector( |
10 | 10 | '[class*="mail-status unread"]:not([hidden])', | |
11 | const indirectCountElement = document.querySelector( | 11 | ) ? 1 : 0; |
12 | '[class*="mail-status unread"]', | ||
13 | ); | ||
14 | let indirectCount = 0; | ||
15 | if (indirectCountElement && indirectCountElement.textContent.trim().length > 0) { | ||
16 | indirectCount = 1; | ||
17 | } | ||
18 | |||
19 | Ferdium.setBadge(directCount, indirectCount); | 12 | Ferdium.setBadge(directCount, indirectCount); |
20 | }; | 13 | }; |
21 | 14 | ||