From 2b0ddd3516b0c329087707bebeaa2bea50f5f724 Mon Sep 17 00:00:00 2001 From: Jonathan Weber Date: Thu, 23 Dec 2021 17:00:32 +0100 Subject: Use the Zoho Mail JS API instead of outdated HTML elements (#791) --- recipes/zoho/package.json | 2 +- recipes/zoho/webview-unsafe.js | 12 ++++++++++++ recipes/zoho/webview.js | 21 +++++++++++++++++---- 3 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 recipes/zoho/webview-unsafe.js (limited to 'recipes') diff --git a/recipes/zoho/package.json b/recipes/zoho/package.json index 0ad72c0..e6e8823 100644 --- a/recipes/zoho/package.json +++ b/recipes/zoho/package.json @@ -1,7 +1,7 @@ { "id": "zoho", "name": "Zoho Mail", - "version": "1.1.0", + "version": "1.2.0", "license": "MIT", "config": { "serviceURL": "https://www.zoho.com/mail/login.html", diff --git a/recipes/zoho/webview-unsafe.js b/recipes/zoho/webview-unsafe.js new file mode 100644 index 0000000..e4026c5 --- /dev/null +++ b/recipes/zoho/webview-unsafe.js @@ -0,0 +1,12 @@ +//wait for Ferdi and Zoho Mail to initialize +if ( + Object.prototype.hasOwnProperty.call(window, "ferdi") && + Object.prototype.hasOwnProperty.call(window.ferdi, "setBadge") && + Object.prototype.hasOwnProperty.call(window, "zmNCenter") && + Object.prototype.hasOwnProperty.call(window, "zmfolAction") +) { + var unreadNotifications = window.zmNCenter.counter.count(); //General Notifications by Zoho (Bell Icon) + var unreadMail = window.zmfolAction.getUnreadViewCount(); //Unread messages count + + window.ferdi.setBadge(unreadMail, unreadNotifications); +} \ No newline at end of file diff --git a/recipes/zoho/webview.js b/recipes/zoho/webview.js index 177ea4c..7c833a3 100644 --- a/recipes/zoho/webview.js +++ b/recipes/zoho/webview.js @@ -1,10 +1,23 @@ +const _path = _interopRequireDefault(require('path')); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + module.exports = (Ferdi) => { const getMessages = () => { - const unreadMailInCurrentFolder = $('.zmList.zmLUrd').length; - const unreadMailAnyware = $('#zmlTree .zmTreeNDWra .zmBold').length; - - Ferdi.setBadge(unreadMailInCurrentFolder, unreadMailAnyware); + Ferdi.injectJSUnsafe(_path.default.join(__dirname, 'webview-unsafe.js')); }; + //Zoho uses different URLs for different regions. Find out which region the account belongs to and redirect to the correct URL. + const redirectRegion = () => { + if (window.location.href === "https://www.zoho.com/mail/login.html") { + const btn = document.querySelectorAll(".access-apps"); + if (btn.length > 0) { + window.location.assign(btn[0].href + "zm/"); + } + } + } + + window.addEventListener('load', redirectRegion); Ferdi.loop(getMessages); + }; -- cgit v1.2.3-54-g00ecf