diff options
author | 2020-09-22 20:56:48 +0200 | |
---|---|---|
committer | 2020-09-22 19:56:48 +0100 | |
commit | 6f5e4a00588aefdda7a5a1cfe70935870e7e234a (patch) | |
tree | 9e29aa7aa0620a1a4a968ff8739b4b8ba96791a9 /recipes/hangoutschat/webview.js | |
parent | Updated logos for Outlook/OWA (diff) | |
download | ferdium-recipes-6f5e4a00588aefdda7a5a1cfe70935870e7e234a.tar.gz ferdium-recipes-6f5e4a00588aefdda7a5a1cfe70935870e7e234a.tar.zst ferdium-recipes-6f5e4a00588aefdda7a5a1cfe70935870e7e234a.zip |
Unpack recipes and update recipes icons (#292)
Co-authored-by: Amine Mouafik <amine@mouafik.fr>
Diffstat (limited to 'recipes/hangoutschat/webview.js')
-rw-r--r-- | recipes/hangoutschat/webview.js | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/recipes/hangoutschat/webview.js b/recipes/hangoutschat/webview.js new file mode 100644 index 0000000..9597f58 --- /dev/null +++ b/recipes/hangoutschat/webview.js | |||
@@ -0,0 +1,51 @@ | |||
1 | module.exports = (Franz) => { | ||
2 | |||
3 | // class corresponding to the mute icon | ||
4 | const muteSelector = '.DQy0Rb'; | ||
5 | |||
6 | // class corresponding to the red badge that is visible for direct messages | ||
7 | const directMessageSelector = '.SaMfhe.m9MHid'; | ||
8 | |||
9 | // class corresponding to the bold text that is visible for all messages | ||
10 | const allMessageSelector = '.IL9EXe.PL5Wwe.dHI9xe.H7du2'; | ||
11 | |||
12 | const isMuted = node => !!node.closest('[role="listitem"]').querySelector(muteSelector); | ||
13 | |||
14 | const getMessages = function getMessages() { | ||
15 | let allMessageCount = 0; | ||
16 | let directCount = 0; | ||
17 | |||
18 | // get unread direct messages | ||
19 | document.querySelectorAll(directMessageSelector).forEach((node) => { | ||
20 | // Hangouts Chat overrides the muted indicator when there is a direct mention | ||
21 | // Check for the width of the badge element | ||
22 | if (!isMuted(node) && node.clientWidth != 0 ) { | ||
23 | directCount += 1; | ||
24 | } | ||
25 | }); | ||
26 | |||
27 | let indirectCount = 0; | ||
28 | document.querySelectorAll(allMessageSelector).forEach((node) => { | ||
29 | if (!isMuted(node)) { | ||
30 | allMessageCount += 1; | ||
31 | } | ||
32 | }); | ||
33 | indirectCount = allMessageCount - directCount; | ||
34 | |||
35 | // set Franz badge | ||
36 | Franz.setBadge(directCount, indirectCount); | ||
37 | }; | ||
38 | |||
39 | document.addEventListener('click', (e) => { | ||
40 | const { tagName, target, href } = e.target; | ||
41 | |||
42 | if (tagName === 'A' && target === '_blank') { | ||
43 | e.preventDefault(); | ||
44 | e.stopImmediatePropagation(); | ||
45 | window.open(href); | ||
46 | } | ||
47 | }); | ||
48 | |||
49 | // check for new messages every second and update Franz badge | ||
50 | Franz.loop(getMessages); | ||
51 | }; | ||