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/gmail/webview.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 recipes/gmail/webview.js (limited to 'recipes/gmail/webview.js') diff --git a/recipes/gmail/webview.js b/recipes/gmail/webview.js new file mode 100644 index 0000000..95d28e7 --- /dev/null +++ b/recipes/gmail/webview.js @@ -0,0 +1,31 @@ +const path = require("path"); + +module.exports = (Franz) => { + // if the user is on gmail's landing page, go to the login page. + if (location.hostname == 'www.google.com' && location.href.includes("gmail/about/")) { + location.href = 'https://accounts.google.com/AccountChooser?service=mail&continue=https://mail.google.com/mail/'; + } + + const getMessages = function getMessages() { + let count = 0; + + if (document.getElementsByClassName('J-Ke n0').length > 0) { + if (document.getElementsByClassName('J-Ke n0')[0].getAttribute('aria-label') != null) { + count = parseInt(document.getElementsByClassName('J-Ke n0')[0].getAttribute('aria-label').replace(/[^0-9.]/g, ''), 10); + } + } + + // Just incase we don't end up with a number, set it back to zero (parseInt can return NaN) + count = parseInt(count, 10); + if (isNaN(count)) { + count = 0; + } + + // set Franz badge + Franz.setBadge(count); + }; + + Franz.injectCSS(path.join(__dirname, 'service.css')); + // check for new messages every second and update Franz badge + Franz.loop(getMessages); +}; -- cgit v1.2.3-54-g00ecf