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/README.md | 5 +++++ recipes/slack/icon.png | Bin 0 -> 69225 bytes recipes/slack/icon.svg | 26 ++++++++++++++++++++++ recipes/slack/index.js | 3 +++ recipes/slack/package.json | 17 ++++++++++++++ recipes/slack/service.css | 3 +++ recipes/slack/webview.js | 54 +++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 108 insertions(+) create mode 100644 recipes/slack/README.md create mode 100644 recipes/slack/icon.png create mode 100644 recipes/slack/icon.svg create mode 100644 recipes/slack/index.js create mode 100644 recipes/slack/package.json create mode 100644 recipes/slack/service.css create mode 100644 recipes/slack/webview.js (limited to 'recipes/slack') diff --git a/recipes/slack/README.md b/recipes/slack/README.md new file mode 100644 index 0000000..ef51d64 --- /dev/null +++ b/recipes/slack/README.md @@ -0,0 +1,5 @@ +# Slack for Franz +This is the official Franz recipe for Slack + +### How to create your own Franz recipes: +* [Read the documentation](https://github.com/meetfranz/plugins) diff --git a/recipes/slack/icon.png b/recipes/slack/icon.png new file mode 100644 index 0000000..ed56a11 Binary files /dev/null and b/recipes/slack/icon.png differ diff --git a/recipes/slack/icon.svg b/recipes/slack/icon.svg new file mode 100644 index 0000000..97b01f1 --- /dev/null +++ b/recipes/slack/icon.svg @@ -0,0 +1,26 @@ + + + + Service/Slack + Created with Sketch. + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/recipes/slack/index.js b/recipes/slack/index.js new file mode 100644 index 0000000..e8243fb --- /dev/null +++ b/recipes/slack/index.js @@ -0,0 +1,3 @@ +"use strict"; + +module.exports = Franz => Franz; \ No newline at end of file diff --git a/recipes/slack/package.json b/recipes/slack/package.json new file mode 100644 index 0000000..8463e88 --- /dev/null +++ b/recipes/slack/package.json @@ -0,0 +1,17 @@ +{ + "id": "slack", + "name": "Slack", + "version": "1.0.16", + "description": "Slack", + "main": "index.js", + "author": "Stefan Malzner ", + "license": "MIT", + "config": { + "serviceURL": "https://{teamId}.slack.com", + "hasNotificationSound": true, + "hasDirectMessages": true, + "hasIndirectMessages": true, + "hasTeamId": true, + "urlInputSuffix": ".slack.com" + } +} diff --git a/recipes/slack/service.css b/recipes/slack/service.css new file mode 100644 index 0000000..1dd6209 --- /dev/null +++ b/recipes/slack/service.css @@ -0,0 +1,3 @@ +#banner { + display: none !important; +} \ No newline at end of file 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