From fe97c525fc8411f4b0a9658f8732bfa94a667c2d Mon Sep 17 00:00:00 2001 From: Mahadevan Sreenivasan Date: Fri, 2 Oct 2020 19:19:45 +0530 Subject: Update Hangouts Chat to display direct and indirect notifications (#306) --- recipes/hangoutschat/package.json | 2 +- recipes/hangoutschat/webview.js | 24 +++++++++++++++--------- 2 files changed, 16 insertions(+), 10 deletions(-) (limited to 'recipes/hangoutschat') diff --git a/recipes/hangoutschat/package.json b/recipes/hangoutschat/package.json index bcc58f9..5ffc252 100644 --- a/recipes/hangoutschat/package.json +++ b/recipes/hangoutschat/package.json @@ -1,7 +1,7 @@ { "id": "hangoutschat", "name": "Hangouts Chat", - "version": "1.3.0", + "version": "1.4.0", "description": "Hangouts Chat", "main": "index.js", "author": "Stefan Malzner and Iván López (ilopmar)", diff --git a/recipes/hangoutschat/webview.js b/recipes/hangoutschat/webview.js index 9597f58..8d51278 100644 --- a/recipes/hangoutschat/webview.js +++ b/recipes/hangoutschat/webview.js @@ -1,15 +1,21 @@ module.exports = (Franz) => { - // class corresponding to the mute icon - const muteSelector = '.DQy0Rb'; + const muteSelector = ".DQy0Rb"; // class corresponding to the red badge that is visible for direct messages - const directMessageSelector = '.SaMfhe.m9MHid'; + const directMessageSelector = ".SaMfhe.m9MHid"; // class corresponding to the bold text that is visible for all messages - const allMessageSelector = '.IL9EXe.PL5Wwe.dHI9xe.H7du2'; - - const isMuted = node => !!node.closest('[role="listitem"]').querySelector(muteSelector); + const allMessageSelector = ".IL9EXe.PL5Wwe.dHI9xe.H7du2"; + + const isMuted = (node) => { + closestItem = node.closest('[role="listitem"]') + if (closestItem) { + return !!closestItem.querySelector(muteSelector); + } else { + return true; + } + } const getMessages = function getMessages() { let allMessageCount = 0; @@ -19,7 +25,7 @@ module.exports = (Franz) => { document.querySelectorAll(directMessageSelector).forEach((node) => { // Hangouts Chat overrides the muted indicator when there is a direct mention // Check for the width of the badge element - if (!isMuted(node) && node.clientWidth != 0 ) { + if (!isMuted(node) && node.clientWidth != 0) { directCount += 1; } }); @@ -36,10 +42,10 @@ module.exports = (Franz) => { Franz.setBadge(directCount, indirectCount); }; - document.addEventListener('click', (e) => { + document.addEventListener("click", (e) => { const { tagName, target, href } = e.target; - if (tagName === 'A' && target === '_blank') { + if (tagName === "A" && target === "_blank") { e.preventDefault(); e.stopImmediatePropagation(); window.open(href); -- cgit v1.2.3-70-g09d2