diff options
Diffstat (limited to 'recipes/slack/webview.js')
-rw-r--r-- | recipes/slack/webview.js | 40 |
1 files changed, 33 insertions, 7 deletions
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 @@ | |||
1 | const _path = _interopRequireDefault(require('path')); | 1 | const _path = _interopRequireDefault(require('path')); |
2 | 2 | ||
3 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | 3 | function _interopRequireDefault(obj) { |
4 | return obj && obj.__esModule ? obj : { default: obj }; | ||
5 | } | ||
4 | 6 | ||
5 | const SELECTOR_CHANNELS_UNREAD = '.p-channel_sidebar__channel--unread:not(.p-channel_sidebar__channel--muted)'; | 7 | const SELECTOR_CHANNELS_UNREAD = |
8 | '.p-channel_sidebar__channel--unread:not(.p-channel_sidebar__channel--muted)'; | ||
6 | 9 | ||
7 | module.exports = Ferdi => { | 10 | module.exports = Ferdi => { |
8 | const getMessages = () => { | 11 | const getMessages = () => { |
9 | 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; | 12 | const directMessages = document.querySelectorAll( |
10 | const allMessages = document.querySelectorAll(SELECTOR_CHANNELS_UNREAD).length - directMessages; | 13 | `${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"])`, |
14 | ).length; | ||
15 | const allMessages = | ||
16 | document.querySelectorAll(SELECTOR_CHANNELS_UNREAD).length - | ||
17 | directMessages; | ||
11 | Ferdi.setBadge(directMessages, allMessages); | 18 | Ferdi.setBadge(directMessages, allMessages); |
12 | }; | 19 | }; |
13 | 20 | ||
14 | Ferdi.loop(getMessages); | 21 | const getActiveDialogTitle = () => { |
22 | const element = document.querySelector( | ||
23 | '.p-channel_sidebar__channel--selected .p-channel_sidebar__name', | ||
24 | ); | ||
25 | |||
26 | Ferdi.setDialogTitle( | ||
27 | element && element.firstChild ? element.firstChild.textContent : null, | ||
28 | ); | ||
29 | }; | ||
30 | |||
31 | const loopFunc = () => { | ||
32 | getMessages(); | ||
33 | getActiveDialogTitle(); | ||
34 | }; | ||
35 | |||
36 | Ferdi.loop(loopFunc); | ||
15 | 37 | ||
16 | const getTeamIcon = function getTeamIcon(count = 0) { | 38 | const getTeamIcon = function getTeamIcon(count = 0) { |
17 | let countTeamIconCheck = count; | 39 | let countTeamIconCheck = count; |
18 | let bgUrl = null; | 40 | let bgUrl = null; |
19 | const teamMenu = document.querySelector('#team-menu-trigger, .p-ia__sidebar_header__team_name'); | 41 | const teamMenu = document.querySelector( |
42 | '#team-menu-trigger, .p-ia__sidebar_header__team_name', | ||
43 | ); | ||
20 | 44 | ||
21 | if (teamMenu) { | 45 | if (teamMenu) { |
22 | teamMenu.click(); | 46 | teamMenu.click(); |
23 | const icon = document.querySelector('.c-team_icon'); | 47 | const icon = document.querySelector('.c-team_icon'); |
24 | 48 | ||
25 | if (icon) { | 49 | if (icon) { |
26 | bgUrl = window.getComputedStyle(icon, null).getPropertyValue('background-image'); | 50 | bgUrl = window |
51 | .getComputedStyle(icon, null) | ||
52 | .getPropertyValue('background-image'); | ||
27 | bgUrl = /^url\((["']?)(.*)\1\)$/.exec(bgUrl); | 53 | bgUrl = /^url\((["']?)(.*)\1\)$/.exec(bgUrl); |
28 | bgUrl = bgUrl ? bgUrl[2] : ''; | 54 | bgUrl = bgUrl ? bgUrl[2] : ''; |
29 | } | 55 | } |