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/office365-owa/webview.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 recipes/office365-owa/webview.js (limited to 'recipes/office365-owa/webview.js') diff --git a/recipes/office365-owa/webview.js b/recipes/office365-owa/webview.js new file mode 100644 index 0000000..ae21e19 --- /dev/null +++ b/recipes/office365-owa/webview.js @@ -0,0 +1,33 @@ +'use strict'; + +module.exports = Franz => { + const getMessages = function getMessages() { + let unreadMail = 0; + + if (location.pathname.match(/\/owa/)) { + // classic app + unreadMail = parseInt( + jQuery("span[title*='Inbox'] + div > span") + .first() + .text(), + 10 + ); + } else { + // new app + const folders = document.querySelector('div[title="Folders"]'); + if (!folders) { + return; + } + + unreadMail = [...folders.parentNode.parentNode.children].reduce((count, child) => { + const unread = child.querySelector('.screenReaderOnly'); + return unread && unread.textContent === 'unread' + ? count + parseInt(unread.previousSibling.textContent, 10) + : count; + }, 0); + } + + Franz.setBadge(unreadMail); + }; + Franz.loop(getMessages); +}; -- cgit v1.2.3-70-g09d2