diff options
Diffstat (limited to 'recipes/rocketchat/webview.js')
-rw-r--r-- | recipes/rocketchat/webview.js | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/recipes/rocketchat/webview.js b/recipes/rocketchat/webview.js index 74556de..67f50f1 100644 --- a/recipes/rocketchat/webview.js +++ b/recipes/rocketchat/webview.js | |||
@@ -6,19 +6,19 @@ const _path = _interopRequireDefault(require('path')); | |||
6 | 6 | ||
7 | module.exports = Ferdium => { | 7 | module.exports = Ferdium => { |
8 | const getMessages = () => { | 8 | const getMessages = () => { |
9 | const directMessages = document.querySelectorAll('.rcx-badge'); | 9 | const title = document.querySelector('title'); |
10 | 10 | const matches = title.textContent.match(/^\((\S*?)\)/); | |
11 | let directMessagesCount = 0; | 11 | |
12 | 12 | if (matches) { | |
13 | for (const directMessage of directMessages) { | 13 | const count = Ferdium.safeParseInt(matches[1], 10); |
14 | directMessagesCount += Ferdium.safeParseInt(directMessage.textContent); | 14 | if (count) { |
15 | Ferdium.setBadge(count); | ||
16 | } else { | ||
17 | Ferdium.setBadge(0, 1); | ||
18 | } | ||
19 | } else { | ||
20 | Ferdium.setBadge(0); | ||
15 | } | 21 | } |
16 | |||
17 | const indirectMessagesCount = Math.round( | ||
18 | document.querySelectorAll('.rcx-sidebar-item--highlighted').length, | ||
19 | ); | ||
20 | |||
21 | Ferdium.setBadge(directMessagesCount, indirectMessagesCount); | ||
22 | }; | 22 | }; |
23 | 23 | ||
24 | Ferdium.loop(getMessages); | 24 | Ferdium.loop(getMessages); |