Last active
February 15, 2019 17:34
-
-
Save Gungthar/cc54b8cfe3d3578ca2740a51e67b4c82 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// First make sure the wrapper app is loaded | |
document.addEventListener("DOMContentLoaded", function() { | |
// Then get its webviews | |
let webviews = document.querySelectorAll(".TeamView webview"); | |
// Fetch our CSS in parallel ahead of time | |
const cssPath = 'https://gist.githubusercontent.com/Gungthar/30716df122a6919f4377f91f828b2652/raw'; | |
let cssPromise = fetch(cssPath).then(response => response.text()); | |
let customCustomCSS = ` | |
:root { | |
/* Modify these to change your theme colors: */ | |
--primary: #8EF03B; | |
--text: #CCC; | |
--background: #080808; | |
--background-elevated: #222; | |
} | |
` | |
// Insert a style tag into the wrapper view | |
cssPromise.then(css => { | |
let s = document.createElement('style'); | |
s.type = 'text/css'; | |
s.innerHTML = css + customCustomCSS; | |
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 + customCustomCSS}\`; | |
document.head.appendChild(s); | |
` | |
webview.executeJavaScript(script); | |
}) | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment