diff options
Diffstat (limited to 'recipes/wire/webview.js')
-rw-r--r-- | recipes/wire/webview.js | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/recipes/wire/webview.js b/recipes/wire/webview.js new file mode 100644 index 0000000..57baadc --- /dev/null +++ b/recipes/wire/webview.js | |||
@@ -0,0 +1,38 @@ | |||
1 | module.exports = (Ferdi) => { | ||
2 | function getMessages() { | ||
3 | let direct = 0; | ||
4 | let indirect = 0; | ||
5 | |||
6 | // Count how many people/groups have texted you | ||
7 | const conversationElems = document.querySelectorAll('[data-uie-name="conversation-folder-badge"]'); | ||
8 | if (conversationElems) { | ||
9 | for (const conversationElem of conversationElems) { | ||
10 | const count = parseInt(conversationElem.innerText); | ||
11 | if (count) { | ||
12 | direct += count; | ||
13 | } | ||
14 | } | ||
15 | } | ||
16 | |||
17 | // Count unread pending user requests | ||
18 | const pendingElem = document.querySelector('[data-uie-name="item-pending-requests"]'); | ||
19 | if (pendingElem) { | ||
20 | const matches = pendingElem.innerText.match(/^([1-9][0-9]*)/); | ||
21 | if (matches && matches.length > 0) { | ||
22 | indirect += parseInt(matches[1]); | ||
23 | } | ||
24 | } | ||
25 | |||
26 | // Alternative would be to count all messages (unread conversation count + pending) from the header | ||
27 | // const titleElem = document.querySelector('head title'); | ||
28 | // const matches = titleElem.innerText.match(/^\(([1-9][0-9]*)\)/); | ||
29 | // if (matches) { | ||
30 | // direct = matches[1]; | ||
31 | // } | ||
32 | |||
33 | Ferdi.setBadge(direct, indirect); | ||
34 | } | ||
35 | |||
36 | Ferdi.loop(getMessages); | ||
37 | |||
38 | }; | ||