diff options
Diffstat (limited to 'uncompressed/rocketchat/webview.js')
-rw-r--r-- | uncompressed/rocketchat/webview.js | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/uncompressed/rocketchat/webview.js b/uncompressed/rocketchat/webview.js new file mode 100644 index 0000000..1e26ac9 --- /dev/null +++ b/uncompressed/rocketchat/webview.js | |||
@@ -0,0 +1,49 @@ | |||
1 | 'use strict'; | ||
2 | |||
3 | const { ipcRenderer } = require('electron'); | ||
4 | |||
5 | const getTeamIcon = function getTeamIcon() { | ||
6 | console.log('getTeamIcon'); | ||
7 | |||
8 | const manifestElement = document.querySelector('link[rel="manifest"]'); | ||
9 | |||
10 | if (manifestElement == null) { | ||
11 | return; | ||
12 | } | ||
13 | |||
14 | const manifestUrl = manifestElement.getAttribute('href'); | ||
15 | |||
16 | if (manifestUrl == null) { | ||
17 | return; | ||
18 | } | ||
19 | |||
20 | const xmlhttp = new XMLHttpRequest(); | ||
21 | xmlhttp.onreadystatechange = function () { | ||
22 | if (this.readyState != 4 || this.status != 200) { | ||
23 | return; | ||
24 | } | ||
25 | |||
26 | const response = JSON.parse(this.responseText); | ||
27 | |||
28 | if (response.icons.length >= 1) { | ||
29 | ipcRenderer.sendToHost('avatar', `${window.location.protocol}//${window.location.host}/${response.icons[0].src}`); | ||
30 | } | ||
31 | }; | ||
32 | xmlhttp.open('GET', manifestUrl, true); | ||
33 | xmlhttp.send(); | ||
34 | }; | ||
35 | |||
36 | module.exports = Franz => { | ||
37 | const getMessages = function getMessages() { | ||
38 | const directMessages = Math.round(document.querySelectorAll('.unread.unread-mention, .badge--unread').length / 2); | ||
39 | const indirectMessages = Math.round(document.querySelectorAll('.unread:not(.unread-mention), .sidebar-item--unread').length / 2); | ||
40 | Franz.setBadge(directMessages, indirectMessages); | ||
41 | }; | ||
42 | |||
43 | Franz.loop(getMessages); | ||
44 | |||
45 | setTimeout(() => { | ||
46 | getTeamIcon(); | ||
47 | }, 4000); | ||
48 | }; | ||
49 | //# sourceMappingURL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