From 6f5e4a00588aefdda7a5a1cfe70935870e7e234a Mon Sep 17 00:00:00 2001 From: Bennett Date: Tue, 22 Sep 2020 20:56:48 +0200 Subject: Unpack recipes and update recipes icons (#292) Co-authored-by: Amine Mouafik --- recipes/workplace/webview.js | 51 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 recipes/workplace/webview.js (limited to 'recipes/workplace/webview.js') 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 @@ +"use strict"; + +const path = require('path'); + +module.exports = Franz => { + const getMessages = () => { + let direct = 0; + let indirect = 0; + const chatsElement = document.querySelector('#chats'); + const notifications = document.querySelector('#notifications span span'); + + if (notifications) { + indirect = parseInt(notifications.innerText, 10); + } + + if (chatsElement) { + if (!chatsElement.hasAttribute('aria-current')) { + const chatMessages = chatsElement.querySelector('span'); + + if (chatMessages) { + direct = parseInt(chatMessages.innerText, 10); + } + } else { + direct = document.querySelectorAll('[data-pagelet="WorkGalahadChannel"] .uiList [role="gridcell"] [role="button"] .oxk9n0fw').length; + } + } + + Franz.setBadge(direct, indirect); + }; + + Franz.injectCSS(path.join(__dirname, 'workplace.css')); + Franz.loop(getMessages); + localStorage._cs_desktopNotifsEnabled = JSON.stringify({ + __t: new Date().getTime(), + __v: true + }); + + if (typeof Franz.onNotify === 'function') { + Franz.onNotify(notification => { + if (typeof notification.title !== 'string') { + notification.title = ((notification.title.props || {}).content || [])[0] || 'Work Chat'; + } + + if (typeof notification.options.body !== 'string') { + notification.options.body = (((notification.options.body || {}).props || {}).content || [])[0] || ''; + } + + return notification; + }); + } +}; \ No newline at end of file -- cgit v1.2.3-70-g09d2