Skip to content

Instantly share code, notes, and snippets.

@vRobM
Created December 6, 2018 19:38
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vRobM/bf158904fcbdcd45c94eceaaa58556ec to your computer and use it in GitHub Desktop.
Save vRobM/bf158904fcbdcd45c94eceaaa58556ec to your computer and use it in GitHub Desktop.
Make Slack Desktop for Windows have dARK mode using powershell.
// Ark Labs presents - Slack dARK mode
$slackBaseDir = "$env:LocalAppData\Slack"
$installations = Get-ChildItem $slackBaseDir -Directory | Where-Object { $_.Name.StartsWith("app-") }
$version = $installations | Sort-Object { [version]$_.Name.Substring(4) } | Select-Object -Last 1
Write-Output "Select highest intalled Slack version: $version";
$modAdded = $false;
$customContent = @'
// slack-dARK-mode |-)
document.addEventListener('DOMContentLoaded', function() {
$.ajax({
url: 'https://raw.githubusercontent.com/laCour/slack-night-mode/master/css/raw/black.css',
success: function(css) {
$("<style></style>").appendTo('head').html(css);
}
});
});
'@
if ((Get-Content "$($version.FullName)\resources\app.asar.unpacked\src\static\index.js" | %{$_ -match "// laCour - slack-night-mode"}) -notcontains $true) {
Add-Content "$($version.FullName)\resources\app.asar.unpacked\src\static\index.js" $customContent
Write-Host "Mod Added To index.js";
$modAdded = $true;
} else {
Write-Host "Mod Detected In index.js - Skipping";
}
if ((Get-Content "$($version.FullName)\resources\app.asar.unpacked\src\static\ssb-interop.js" | %{$_ -match "// laCour - slack-night-mode"}) -notcontains $true) {
Add-Content "$($version.FullName)\resources\app.asar.unpacked\src\static\ssb-interop.js" $customContent
Write-Host "Mod Added To ssb-interop.js";
$modAdded = $true;
} else {
Write-Host "Mod Detected In ssb-interop.js - Skipping";
}
if ($modAdded -eq $true) {
if((Get-Process "slack" -ErrorAction SilentlyContinue) -ne $null) {
Write-Host "Mod Complete - Mod Will Take Effect After Slack Is Restarted";
} else {
Write-Host "Mod Complete";
}
} else {
Write-Host "Mod Already Active - No Further Action Is Needed.";
}
@adilio
Copy link

adilio commented Feb 3, 2019

Hey Rob, thanks for this!

might i suggest changing the "//" to "#" ?

@JadedBlueEyes
Copy link

might i suggest changing the "//" to "#" ?

I highly reccomend this. // is not a vailid comment in PowerShell, and causes an error.

@GottZ
Copy link

GottZ commented Mar 16, 2019

TL;DR: use my fork

throw this into a .bat file and run this permission elevated in case you don't want to enable powershell scripts globally:

@set pwd=%~dp0
@cd %pwd:~0,-1%
@powershell -nologo -executionpolicy bypass -File "Slack-Go-dARK.ps1"
@pause

i assume %{$_ -match "// laCour - slack-night-mode"} does not work either.

i'm using this now:

document.addEventListener("DOMContentLoaded", async () => {
  try {
    let css = await fetch("https://raw.githubusercontent.com/laCour/slack-night-mode/master/css/raw/black.css");
    if (!css.ok) return;
    css = await css.text();
    // remove all comments. go there to check it: https://regex101.com/r/pvPqAZ/3
    // just removing multiline comments would be fine though. but why worry. // will only apply to URL's and content: "//" then.
    css = css.replace(/\/(?:\/.*$|\*(?:[^]*?\*\/|[^]+))/g, "");
    // checking if malicious code is present and abort style injection.
    // unless you can tell me about a different attack vector,
    // this aborts further execution if it detects presence of possible attack vectors.
    // if you don't have a clue, read this random google result i just found:
    // https://www.netsparker.com/blog/web-security/private-data-stolen-exploiting-css-injection/
    if (/url\s*\(/u.test(css) || /@\s*import/u.test(css)) return;
    var style = document.createElement("style");
    // using textContent will extinguish any html injections
    style.textContent = css;
    document.head.appendChild(style);
  } catch (e) {
    const fs = require("fs");
    const path = require("path");
    const os = require("os");
    fs.writeFileSync(path.join(os.tmpdir(), "slackfail.log"), e.toString());
  }
});

i simply forked this now https://gist.github.com/GottZ/621f4b6994cfb2726e43e18e7a75e49a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment