aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/wire/webview.js
diff options
context:
space:
mode:
authorLibravatar Dustin <dustin.steiner@gmail.com>2020-10-27 18:20:38 +0000
committerLibravatar GitHub <noreply@github.com>2020-10-27 19:20:38 +0100
commit34471638f12398f8b474c45ed8609299935f769a (patch)
tree1f1ba217ff6d12001bb3104254c189677b266ad0 /recipes/wire/webview.js
parentMerge pull request #341 from marcolussetti/clarify-docs-square-svg (diff)
downloadferdium-recipes-34471638f12398f8b474c45ed8609299935f769a.tar.gz
ferdium-recipes-34471638f12398f8b474c45ed8609299935f769a.tar.zst
ferdium-recipes-34471638f12398f8b474c45ed8609299935f769a.zip
Add recipe for Wire (#344)
Co-authored-by: Amine Mouafik <amine@mouafik.fr>
Diffstat (limited to 'recipes/wire/webview.js')
-rw-r--r--recipes/wire/webview.js38
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 @@
1module.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};