aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/rocketchat/webview.js
diff options
context:
space:
mode:
authorLibravatar Bennett <hello@vantezzen.io>2020-09-22 20:56:48 +0200
committerLibravatar GitHub <noreply@github.com>2020-09-22 19:56:48 +0100
commit6f5e4a00588aefdda7a5a1cfe70935870e7e234a (patch)
tree9e29aa7aa0620a1a4a968ff8739b4b8ba96791a9 /recipes/rocketchat/webview.js
parentUpdated logos for Outlook/OWA (diff)
downloadferdium-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/rocketchat/webview.js')
-rw-r--r--recipes/rocketchat/webview.js51
1 files changed, 51 insertions, 0 deletions
diff --git a/recipes/rocketchat/webview.js b/recipes/rocketchat/webview.js
new file mode 100644
index 0000000..5ccd0d2
--- /dev/null
+++ b/recipes/rocketchat/webview.js
@@ -0,0 +1,51 @@
1"use strict";
2
3const {
4 ipcRenderer
5} = require('electron');
6
7const getTeamIcon = function getTeamIcon() {
8 console.log('getTeamIcon');
9 const manifestElement = document.querySelector('link[rel="manifest"]');
10
11 if (manifestElement == null) {
12 return;
13 }
14
15 const manifestUrl = manifestElement.getAttribute('href');
16 console.log(manifestUrl);
17
18 if (manifestUrl == null) {
19 return;
20 }
21
22 const xmlhttp = new XMLHttpRequest();
23
24 xmlhttp.onreadystatechange = function () {
25 if (this.readyState != 4 || this.status != 200) {
26 return;
27 }
28
29 const response = JSON.parse(this.responseText);
30
31 if (response.icons.length >= 1) {
32 ipcRenderer.sendToHost('avatar', `${window.location.protocol}//${window.location.host}${response.icons[0].src}`);
33 }
34 };
35
36 xmlhttp.open('GET', manifestUrl, true);
37 xmlhttp.send();
38};
39
40module.exports = Franz => {
41 const getMessages = function getMessages() {
42 const directMessages = Math.round(document.querySelectorAll('.unread.unread-mention, .badge--unread').length / 2);
43 const indirectMessages = Math.round(document.querySelectorAll('.unread:not(.unread-mention), .sidebar-item--unread').length / 2);
44 Franz.setBadge(directMessages, indirectMessages);
45 };
46
47 Franz.loop(getMessages);
48 setTimeout(() => {
49 getTeamIcon();
50 }, 4000);
51}; \ No newline at end of file