From 591a9a4ca229dcda6e54d4e24f79dfef14d0acc5 Mon Sep 17 00:00:00 2001 From: Iaroslav Date: Sat, 23 Oct 2021 19:13:55 +0500 Subject: Add setDialogTitle feature to api, WhatsApp and Telegram (#750) Co-authored-by: Vijay A --- recipes/whatsapp/webview.js | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) (limited to 'recipes/whatsapp/webview.js') diff --git a/recipes/whatsapp/webview.js b/recipes/whatsapp/webview.js index a908637..1c11edc 100644 --- a/recipes/whatsapp/webview.js +++ b/recipes/whatsapp/webview.js @@ -1,14 +1,17 @@ const _path = _interopRequireDefault(require('path')); -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { default: obj }; +} module.exports = (Ferdi, settings) => { const getMessages = () => { let count = 0; let indirectCount = 0; - const parentChatElem = [...document.querySelectorAll('div[aria-label]')] - .sort((a, b) => (a.offsetHeight < b.offsetHeight) ? 1 : -1)[0]; + const parentChatElem = [ + ...document.querySelectorAll('div[aria-label]'), + ].sort((a, b) => (a.offsetHeight < b.offsetHeight ? 1 : -1))[0]; if (!parentChatElem) { return; } @@ -17,7 +20,12 @@ module.exports = (Ferdi, settings) => { for (const unreadElem of unreadSpans) { const countValue = Ferdi.safeParseInt(unreadElem.textContent); if (countValue > 0) { - if (!unreadElem.parentNode.previousSibling || unreadElem.parentNode.previousSibling.querySelectorAll('[data-icon=muted]').length === 0) { + if ( + !unreadElem.parentNode.previousSibling || + unreadElem.parentNode.previousSibling.querySelectorAll( + '[data-icon=muted]', + ).length === 0 + ) { count += countValue; } else { indirectCount += countValue; @@ -28,12 +36,31 @@ module.exports = (Ferdi, settings) => { Ferdi.setBadge(count, indirectCount); }; + const getActiveDialogTitle = () => { + const element = document.querySelector('header .emoji-texttt'); + + Ferdi.setDialogTitle(element ? element.textContent : ''); + }; + + const loopFunc = () => { + getMessages(); + getActiveDialogTitle(); + }; + window.addEventListener('beforeunload', async () => { - Ferdi.clearStorageData(settings.id, { storages: ['appcache', 'serviceworkers', 'cachestorage', 'websql', 'indexdb'] }); + Ferdi.clearStorageData(settings.id, { + storages: [ + 'appcache', + 'serviceworkers', + 'cachestorage', + 'websql', + 'indexdb', + ], + }); Ferdi.releaseServiceWorkers(); }); - Ferdi.loop(getMessages); + Ferdi.loop(loopFunc); Ferdi.injectCSS(_path.default.join(__dirname, 'service.css')); }; -- cgit v1.2.3-70-g09d2