aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/tt-rss/webview.js
diff options
context:
space:
mode:
authorLibravatar Joseph Hale <47901316+thehale@users.noreply.github.com>2023-05-23 14:43:25 -0700
committerLibravatar GitHub <noreply@github.com>2023-05-23 22:43:25 +0100
commiteef3b310e7081c4a636bb29739fb99cb917d4974 (patch)
tree0b678650325fd106c6e48b875108ba5c6d65ec8a /recipes/tt-rss/webview.js
parentfix(github): Include "new notifications" in direct total (#371) (diff)
downloadferdium-recipes-eef3b310e7081c4a636bb29739fb99cb917d4974.tar.gz
ferdium-recipes-eef3b310e7081c4a636bb29739fb99cb917d4974.tar.zst
ferdium-recipes-eef3b310e7081c4a636bb29739fb99cb917d4974.zip
feat(tt-rss): Optionally limit notifications to a Category. (#370)
Diffstat (limited to 'recipes/tt-rss/webview.js')
-rw-r--r--recipes/tt-rss/webview.js43
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
3module.exports = Ferdium => { 3module.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 = () => {