diff options
author | 2020-02-01 11:27:00 +0100 | |
---|---|---|
committer | 2020-02-01 11:27:00 +0100 | |
commit | d024e2a0d18ce7d4d462b86a7a962dfcc7ca8e05 (patch) | |
tree | 801be6dfc25b69ed121841ef7282dc33e7b6870f /uncompressed/hangoutschat | |
parent | Replace Google Service User Agents (diff) | |
download | ferdium-recipes-d024e2a0d18ce7d4d462b86a7a962dfcc7ca8e05.tar.gz ferdium-recipes-d024e2a0d18ce7d4d462b86a7a962dfcc7ca8e05.tar.zst ferdium-recipes-d024e2a0d18ce7d4d462b86a7a962dfcc7ca8e05.zip |
#35 Add fixed Hangouts Chat recipe
Diffstat (limited to 'uncompressed/hangoutschat')
-rw-r--r-- | uncompressed/hangoutschat/README.md | 15 | ||||
-rw-r--r-- | uncompressed/hangoutschat/index.js | 3 | ||||
-rw-r--r-- | uncompressed/hangoutschat/package.json | 4 | ||||
-rw-r--r-- | uncompressed/hangoutschat/webview.js | 38 |
4 files changed, 39 insertions, 21 deletions
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 @@ | |||
1 | # Hangouts Chat for Franz | 1 | # Hangouts Chat for Franz |
2 | This is the official Franz recipe for Hangouts Chat | ||
3 | 2 | ||
4 | ### How to create your own Franz recipes: | 3 | This is a clone of the [official Franz recipe for Hangouts Chat](https://github.com/meetfranz/recipe-hangoutschat) to |
5 | * [Read the documentation](https://github.com/meetfranz/plugins) | 4 | merge the pending PRs, specially the one that fixes the notifications badge. |
5 | |||
6 | ## Installation | ||
7 | |||
8 | You need to apply the plugin manually. | ||
9 | |||
10 | 1. Create the directory `~/.config/Franz/recipes/dev/recipe-hangoutschat` | ||
11 | 2. Copy the files from this repository into the new folder | ||
12 | 3. Reload Franz | ||
13 | 4. Add "Hangouts Chat (Non official)" in Add Service > Custom Service > Hangouts Chat (Non official) | ||
14 | 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 @@ | |||
1 | // just pass through Franz | ||
1 | module.exports = Franz => | 2 | module.exports = Franz => |
2 | class hangoutschat extends Franz { | 3 | class HangoutsChat extends Franz { |
3 | overrideUserAgent() { | 4 | overrideUserAgent() { |
4 | return "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:72.0) Gecko/20100101 Firefox/72.0"; | 5 | return "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:72.0) Gecko/20100101 Firefox/72.0"; |
5 | } | 6 | } |
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 @@ | |||
1 | { | 1 | { |
2 | "id": "hangoutschat", | 2 | "id": "hangoutschat", |
3 | "name": "Hangouts Chat", | 3 | "name": "Hangouts Chat", |
4 | "version": "1.1.2", | 4 | "version": "1.2.0", |
5 | "description": "Hangouts Chat", | 5 | "description": "Hangouts Chat", |
6 | "main": "index.js", | 6 | "main": "index.js", |
7 | "author": "Stefan Malzner <stefan@adlk.io>", | 7 | "author": "Stefan Malzner <stefan@adlk.io> and Iván López (ilopmar)", |
8 | "license": "MIT", | 8 | "license": "MIT", |
9 | "config": { | 9 | "config": { |
10 | "serviceURL": "https://chat.google.com", | 10 | "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 @@ | |||
1 | "use strict"; | 1 | module.exports = (Franz) => { |
2 | |||
3 | const muteSelector = '.DQy0Rb'; | ||
4 | const directMessageSelector = '.eM5l9e.FVKzAb'; | ||
5 | const indirectMessageSelector = '.PL5Wwe.H7du2 .t5F5nf'; | ||
6 | |||
7 | const isMuted = node => !!node.closest('[role="listitem"]').querySelector(muteSelector); | ||
2 | 8 | ||
3 | module.exports = Franz => { | ||
4 | const getMessages = function getMessages() { | 9 | const getMessages = function getMessages() { |
5 | const muteSelector = '.DQy0Rb'; | 10 | |
11 | // get unread messages | ||
6 | let directCount = 0; | 12 | let directCount = 0; |
7 | document.querySelectorAll('.eM5l9e.FVKzAb').forEach(node => { | 13 | document.querySelectorAll(directMessageSelector).forEach((node) => { |
8 | if (!node.closest('content[role="listitem"]').querySelector(muteSelector)) { | 14 | // Hangouts Chat overrides the muted indicator when there is a direct mention |
15 | if (!isMuted(node)) { | ||
9 | directCount += 1; | 16 | directCount += 1; |
10 | } | 17 | } |
11 | }); | 18 | }); |
19 | |||
12 | let indirectCount = 0; | 20 | let indirectCount = 0; |
13 | document.querySelectorAll('.PL5Wwe.H7du2 .t5F5nf').forEach(node => { | 21 | document.querySelectorAll(indirectMessageSelector).forEach((node) => { |
14 | if (!node.closest('content[role="listitem"]').querySelector(muteSelector)) { | 22 | if (!isMuted(node)) { |
15 | indirectCount = +1; | 23 | indirectCount += 1; |
16 | } | 24 | } |
17 | }); | 25 | }); |
18 | indirectCount -= directCount; | 26 | indirectCount -= directCount; |
27 | |||
28 | // set Franz badge | ||
19 | Franz.setBadge(directCount, indirectCount); | 29 | Franz.setBadge(directCount, indirectCount); |
20 | }; | 30 | }; |
21 | 31 | ||
22 | document.addEventListener('click', e => { | 32 | document.addEventListener('click', (e) => { |
23 | const { | 33 | const { tagName, target, href } = e.target; |
24 | tagName, | ||
25 | target, | ||
26 | href | ||
27 | } = e.target; | ||
28 | 34 | ||
29 | if (tagName === 'A' && target === '_blank') { | 35 | if (tagName === 'A' && target === '_blank') { |
30 | e.preventDefault(); | 36 | e.preventDefault(); |
@@ -32,5 +38,7 @@ module.exports = Franz => { | |||
32 | window.open(href); | 38 | window.open(href); |
33 | } | 39 | } |
34 | }); | 40 | }); |
41 | |||
42 | // check for new messages every second and update Franz badge | ||
35 | Franz.loop(getMessages); | 43 | Franz.loop(getMessages); |
36 | }; \ No newline at end of file | 44 | }; |