-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsnippet.js
42 lines (37 loc) · 1.63 KB
/
snippet.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// START MASHUPMILL/SLACK-THEMES -- DO NOT MODIFY
const enableDarkMode = true;
if (enableDarkMode) {
const fetchCss = url => fetch(url).then(response => response.text());
// Slack Night Mood theme
document.addEventListener("DOMContentLoaded", function() {
// Then get its webviews
let webviews = document.querySelectorAll(".TeamView webview");
const cssUrls = [`https://raw.githubusercontent.com/MashupMill/slack-themes/master/black.css?_=BUST_A_CACHE`, `https://raw.githubusercontent.com/MashupMill/slack-themes/master/theme-black.css?_=BUST_A_CACHE`];
const cssPromise = Promise.all(cssUrls.map(url => fetchCss(url))).then(cssFiles => cssFiles.join("\n"));
// Insert a style tag into the wrapper view
cssPromise.then(css => {
let s = document.createElement('style');
s.type = 'text/css';
s.innerHTML = css;
document.head.appendChild(s);
});
// Wait for each webview to load
webviews.forEach(webview => {
webview.addEventListener('ipc-message', message => {
if (message.channel == 'didFinishLoading')
// Finally add the CSS into the webview
cssPromise.then(css => {
let script = `
let s = document.createElement('style');
s.type = 'text/css';
s.id = 'slack-custom-css';
s.innerHTML = \`${css}\`;
document.head.appendChild(s);
`;
webview.executeJavaScript(script);
})
});
});
});
}
// END MASHUPMILL/SLACK-THEMES -- DO NOT MODIFY