diff options
Diffstat (limited to 'recipes/tt-rss/webview.js')
-rw-r--r-- | recipes/tt-rss/webview.js | 43 |
1 files changed, 34 insertions, 9 deletions
diff --git a/recipes/tt-rss/webview.js b/recipes/tt-rss/webview.js index 3e3a0d3..7d90615 100644 --- a/recipes/tt-rss/webview.js +++ b/recipes/tt-rss/webview.js | |||
@@ -1,16 +1,41 @@ | |||
1 | "use strict"; | 1 | "use strict"; |
2 | 2 | ||
3 | module.exports = Ferdium => { | 3 | module.exports = Ferdium => { |
4 | const _notificationCategory = new URL(window.location.href).searchParams.get("ferdiumNotificationCategory"); | ||
5 | |||
4 | const getMessages = function getMessages() { | 6 | const getMessages = function getMessages() { |
5 | // Initialize empty vars | 7 | if (_notificationCategory) { |
6 | var unread = 0; | 8 | countMessagesUnderCategory(_notificationCategory); |
7 | var match = []; | 9 | } else { |
8 | // Extract the number from the title | 10 | countMessages(); |
9 | match = document.title.match(/^\((\d+)\) Tiny Tiny RSS$/); | 11 | } |
10 | // Some logic to handle the match groups | 12 | }; |
11 | unread = match != null && match.length > 0 ? match[1] : 0; | 13 | |
12 | // Set unread msgs badge | 14 | const countMessagesUnderCategory = (notificationCategory) => { |
13 | Ferdium.setBadge(Number.parseInt(unread, 10)); | 15 | var elements = document.querySelectorAll(".dijitTreeIsRoot") |
16 | var directMessages = 0; | ||
17 | var indirectMessages = 0; | ||
18 | for (var element of elements) { | ||
19 | var label = element.querySelectorAll(".dijitTreeLabel")[0]; | ||
20 | var unreadNode = element.querySelectorAll(".unread")[0]; | ||
21 | var unreadAmount = Ferdium.safeParseInt(unreadNode.textContent); | ||
22 | if (label.textContent === notificationCategory) { | ||
23 | directMessages += unreadAmount; | ||
24 | } else { | ||
25 | indirectMessages += unreadAmount; | ||
26 | } | ||
27 | } | ||
28 | Ferdium.setBadge(directMessages, indirectMessages); | ||
29 | }; | ||
30 | |||
31 | const _countMessagesFromTitle = () => { | ||
32 | var match = document.title.match(/^\((\d+)\) Tiny Tiny RSS$/); | ||
33 | var count = match != null && match.length > 0 ? match[1] : 0; | ||
34 | return Ferdium.safeParseInt(count); | ||
35 | } | ||
36 | |||
37 | const countMessages = () => { | ||
38 | Ferdium.setBadge(_countMessagesFromTitle()); | ||
14 | }; | 39 | }; |
15 | 40 | ||
16 | const loopFunc = () => { | 41 | const loopFunc = () => { |