diff options
author | 2023-12-15 01:44:51 +0100 | |
---|---|---|
committer | 2023-12-14 17:44:51 -0700 | |
commit | 6a74a1bb8cb12e7de4e011870eb0e62d666b3be9 (patch) | |
tree | 4ea18cb839852e3c39b5d56fa76c01c4369f4601 /recipes/zulip/webview.js | |
parent | Add Diagrams.net service recipe (#477) (diff) | |
download | ferdium-recipes-6a74a1bb8cb12e7de4e011870eb0e62d666b3be9.tar.gz ferdium-recipes-6a74a1bb8cb12e7de4e011870eb0e62d666b3be9.tar.zst ferdium-recipes-6a74a1bb8cb12e7de4e011870eb0e62d666b3be9.zip |
Zulip changed unread locations (#478)
Diffstat (limited to 'recipes/zulip/webview.js')
-rw-r--r-- | recipes/zulip/webview.js | 39 |
1 files changed, 29 insertions, 10 deletions
diff --git a/recipes/zulip/webview.js b/recipes/zulip/webview.js index 707b723..a63d49e 100644 --- a/recipes/zulip/webview.js +++ b/recipes/zulip/webview.js | |||
@@ -5,27 +5,46 @@ 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 | function getUnreadCount(eltClassName) { | 8 | function getUnreadMentions() { |
9 | const elt = document.querySelectorAll( | 9 | const anchorWithMentionHref = document.querySelector( |
10 | `#global_filters .${eltClassName} .unread_count`, | 10 | 'a[href*="is/mentioned"]', |
11 | )[0]; | 11 | ); |
12 | return elt === null ? 0 : Ferdium.safeParseInt(elt.textContent); | 12 | const unreadCountElement = |
13 | anchorWithMentionHref.querySelector('.unread_count'); | ||
14 | |||
15 | return unreadCountElement == null | ||
16 | ? 0 | ||
17 | : Ferdium.safeParseInt(unreadCountElement.textContent); | ||
13 | } | 18 | } |
14 | 19 | ||
20 | function getUnreadCount(eltId) { | ||
21 | const elt = document.querySelectorAll(`#${eltId} + .unread_count`)[0]; | ||
22 | return elt == null ? 0 : Ferdium.safeParseInt(elt.textContent); | ||
23 | } | ||
24 | |||
25 | function getStreamsUnread() { | ||
26 | const streamsHeader = document.querySelector('#streams_header'); | ||
27 | const unreadCountElement = streamsHeader.querySelector('.unread_count'); | ||
28 | |||
29 | return unreadCountElement == null | ||
30 | ? 0 | ||
31 | : Ferdium.safeParseInt(unreadCountElement.textContent); | ||
32 | } | ||
33 | |||
34 | //document.querySelector('#show_all_private_messages + .unread_count') | ||
15 | const getMessages = () => { | 35 | const getMessages = () => { |
16 | // All unread messages | 36 | // All unread messages |
17 | const unreadAll = getUnreadCount('top_left_all_messages'); | 37 | const streamUnread = getStreamsUnread(); |
18 | 38 | ||
19 | // Private messages | 39 | // Private messages |
20 | const unreadPrivate = getUnreadCount('top_left_private_messages'); | 40 | const unreadPrivate = getUnreadCount('show_all_private_messages'); |
21 | 41 | ||
22 | // @ Mentions messages | 42 | // @ Mentions messages |
23 | const unreadMentions = getUnreadCount('top_left_mentions'); | 43 | const unreadMentions = getUnreadMentions(); |
24 | 44 | ||
25 | const directMessages = unreadPrivate + unreadMentions; | 45 | const directMessages = unreadPrivate + unreadMentions; |
26 | const indirectMessages = unreadAll - directMessages; | ||
27 | 46 | ||
28 | Ferdium.setBadge(directMessages, indirectMessages); | 47 | Ferdium.setBadge(directMessages, streamUnread); |
29 | }; | 48 | }; |
30 | 49 | ||
31 | Ferdium.loop(getMessages); | 50 | Ferdium.loop(getMessages); |