diff options
-rw-r--r-- | recipes/tt-rss/README.md | 38 | ||||
-rw-r--r-- | recipes/tt-rss/package.json | 2 | ||||
-rw-r--r-- | recipes/tt-rss/webview.js | 43 |
3 files changed, 72 insertions, 11 deletions
diff --git a/recipes/tt-rss/README.md b/recipes/tt-rss/README.md index d0ef122..a4866d4 100644 --- a/recipes/tt-rss/README.md +++ b/recipes/tt-rss/README.md | |||
@@ -1,3 +1,39 @@ | |||
1 | # Tiny Tiny RSS for Ferdium | 1 | # Tiny Tiny RSS for Ferdium |
2 | 2 | ||
3 | Support for [Tiny Tiny RSS](https://tt-rss.org/) | 3 | Interact with [Tiny Tiny RSS](https://tt-rss.org/) inside of Ferdium! |
4 | |||
5 | ## Usage | ||
6 | |||
7 | 1. Search for "RSS" in Ferdium's **Available Services** | ||
8 | 2. Enter the URL of your Tiny Tiny RSS server | ||
9 | 3. Save the service and log in! | ||
10 | |||
11 | ## Configuration | ||
12 | |||
13 | ### `ferdiumNotificationLabel` | ||
14 | |||
15 | You can limit notifications from Tiny Tiny RSS to new articles in a specific | ||
16 | Category using the custom `ferdiumNotificationLabel` query parameter as part of | ||
17 | your server URL. | ||
18 | |||
19 | ``` | ||
20 | https://ttrss.example.com/tt-rss/?ferdiumNotificationLabel=CATEGORY_NAME | ||
21 | ``` | ||
22 | |||
23 | For example, if I wanted to only see notifications from a Category titled | ||
24 | `Software - Updates`, I would use one of the following query parameters: | ||
25 | |||
26 | ``` | ||
27 | ?ferdiumNotificationLabel=Software - Updates | ||
28 | ``` | ||
29 | **OR** | ||
30 | ``` | ||
31 | ?ferdiumNotificationLabel=Software%20-%20Updates | ||
32 | ``` | ||
33 | |||
34 | The second option is the better/safer approach to take, but the first also works | ||
35 | because Ferdium will escape the spaces for you (at least as of version 6.2.7). | ||
36 | |||
37 | NOTE: When using the `ferdiumNotificationLabel` configuration, all other unread | ||
38 | articles in other categories are reported as [**indirect** | ||
39 | messages](https://github.com/ferdium/ferdium-recipes/blob/main/docs/frontend_api.md#setbadgedirectmessages-indirectmessages). \ No newline at end of file | ||
diff --git a/recipes/tt-rss/package.json b/recipes/tt-rss/package.json index 2b3a305..a2fff77 100644 --- a/recipes/tt-rss/package.json +++ b/recipes/tt-rss/package.json | |||
@@ -1,7 +1,7 @@ | |||
1 | { | 1 | { |
2 | "id": "tt-rss", | 2 | "id": "tt-rss", |
3 | "name": "Tiny Tiny RSS", | 3 | "name": "Tiny Tiny RSS", |
4 | "version": "1.1.0", | 4 | "version": "1.2.0", |
5 | "license": "MIT", | 5 | "license": "MIT", |
6 | "config": { | 6 | "config": { |
7 | "hasCustomUrl": true | 7 | "hasCustomUrl": true |
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 = () => { |