Created
June 11, 2019 16:24
-
-
Save stevenpdq/a1dfa6584bcf29d670c25c53ffc7616a to your computer and use it in GitHub Desktop.
Applies dark theme to Slack
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
# Find ssb-interop.js file thata needs to be patched | |
# Test-Path Machine-Wide 64-bit install | |
If (Test-Path "C:\Program Files\Slack\resources\app.asar.unpacked\src\static\ssb-interop.js") { | |
$ssbinteropPath = "C:\Program Files\Slack\resources\app.asar.unpacked\src\static\ssb-interop.js" | |
$exePath = "C:\Program Files\Slack\Slack.exe" | |
} | |
# Test-Path Machine-Wide 32-bit install | |
ElseIf (Test-Path "C:\Program Files (x86)\Slack\resources\app.asar.unpacked\src\static\ssb-interop.js") { | |
$ssbinteropPath = "C:\Program Files (x86)\Slack\resources\app.asar.unpacked\src\static\ssb-interop.js" | |
$exePath = "C:\Program Files (x86)\Slack\Slack.exe" | |
} | |
# Test-Path standard per-user install | |
ElseIf (Test-Path "$env:localappdata\slack") { | |
$rootPath = Get-Childitem -Path "$env:localappdata\slack" -Filter "app*" -directory | Sort-Object -Descending | Select-Object -First 1 | |
$ssbinteropPath = "$($rootPath.FullName)\resources\app.asar.unpacked\src\static\ssb-interop.js" | |
$exePath = "$($rootPath.FullName)\slack.exe" | |
} | |
Else { | |
Write-Error "Slack doesn't seem to be installed" | |
Exit 1 | |
} | |
$newCode = @' | |
// This was dynamically added by "Apply-SlackDarkTheme.ps1" | |
// See here for more info: https://github.com/Nockiro/slack-black-theme | |
// 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://raw.githubusercontent.com/Nockiro/slack-black-theme/master/custom.css"; | |
let cssPromise = fetch(cssPath).then(response => response.text()); | |
let customCustomCSS = ` | |
:root { | |
/* Modify these to change your theme colors: */ | |
--primary: #09F; | |
--text: #CCC; | |
--background: #080808; | |
--background-elevated: #222; | |
} | |
a[aria-label^="NAME_OF_CHANNEL_OR_DIRECT_CONVO_TO_STYLE"] | |
{ | |
--background: #4d0000 !important; | |
--text-transform: uppercase !important; | |
--letter-spacing: 2px !important; | |
--text-shadow: 1px 1px white; | |
} `; | |
// 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); | |
}); | |
}); | |
}); | |
}); | |
'@; | |
$alreadyBlackssbInterop = Get-Content $ssbinteropPath | Where-Object { $_.Contains("This was dynamically added") } | |
if ($alreadyBlackssbInterop) { | |
Write-Output "$ssbinteropPath already has dark theme" | |
} | |
else { | |
Add-Content -Path $ssbinteropPath -Value $newCode | |
Get-Process -Name "Slack*" | Stop-Process | |
Start-Process -FilePath $exePath -RedirectStandardOutput Out-Null | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment