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