aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/rocketchat/webview.js
diff options
context:
space:
mode:
Diffstat (limited to 'recipes/rocketchat/webview.js')
-rw-r--r--recipes/rocketchat/webview.js67
1 files changed, 34 insertions, 33 deletions
diff --git a/recipes/rocketchat/webview.js b/recipes/rocketchat/webview.js
index 4240935..159adea 100644
--- a/recipes/rocketchat/webview.js
+++ b/recipes/rocketchat/webview.js
@@ -1,36 +1,3 @@
1const getTeamIcon = function getTeamIcon() {
2 const manifestElement = document.querySelector('link[rel="manifest"]');
3
4 if (manifestElement == null) {
5 return;
6 }
7
8 const manifestUrl = manifestElement.getAttribute('href');
9
10 if (manifestUrl == null) {
11 return;
12 }
13
14 const xmlhttp = new XMLHttpRequest();
15
16 xmlhttp.onreadystatechange = function () {
17 if (this.readyState != 4 || this.status != 200) {
18 return;
19 }
20
21 const response = JSON.parse(this.responseText);
22
23 if (response.icons.length >= 1) {
24 Ferdi.ipcRenderer.sendToHost(
25 'avatar',
26 `${window.location.protocol}//${window.location.host}${response.icons[0].src}`,
27 );
28 }
29 };
30
31 xmlhttp.open('GET', manifestUrl, true);
32 xmlhttp.send();
33};
34 1
35module.exports = Ferdi => { 2module.exports = Ferdi => {
36 const getMessages = function getMessages() { 3 const getMessages = function getMessages() {
@@ -51,6 +18,40 @@ module.exports = Ferdi => {
51 18
52 Ferdi.loop(getMessages); 19 Ferdi.loop(getMessages);
53 20
21 const getTeamIcon = function getTeamIcon() {
22 const manifestElement = document.querySelector('link[rel="manifest"]');
23
24 if (manifestElement == null) {
25 return;
26 }
27
28 const manifestUrl = manifestElement.getAttribute('href');
29
30 if (manifestUrl == null) {
31 return;
32 }
33
34 const xmlhttp = new XMLHttpRequest();
35
36 xmlhttp.onreadystatechange = function () {
37 if (this.readyState != 4 || this.status != 200) {
38 return;
39 }
40
41 const response = JSON.parse(this.responseText);
42
43 if (response.icons.length >= 1) {
44 Ferdi.ipcRenderer.sendToHost(
45 'avatar',
46 `${window.location.protocol}//${window.location.host}${response.icons[0].src}`,
47 );
48 }
49 };
50
51 xmlhttp.open('GET', manifestUrl, true);
52 xmlhttp.send();
53 };
54
54 setTimeout(() => { 55 setTimeout(() => {
55 getTeamIcon(); 56 getTeamIcon();
56 }, 4000); 57 }, 4000);