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/slack/webview.js | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) (limited to 'recipes/slack/webview.js') 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] : ''; } -- cgit v1.2.3-70-g09d2