From d024e2a0d18ce7d4d462b86a7a962dfcc7ca8e05 Mon Sep 17 00:00:00 2001 From: vantezzen Date: Sat, 1 Feb 2020 11:27:00 +0100 Subject: #35 Add fixed Hangouts Chat recipe --- uncompressed/hangoutschat/README.md | 15 +++++++++++--- uncompressed/hangoutschat/index.js | 3 ++- uncompressed/hangoutschat/package.json | 4 ++-- uncompressed/hangoutschat/webview.js | 38 ++++++++++++++++++++-------------- 4 files changed, 39 insertions(+), 21 deletions(-) (limited to 'uncompressed') diff --git a/uncompressed/hangoutschat/README.md b/uncompressed/hangoutschat/README.md index c899924..3ac9e49 100644 --- a/uncompressed/hangoutschat/README.md +++ b/uncompressed/hangoutschat/README.md @@ -1,5 +1,14 @@ # Hangouts Chat for Franz -This is the official Franz recipe for Hangouts Chat -### How to create your own Franz recipes: -* [Read the documentation](https://github.com/meetfranz/plugins) +This is a clone of the [official Franz recipe for Hangouts Chat](https://github.com/meetfranz/recipe-hangoutschat) to +merge the pending PRs, specially the one that fixes the notifications badge. + +## Installation + +You need to apply the plugin manually. + +1. Create the directory `~/.config/Franz/recipes/dev/recipe-hangoutschat` +2. Copy the files from this repository into the new folder +3. Reload Franz +4. Add "Hangouts Chat (Non official)" in Add Service > Custom Service > Hangouts Chat (Non official) +5. Close Franz, start it again and add your account again. diff --git a/uncompressed/hangoutschat/index.js b/uncompressed/hangoutschat/index.js index 298a17c..560a173 100644 --- a/uncompressed/hangoutschat/index.js +++ b/uncompressed/hangoutschat/index.js @@ -1,5 +1,6 @@ +// just pass through Franz module.exports = Franz => - class hangoutschat extends Franz { + class HangoutsChat extends Franz { overrideUserAgent() { return "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:72.0) Gecko/20100101 Firefox/72.0"; } diff --git a/uncompressed/hangoutschat/package.json b/uncompressed/hangoutschat/package.json index 0976f09..e7e1ce3 100644 --- a/uncompressed/hangoutschat/package.json +++ b/uncompressed/hangoutschat/package.json @@ -1,10 +1,10 @@ { "id": "hangoutschat", "name": "Hangouts Chat", - "version": "1.1.2", + "version": "1.2.0", "description": "Hangouts Chat", "main": "index.js", - "author": "Stefan Malzner ", + "author": "Stefan Malzner and Iván López (ilopmar)", "license": "MIT", "config": { "serviceURL": "https://chat.google.com", diff --git a/uncompressed/hangoutschat/webview.js b/uncompressed/hangoutschat/webview.js index 27a2016..ea8a1b2 100644 --- a/uncompressed/hangoutschat/webview.js +++ b/uncompressed/hangoutschat/webview.js @@ -1,30 +1,36 @@ -"use strict"; +module.exports = (Franz) => { + + const muteSelector = '.DQy0Rb'; + const directMessageSelector = '.eM5l9e.FVKzAb'; + const indirectMessageSelector = '.PL5Wwe.H7du2 .t5F5nf'; + + const isMuted = node => !!node.closest('[role="listitem"]').querySelector(muteSelector); -module.exports = Franz => { const getMessages = function getMessages() { - const muteSelector = '.DQy0Rb'; + + // get unread messages let directCount = 0; - document.querySelectorAll('.eM5l9e.FVKzAb').forEach(node => { - if (!node.closest('content[role="listitem"]').querySelector(muteSelector)) { + document.querySelectorAll(directMessageSelector).forEach((node) => { + // Hangouts Chat overrides the muted indicator when there is a direct mention + if (!isMuted(node)) { directCount += 1; } }); + let indirectCount = 0; - document.querySelectorAll('.PL5Wwe.H7du2 .t5F5nf').forEach(node => { - if (!node.closest('content[role="listitem"]').querySelector(muteSelector)) { - indirectCount = +1; + document.querySelectorAll(indirectMessageSelector).forEach((node) => { + if (!isMuted(node)) { + indirectCount += 1; } }); indirectCount -= directCount; + + // set Franz badge Franz.setBadge(directCount, indirectCount); }; - document.addEventListener('click', e => { - const { - tagName, - target, - href - } = e.target; + document.addEventListener('click', (e) => { + const { tagName, target, href } = e.target; if (tagName === 'A' && target === '_blank') { e.preventDefault(); @@ -32,5 +38,7 @@ module.exports = Franz => { window.open(href); } }); + + // check for new messages every second and update Franz badge Franz.loop(getMessages); -}; \ No newline at end of file +}; -- cgit v1.2.3-54-g00ecf