From 87731bd4a54dc3c40e0188d790d0f430cacf1ef6 Mon Sep 17 00:00:00 2001 From: Iaroslav Date: Tue, 26 Oct 2021 07:59:12 +0500 Subject: Add dialog title for VK, FB and Slack (#753) --- recipes/facebook/package.json | 2 +- recipes/facebook/webview.js | 20 +++++++++++++++++++- recipes/slack/package.json | 2 +- recipes/slack/webview.js | 40 +++++++++++++++++++++++++++++++++------- recipes/vk/package.json | 2 +- recipes/vk/webview.js | 18 +++++++++++++++++- 6 files changed, 72 insertions(+), 12 deletions(-) (limited to 'recipes') diff --git a/recipes/facebook/package.json b/recipes/facebook/package.json index 2f5a54a..53bc486 100755 --- a/recipes/facebook/package.json +++ b/recipes/facebook/package.json @@ -1,7 +1,7 @@ { "id": "facebook", "name": "Facebook", - "version": "1.1.1", + "version": "1.1.2", "license": "MIT", "config": { "serviceURL": "https://www.facebook.com/login" diff --git a/recipes/facebook/webview.js b/recipes/facebook/webview.js index b38a2fb..3100935 100755 --- a/recipes/facebook/webview.js +++ b/recipes/facebook/webview.js @@ -20,5 +20,23 @@ module.exports = Ferdi => { Ferdi.setBadge(count); }; - Ferdi.loop(getNotifications); + const getActiveDialogTitle = () => { + const element = [ + document.querySelector( + '.cbu4d94t:not(.kr9hpln1) .l9j0dhe7 .pfnyh3mw .g5gj957u .ni8dbmo4.stjgntxs.g0qnabr5.ltmttdrg.ekzkrbhg.mdldhsdk.oo9gr5id', + ), + document.querySelector( + '.j83agx80.cbu4d94t.d6urw2fd.dp1hu0rb.l9j0dhe7.du4w35lb:not(.kr9hpln1) .rq0escxv[role="main"] .t6p9ggj4.tkr6xdv7 .d2edcug0.j83agx80.bp9cbjyn.aahdfvyu.bi6gxh9e .a8c37x1j.ni8dbmo4.stjgntxs.l9j0dhe7.ltmttdrg.g0qnabr5.ojkyduve a.lzcic4wl.gmql0nx0.gpro0wi8.lrazzd5p', + ), + ].find(Boolean); + + Ferdi.setDialogTitle(element ? element.textContent : null); + }; + + const loopFunc = () => { + getNotifications(); + getActiveDialogTitle(); + }; + + Ferdi.loop(loopFunc); }; diff --git a/recipes/slack/package.json b/recipes/slack/package.json index db05b26..3a8f248 100644 --- a/recipes/slack/package.json +++ b/recipes/slack/package.json @@ -1,7 +1,7 @@ { "id": "slack", "name": "Slack", - "version": "1.3.2", + "version": "1.3.3", "license": "MIT", "config": { "serviceURL": "https://{teamId}.slack.com", diff --git a/recipes/slack/webview.js b/recipes/slack/webview.js index f436ba9..924784d 100644 --- a/recipes/slack/webview.js +++ b/recipes/slack/webview.js @@ -1,29 +1,55 @@ 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 }; +} -const SELECTOR_CHANNELS_UNREAD = '.p-channel_sidebar__channel--unread:not(.p-channel_sidebar__channel--muted)'; +const SELECTOR_CHANNELS_UNREAD = + '.p-channel_sidebar__channel--unread:not(.p-channel_sidebar__channel--muted)'; module.exports = Ferdi => { const getMessages = () => { - const directMessages = document.querySelectorAll(`${SELECTOR_CHANNELS_UNREAD} .p-channel_sidebar__badge, .p-channel_sidebar__link--unread:not([data-sidebar-link-id="Punreads"]):not([data-sidebar-link-id="Pdrafts"]):not([data-sidebar-link-id="Pdms"])`).length; - const allMessages = document.querySelectorAll(SELECTOR_CHANNELS_UNREAD).length - directMessages; + const directMessages = document.querySelectorAll( + `${SELECTOR_CHANNELS_UNREAD} .p-channel_sidebar__badge, .p-channel_sidebar__link--unread:not([data-sidebar-link-id="Punreads"]):not([data-sidebar-link-id="Pdrafts"]):not([data-sidebar-link-id="Pdms"])`, + ).length; + const allMessages = + document.querySelectorAll(SELECTOR_CHANNELS_UNREAD).length - + directMessages; Ferdi.setBadge(directMessages, allMessages); }; - Ferdi.loop(getMessages); + const getActiveDialogTitle = () => { + const element = document.querySelector( + '.p-channel_sidebar__channel--selected .p-channel_sidebar__name', + ); + + Ferdi.setDialogTitle( + element && element.firstChild ? element.firstChild.textContent : null, + ); + }; + + const loopFunc = () => { + getMessages(); + getActiveDialogTitle(); + }; + + Ferdi.loop(loopFunc); const getTeamIcon = function getTeamIcon(count = 0) { let countTeamIconCheck = count; let bgUrl = null; - const teamMenu = document.querySelector('#team-menu-trigger, .p-ia__sidebar_header__team_name'); + const teamMenu = document.querySelector( + '#team-menu-trigger, .p-ia__sidebar_header__team_name', + ); if (teamMenu) { teamMenu.click(); const icon = document.querySelector('.c-team_icon'); if (icon) { - bgUrl = window.getComputedStyle(icon, null).getPropertyValue('background-image'); + bgUrl = window + .getComputedStyle(icon, null) + .getPropertyValue('background-image'); bgUrl = /^url\((["']?)(.*)\1\)$/.exec(bgUrl); bgUrl = bgUrl ? bgUrl[2] : ''; } diff --git a/recipes/vk/package.json b/recipes/vk/package.json index e4b7dfa..e61c166 100644 --- a/recipes/vk/package.json +++ b/recipes/vk/package.json @@ -1,7 +1,7 @@ { "id": "vk", "name": "VK", - "version": "1.1.2", + "version": "1.1.3", "license": "MIT", "repository": "https://github.com/meetfranz/recipe-vk", "config": { diff --git a/recipes/vk/webview.js b/recipes/vk/webview.js index decec13..6756363 100644 --- a/recipes/vk/webview.js +++ b/recipes/vk/webview.js @@ -9,5 +9,21 @@ module.exports = Ferdi => { Ferdi.setBadge(directs); }; - Ferdi.loop(getMessages); + const getActiveDialogTitle = () => { + const element = [ + document.querySelector( + '.FCWindow--active .FCWindow__title .ConvoTitle__title', + ), + document.querySelector('.im-page_history-show ._im_page_peer_name'), + ].find(Boolean); + + Ferdi.setDialogTitle(element ? element.textContent : null); + }; + + const loopFunc = () => { + getMessages(); + getActiveDialogTitle(); + }; + + Ferdi.loop(loopFunc); }; -- cgit v1.2.3-54-g00ecf