From a57a4edcb648d025254ede4d18d267b887ad0b8b Mon Sep 17 00:00:00 2001 From: Vijay A Date: Sun, 5 Sep 2021 15:14:28 +0530 Subject: Remove dependency on 'require' of 'electron' and 'electron/remote' modules. Instead, use the exposed content from the recipe model in main ferdi. --- recipes/whatsapp/webview.js | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) (limited to 'recipes/whatsapp/webview.js') diff --git a/recipes/whatsapp/webview.js b/recipes/whatsapp/webview.js index 9b979d2..8087b08 100644 --- a/recipes/whatsapp/webview.js +++ b/recipes/whatsapp/webview.js @@ -1,14 +1,10 @@ -const { remote } = require('electron'); - const _path = _interopRequireDefault(require('path')); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } -const webContents = remote.getCurrentWebContents(); -const { session } = webContents; - window.addEventListener('beforeunload', async () => { try { + const { session } = Ferdi.getCurrentWebContents(); session.flushStorageData(); session.clearStorageData({ storages: ['appcache', 'serviceworkers', 'cachestorage', 'websql', 'indexdb'], @@ -28,20 +24,21 @@ module.exports = Ferdi => { let count = 0; let indirectCount = 0; - const parentChatElem = document.querySelector('#pane-side').children[0].children[0].children[0]; - if (!parentChatElem) return; - - const chatElems = parentChatElem.children; - for (let i = 0; i < chatElems.length; i++) { - const chatElem = chatElems[i]; - const unreadElem = chatElem.children[0].children[0].children[1].children[1].children[1]; + const parentChatElem = document.querySelector('[aria-label="Chat list"]'); + if (!parentChatElem) { + return; + } + const unreadSpans = parentChatElem.querySelectorAll('span[aria-label]'); + for (let i = 0; i < unreadSpans.length; i++) { + const unreadElem = unreadSpans[i]; const countValue = Ferdi.safeParseInt(unreadElem.textContent); - - if (unreadElem.querySelectorAll('[data-icon=muted]').length === 0) { - count += countValue; - } else { - indirectCount += countValue; + if (countValue > 0) { + if (!unreadElem.parentNode.previousSibling || unreadElem.parentNode.previousSibling.querySelectorAll('[data-icon=muted]').length === 0) { + count += countValue; + } else { + indirectCount += countValue; + } } } -- cgit v1.2.3-70-g09d2