diff options
Diffstat (limited to 'recipes/discord')
-rw-r--r-- | recipes/discord/package.json | 2 | ||||
-rw-r--r-- | recipes/discord/webview.js | 95 |
2 files changed, 50 insertions, 47 deletions
diff --git a/recipes/discord/package.json b/recipes/discord/package.json index a9fe8dd..175b4ce 100644 --- a/recipes/discord/package.json +++ b/recipes/discord/package.json | |||
@@ -1,7 +1,7 @@ | |||
1 | { | 1 | { |
2 | "id": "discord", | 2 | "id": "discord", |
3 | "name": "Discord", | 3 | "name": "Discord", |
4 | "version": "1.4.4", | 4 | "version": "1.4.5", |
5 | "license": "MIT", | 5 | "license": "MIT", |
6 | "config": { | 6 | "config": { |
7 | "serviceURL": "https://discordapp.com/login", | 7 | "serviceURL": "https://discordapp.com/login", |
diff --git a/recipes/discord/webview.js b/recipes/discord/webview.js index 2687948..cf13cc9 100644 --- a/recipes/discord/webview.js +++ b/recipes/discord/webview.js | |||
@@ -1,28 +1,25 @@ | |||
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 | module.exports = (Ferdi, settings) => { | 7 | module.exports = (Ferdi, settings) => { |
6 | const getMessages = () => { | 8 | const getMessages = () => { |
7 | let count = 0; | 9 | let directCount = 0; |
8 | const container = document.querySelector('[role="tablist"] > [title="Chats"] > div'); | 10 | const directCountPerServer = document.querySelectorAll( |
11 | '[class*="lowerBadge-"] [class*="numberBadge-"]', | ||
12 | ); | ||
9 | 13 | ||
10 | if (container) { | 14 | for (const directCountBadge of directCountPerServer) { |
11 | const children = container.children; | 15 | directCount += Ferdi.safeParseInt(directCountBadge.textContent); |
12 | |||
13 | if (children.length === 3) { | ||
14 | const elementContainer = children[children.length - 1]; | ||
15 | |||
16 | if (elementContainer) { | ||
17 | const element = elementContainer.querySelector('[data-text-as-pseudo-element]'); | ||
18 | if (element && element.dataset) { | ||
19 | count = Ferdi.safeParseInt(element.dataset.textAsPseudoElement); | ||
20 | } | ||
21 | } | ||
22 | } | ||
23 | } | 16 | } |
24 | 17 | ||
25 | Ferdi.setBadge(count); | 18 | const indirectCountPerServer = document.querySelectorAll( |
19 | '[class*="modeUnread-"]', | ||
20 | ).length; | ||
21 | |||
22 | Ferdi.setBadge(directCount, indirectCountPerServer); | ||
26 | }; | 23 | }; |
27 | 24 | ||
28 | Ferdi.loop(getMessages); | 25 | Ferdi.loop(getMessages); |
@@ -30,34 +27,40 @@ module.exports = (Ferdi, settings) => { | |||
30 | Ferdi.injectCSS(_path.default.join(__dirname, 'service.css')); | 27 | Ferdi.injectCSS(_path.default.join(__dirname, 'service.css')); |
31 | 28 | ||
32 | // TODO: This whole block is duplicated between the 'discord' and 'skype' recipes - reuse | 29 | // TODO: This whole block is duplicated between the 'discord' and 'skype' recipes - reuse |
33 | document.addEventListener('click', event => { | 30 | document.addEventListener( |
34 | const link = event.target.closest('a[href^="http"]'); | 31 | 'click', |
35 | const button = event.target.closest('button[title^="http"]'); | 32 | event => { |
36 | 33 | const link = event.target.closest('a[href^="http"]'); | |
37 | if (link || button) { | 34 | const button = event.target.closest('button[title^="http"]'); |
38 | const url = link ? link.getAttribute('href') : button.getAttribute('title'); | 35 | |
39 | 36 | if (link || button) { | |
40 | if (url.includes('views/imgpsh_fullsize_anim')) { | 37 | const url = link |
41 | event.preventDefault(); | 38 | ? link.getAttribute('href') |
42 | event.stopPropagation(); | 39 | : button.getAttribute('title'); |
43 | // TODO: Can we send an ipc event 'open-browser-window' to open the child window? (see the slack recipe for how to send an ipc message) | 40 | |
44 | // TODO: Can we change the slack recipe to add a clickHandler for screensharing/video calls? (https://github.com/getferdi/ferdi/issues/1697) | 41 | if (url.includes('views/imgpsh_fullsize_anim')) { |
45 | let win = new Ferdi.BrowserWindow({ | 42 | event.preventDefault(); |
46 | width: 800, | 43 | event.stopPropagation(); |
47 | height: window.innerHeight, | 44 | // TODO: Can we send an ipc event 'open-browser-window' to open the child window? (see the slack recipe for how to send an ipc message) |
48 | minWidth: 600, | 45 | // TODO: Can we change the slack recipe to add a clickHandler for screensharing/video calls? (https://github.com/getferdi/ferdi/issues/1697) |
49 | webPreferences: { | 46 | let win = new Ferdi.BrowserWindow({ |
50 | partition: `persist:service-${settings.id}` | 47 | width: 800, |
51 | // TODO: Aren't these needed here? | 48 | height: window.innerHeight, |
52 | // contextIsolation: false, | 49 | minWidth: 600, |
53 | // enableRemoteModule: true, | 50 | webPreferences: { |
54 | } | 51 | partition: `persist:service-${settings.id}`, |
55 | }); | 52 | // TODO: Aren't these needed here? |
56 | win.loadURL(url); | 53 | // contextIsolation: false, |
57 | win.on('closed', () => { | 54 | // enableRemoteModule: true, |
58 | win = null; | 55 | }, |
59 | }); | 56 | }); |
57 | win.loadURL(url); | ||
58 | win.on('closed', () => { | ||
59 | win = null; | ||
60 | }); | ||
61 | } | ||
60 | } | 62 | } |
61 | } | 63 | }, |
62 | }, true); | 64 | true, |
65 | ); | ||
63 | }; | 66 | }; |