From 6f5e4a00588aefdda7a5a1cfe70935870e7e234a Mon Sep 17 00:00:00 2001 From: Bennett Date: Tue, 22 Sep 2020 20:56:48 +0200 Subject: Unpack recipes and update recipes icons (#292) Co-authored-by: Amine Mouafik --- recipes/slack/webview.js | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 recipes/slack/webview.js (limited to 'recipes/slack/webview.js') diff --git a/recipes/slack/webview.js b/recipes/slack/webview.js new file mode 100644 index 0000000..f7bccfc --- /dev/null +++ b/recipes/slack/webview.js @@ -0,0 +1,54 @@ +"use strict"; + +var _electron = require("electron"); + +var _path = _interopRequireDefault(require("path")); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +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'); + + if (teamMenu) { + teamMenu.click(); + const icon = document.querySelector('.c-team_icon'); + + if (icon) { + bgUrl = window.getComputedStyle(icon, null).getPropertyValue('background-image'); + bgUrl = /^url\((['"]?)(.*)\1\)$/.exec(bgUrl); + bgUrl = bgUrl ? bgUrl[2] : ''; + } + + setTimeout(() => { + document.querySelector('.ReactModal__Overlay').click(); + }, 10); + } + + countTeamIconCheck += 1; + + if (bgUrl) { + _electron.ipcRenderer.sendToHost('avatar', bgUrl); + } else if (countTeamIconCheck <= 5) { + setTimeout(() => { + getTeamIcon(countTeamIconCheck + 1); + }, 2000); + } +}; + +const SELECTOR_CHANNELS_UNREAD = '.p-channel_sidebar__channel--unread:not(.p-channel_sidebar__channel--muted)'; + +module.exports = Franz => { + 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; + Franz.setBadge(directMessages, allMessages); + }; + + Franz.loop(getMessages); + setTimeout(() => { + getTeamIcon(); + }, 4000); + Franz.injectCSS(_path.default.join(__dirname, 'service.css')); +}; -- cgit v1.2.3-70-g09d2