diff options
Diffstat (limited to 'recipes/hangoutschat')
-rw-r--r-- | recipes/hangoutschat/webview.js | 38 |
1 files changed, 6 insertions, 32 deletions
diff --git a/recipes/hangoutschat/webview.js b/recipes/hangoutschat/webview.js index 8d51278..d344ad7 100644 --- a/recipes/hangoutschat/webview.js +++ b/recipes/hangoutschat/webview.js | |||
@@ -1,42 +1,16 @@ | |||
1 | module.exports = (Franz) => { | 1 | module.exports = (Franz) => { |
2 | // class corresponding to the mute icon | ||
3 | const muteSelector = ".DQy0Rb"; | ||
4 | |||
5 | // class corresponding to the red badge that is visible for direct messages | 2 | // class corresponding to the red badge that is visible for direct messages |
6 | const directMessageSelector = ".SaMfhe.m9MHid"; | 3 | const directMessageSelector = "div.V6.CL.su.ahD.X9.Y2 span.akt span.XU"; |
7 | |||
8 | // class corresponding to the bold text that is visible for all messages | ||
9 | const allMessageSelector = ".IL9EXe.PL5Wwe.dHI9xe.H7du2"; | ||
10 | 4 | ||
11 | const isMuted = (node) => { | 5 | // class corresponding to the bold text that is visible for room messages |
12 | closestItem = node.closest('[role="listitem"]') | 6 | const indirectMessageSelector = "div.V6.CL.V2.X9.Y2 span.akt span.XU"; |
13 | if (closestItem) { | ||
14 | return !!closestItem.querySelector(muteSelector); | ||
15 | } else { | ||
16 | return true; | ||
17 | } | ||
18 | } | ||
19 | 7 | ||
20 | const getMessages = function getMessages() { | 8 | const getMessages = function getMessages() { |
21 | let allMessageCount = 0; | ||
22 | let directCount = 0; | ||
23 | |||
24 | // get unread direct messages | 9 | // get unread direct messages |
25 | document.querySelectorAll(directMessageSelector).forEach((node) => { | 10 | let directCount = Number(document.querySelector(directMessageSelector).innerText) |
26 | // Hangouts Chat overrides the muted indicator when there is a direct mention | ||
27 | // Check for the width of the badge element | ||
28 | if (!isMuted(node) && node.clientWidth != 0) { | ||
29 | directCount += 1; | ||
30 | } | ||
31 | }); | ||
32 | 11 | ||
33 | let indirectCount = 0; | 12 | // get unread indirect messages |
34 | document.querySelectorAll(allMessageSelector).forEach((node) => { | 13 | let indirectCount = Number(document.querySelector(indirectMessageSelector).innerText); |
35 | if (!isMuted(node)) { | ||
36 | allMessageCount += 1; | ||
37 | } | ||
38 | }); | ||
39 | indirectCount = allMessageCount - directCount; | ||
40 | 14 | ||
41 | // set Franz badge | 15 | // set Franz badge |
42 | Franz.setBadge(directCount, indirectCount); | 16 | Franz.setBadge(directCount, indirectCount); |