diff options
Diffstat (limited to 'recipes/skype/webview.js')
-rw-r--r-- | recipes/skype/webview.js | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/recipes/skype/webview.js b/recipes/skype/webview.js new file mode 100644 index 0000000..93a3613 --- /dev/null +++ b/recipes/skype/webview.js | |||
@@ -0,0 +1,107 @@ | |||
1 | "use strict"; | ||
2 | |||
3 | const { desktopCapturer, remote: { BrowserWindow } } = require("electron"); | ||
4 | const path = require('path'); | ||
5 | |||
6 | window.navigator.mediaDevices.getDisplayMedia = () => { | ||
7 | return new Promise(async (resolve, reject) => { | ||
8 | try { | ||
9 | const sources = await desktopCapturer.getSources({ types: ['screen', 'window'] }); | ||
10 | |||
11 | const selectionElem = document.createElement('div'); | ||
12 | selectionElem.classList = 'desktop-capturer-selection'; | ||
13 | selectionElem.innerHTML = ` | ||
14 | <div class="desktop-capturer-selection__scroller"> | ||
15 | <ul class="desktop-capturer-selection__list"> | ||
16 | ${sources.map(({ id, name, thumbnail, display_id, appIcon }) => ` | ||
17 | <li class="desktop-capturer-selection__item"> | ||
18 | <button class="desktop-capturer-selection__btn" data-id="${id}" title="${name}"> | ||
19 | <img class="desktop-capturer-selection__thumbnail" src="${thumbnail.toDataURL()}" /> | ||
20 | <span class="desktop-capturer-selection__name">${name}</span> | ||
21 | </button> | ||
22 | </li> | ||
23 | `).join('')} | ||
24 | </ul> | ||
25 | </div> | ||
26 | `; | ||
27 | document.body.appendChild(selectionElem); | ||
28 | |||
29 | document.querySelectorAll('.desktop-capturer-selection__btn') | ||
30 | .forEach(button => { | ||
31 | button.addEventListener('click', async () => { | ||
32 | try { | ||
33 | const id = button.getAttribute('data-id'); | ||
34 | const source = sources.find(source => source.id === id); | ||
35 | if (!source) { | ||
36 | throw new Error(`Source with id ${id} does not exist`); | ||
37 | } | ||
38 | |||
39 | const stream = await window.navigator.mediaDevices.getUserMedia({ | ||
40 | audio: false, | ||
41 | video: { | ||
42 | mandatory: { | ||
43 | chromeMediaSource: 'desktop', | ||
44 | chromeMediaSourceId: source.id | ||
45 | } | ||
46 | } | ||
47 | }); | ||
48 | resolve(stream); | ||
49 | |||
50 | selectionElem.remove(); | ||
51 | } catch (err) { | ||
52 | reject(err); | ||
53 | } | ||
54 | }); | ||
55 | }); | ||
56 | } catch (err) { | ||
57 | reject(err); | ||
58 | } | ||
59 | }) | ||
60 | } | ||
61 | |||
62 | module.exports = (Franz, settings) => { | ||
63 | const getMessages = function getMessages() { | ||
64 | let count = 0; | ||
65 | const container = document.querySelector('[role="tablist"] > [title="Chats"] > div'); | ||
66 | |||
67 | if (container) { | ||
68 | const children = container.children; | ||
69 | |||
70 | if (children.length === 3) { | ||
71 | const elementContainer = children[children.length - 1]; | ||
72 | |||
73 | if (elementContainer) { | ||
74 | const element = elementContainer.querySelector('[data-text-as-pseudo-element]'); | ||
75 | count = parseInt(element.dataset.textAsPseudoElement, 10); | ||
76 | } | ||
77 | } | ||
78 | } | ||
79 | |||
80 | Franz.setBadge(count); | ||
81 | }; | ||
82 | |||
83 | Franz.injectCSS(path.join(__dirname, 'service.css')); | ||
84 | Franz.loop(getMessages); | ||
85 | document.addEventListener('click', event => { | ||
86 | const link = event.target.closest('a[href^="http"]'); | ||
87 | const button = event.target.closest('button[title^="http"]'); | ||
88 | |||
89 | if (link || button) { | ||
90 | const url = link ? link.getAttribute('href') : button.getAttribute('title'); | ||
91 | |||
92 | if (url.includes('views/imgpsh_fullsize_anim')) { | ||
93 | event.preventDefault(); | ||
94 | event.stopPropagation(); | ||
95 | let win = new BrowserWindow({ | ||
96 | width: 800, | ||
97 | height: window.innerHeight, | ||
98 | minWidth: 600, | ||
99 | webPreferences: { | ||
100 | partition: `persist:service-${settings.id}` | ||
101 | } | ||
102 | }); | ||
103 | win.loadURL(url); | ||
104 | } | ||
105 | } | ||
106 | }, true); | ||
107 | }; | ||