aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/workplace/webview.js
diff options
context:
space:
mode:
Diffstat (limited to 'recipes/workplace/webview.js')
-rw-r--r--recipes/workplace/webview.js51
1 files changed, 51 insertions, 0 deletions
diff --git a/recipes/workplace/webview.js b/recipes/workplace/webview.js
new file mode 100644
index 0000000..a26515e
--- /dev/null
+++ b/recipes/workplace/webview.js
@@ -0,0 +1,51 @@
1"use strict";
2
3const path = require('path');
4
5module.exports = Franz => {
6 const getMessages = () => {
7 let direct = 0;
8 let indirect = 0;
9 const chatsElement = document.querySelector('#chats');
10 const notifications = document.querySelector('#notifications span span');
11
12 if (notifications) {
13 indirect = parseInt(notifications.innerText, 10);
14 }
15
16 if (chatsElement) {
17 if (!chatsElement.hasAttribute('aria-current')) {
18 const chatMessages = chatsElement.querySelector('span');
19
20 if (chatMessages) {
21 direct = parseInt(chatMessages.innerText, 10);
22 }
23 } else {
24 direct = document.querySelectorAll('[data-pagelet="WorkGalahadChannel"] .uiList [role="gridcell"] [role="button"] .oxk9n0fw').length;
25 }
26 }
27
28 Franz.setBadge(direct, indirect);
29 };
30
31 Franz.injectCSS(path.join(__dirname, 'workplace.css'));
32 Franz.loop(getMessages);
33 localStorage._cs_desktopNotifsEnabled = JSON.stringify({
34 __t: new Date().getTime(),
35 __v: true
36 });
37
38 if (typeof Franz.onNotify === 'function') {
39 Franz.onNotify(notification => {
40 if (typeof notification.title !== 'string') {
41 notification.title = ((notification.title.props || {}).content || [])[0] || 'Work Chat';
42 }
43
44 if (typeof notification.options.body !== 'string') {
45 notification.options.body = (((notification.options.body || {}).props || {}).content || [])[0] || '';
46 }
47
48 return notification;
49 });
50 }
51}; \ No newline at end of file