From 34471638f12398f8b474c45ed8609299935f769a Mon Sep 17 00:00:00 2001 From: Dustin Date: Tue, 27 Oct 2020 18:20:38 +0000 Subject: Add recipe for Wire (#344) Co-authored-by: Amine Mouafik --- recipes/wire/webview.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 recipes/wire/webview.js (limited to 'recipes/wire/webview.js') 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 @@ +module.exports = (Ferdi) => { + function getMessages() { + let direct = 0; + let indirect = 0; + + // Count how many people/groups have texted you + const conversationElems = document.querySelectorAll('[data-uie-name="conversation-folder-badge"]'); + if (conversationElems) { + for (const conversationElem of conversationElems) { + const count = parseInt(conversationElem.innerText); + if (count) { + direct += count; + } + } + } + + // Count unread pending user requests + const pendingElem = document.querySelector('[data-uie-name="item-pending-requests"]'); + if (pendingElem) { + const matches = pendingElem.innerText.match(/^([1-9][0-9]*)/); + if (matches && matches.length > 0) { + indirect += parseInt(matches[1]); + } + } + + // Alternative would be to count all messages (unread conversation count + pending) from the header + // const titleElem = document.querySelector('head title'); + // const matches = titleElem.innerText.match(/^\(([1-9][0-9]*)\)/); + // if (matches) { + // direct = matches[1]; + // } + + Ferdi.setBadge(direct, indirect); + } + + Ferdi.loop(getMessages); + +}; -- cgit v1.2.3-54-g00ecf