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/element/webview.js | 8 ++++---- recipes/telegram/package.json | 2 +- recipes/telegram/webview.js | 23 +++++++++++++++++------ recipes/whatsapp/package.json | 2 +- recipes/whatsapp/webview.js | 39 +++++++++++++++++++++++++++++++++------ 5 files changed, 56 insertions(+), 18 deletions(-) (limited to 'recipes') diff --git a/recipes/element/webview.js b/recipes/element/webview.js index 771c758..75df4d9 100644 --- a/recipes/element/webview.js +++ b/recipes/element/webview.js @@ -9,7 +9,7 @@ module.exports = Ferdi => { let indirectCount = 0; // Count Badges depending on Element Settings if (avatarBadges.length > 0) { - avatarBadges.forEach(function(badge) { + for (const badge of avatarBadges) { if (badge.parentElement.getAttribute('class').includes('mx_NotificationBadge_highlighted')) { directCount = directCount + Ferdi.safeParseInt(badge.textContent); } else if (badge.parentElement.previousSibling != null && badge.parentElement.previousSibling.getAttribute('class').includes('mx_DecoratedRoomAvatar_icon_online')) { @@ -19,9 +19,9 @@ module.exports = Ferdi => { } else { indirectCount = indirectCount + Ferdi.safeParseInt(badge.textContent); } - }); + } } else { - spaceBadges.forEach(function(badge) { + for (const badge of spaceBadges) { if (badge.parentElement.getAttribute('class').includes('mx_NotificationBadge_highlighted')) { directCount = directCount + Ferdi.safeParseInt(badge.textContent); } else if (badge.parentElement.getAttribute('class').includes('mx_NotificationBadge_dot')) { @@ -29,7 +29,7 @@ module.exports = Ferdi => { } else { indirectCount = indirectCount + Ferdi.safeParseInt(badge.textContent); } - }); + } } // set Ferdi badge Ferdi.setBadge(directCount, indirectCount); diff --git a/recipes/telegram/package.json b/recipes/telegram/package.json index adb6de6..beda3c3 100644 --- a/recipes/telegram/package.json +++ b/recipes/telegram/package.json @@ -1,7 +1,7 @@ { "id": "telegram", "name": "Telegram", - "version": "3.2.2", + "version": "3.2.3", "license": "MIT", "config": { "serviceURL": "https://web.telegram.org", diff --git a/recipes/telegram/webview.js b/recipes/telegram/webview.js index 358bdaa..7d2c8e3 100644 --- a/recipes/telegram/webview.js +++ b/recipes/telegram/webview.js @@ -8,25 +8,36 @@ function _interopRequireDefault(obj) { module.exports = Ferdi => { const getMessages = () => { - let count = 0; - let count_sec = 0; + let direct = 0; + let indirect = 0; const elements = document.querySelectorAll('.rp'); for (const element of elements) { const subtitleBadge = element.querySelector('.dialog-subtitle-badge'); if (subtitleBadge) { const parsedValue = Ferdi.safeParseInt(subtitleBadge.textContent); if (element.dataset.peerId > 0) { - count += parsedValue; + direct += parsedValue; } else { - count_sec += parsedValue; + indirect += parsedValue; } } } - Ferdi.setBadge(count, count_sec); + Ferdi.setBadge(direct, indirect); }; - Ferdi.loop(getMessages); + const getActiveDialogTitle = () => { + const element = document.querySelector('.top .peer-title'); + + Ferdi.setDialogTitle(element ? element.textContent : ''); + }; + + const loopFunc = () => { + getMessages(); + getActiveDialogTitle(); + }; + + Ferdi.loop(loopFunc); Ferdi.injectCSS(_path.default.join(__dirname, 'service.css')); }; diff --git a/recipes/whatsapp/package.json b/recipes/whatsapp/package.json index 8f4aab7..208a3a8 100644 --- a/recipes/whatsapp/package.json +++ b/recipes/whatsapp/package.json @@ -1,7 +1,7 @@ { "id": "whatsapp", "name": "WhatsApp", - "version": "3.3.5", + "version": "3.3.6", "license": "MIT", "config": { "serviceURL": "https://web.whatsapp.com", 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-54-g00ecf