Skip to content

Instantly share code, notes, and snippets.

@radditude
Last active August 14, 2019 19:43
Show Gist options
  • Save radditude/43b76745b796db8035d676ff63346d4a to your computer and use it in GitHub Desktop.
Save radditude/43b76745b796db8035d676ff63346d4a to your computer and use it in GitHub Desktop.
slackdarkmode.sh
#!/usr/bin/env bash -e
# GET THE SCRIPT:
# curl https://gist.githubusercontent.com/radditude/43b76745b796db8035d676ff63346d4a/raw/5151905200d894dd4bbf9946d9f3944cfc2db621/slackdarkmode.sh > ~/slackdarkmode.sh
# chmod +x ~/slackdarkmode.sh
#
# SEE OPTIONS:
# ~/slackdarkmode.sh usage
usage() {
echo ""
echo "Dark mode for the MacOS desktop Slack client"
echo "USAGE:"
echo " $(basename $0)"
echo " - enable dark mode or apply updated CSS overrides"
echo " $(basename $0) undo"
echo " - revert to light mode"
echo " $(basename $0) [help|usage]"
echo " - this message"
echo ""
exit
}
FLAG="slackdarkmodehack"
DIR="/Applications/Slack.app/Contents/Resources"
JS_FILE_PATH="$DIR/app.asar.darkmode/dist/ssb-interop.bundle.js"
CSS_FILE_PATH="$DIR/darkmode.css"
CSS_OVERRIDES='code, pre, .CodeMirror { background-color: #535353; color: #85c5ff; }
.p-classic_nav { background-color: #222222; }
.p-classic_nav__channel_header__subtitle, .p-member_profile_field__label, .p-member_profile_name__link, .c-sidebar_menu__list_item { color: #e6e6e6; }
.p-member_profile_card, label.p-prefs_modal__radiogroup--selected, .c-fullscreen_modal__header { background: #363636 !important; color: #ffffff; }
.p-prefs_modal__notification_example, .c-select_button { color: #363636; }'
SLACKDARKMODE="\ndocument.addEventListener('DOMContentLoaded', function darkMode() {
const fs = require('fs');
const filePath = \`$CSS_FILE_PATH\`;
const overrides = \`$CSS_OVERRIDES\`;
fs.readFile(filePath, {
encoding: 'utf-8'
}, function(err, css) {
if (!err) {
var styleEl = document.createElement('style');
styleEl.innerHTML = css + overrides;
document.querySelector('head').append(styleEl);
} else {
console.error(err);
}
});
}); //$FLAG"
get_css() {
sudo curl -sSL -o "$CSS_FILE_PATH" "https://cdn.jsdelivr.net/gh/laCour/slack-night-mode/css/raw/black.css"
}
append_newline() {
echo $'\n' | sudo tee -a $JS_FILE_PATH > /dev/null
}
append_snippet() {
echo "$SLACKDARKMODE" | tr '\n' ' ' | tr -s '[:blank:]' | sudo tee -a $JS_FILE_PATH > /dev/null
}
undo() {
sudo sed -i "" "/$FLAG/d" $JS_FILE_PATH
}
restart_slack() {
echo "restarting Slack..."
killall Slack &>/dev/null
open /Applications/Slack.app
}
unpack_archive() {
npm install -g asar
sudo asar extract $DIR/app.asar $DIR/app.asar.darkmode
}
repack_archive() {
sudo asar pack $DIR/app.asar.darkmode $DIR/app.asar
}
fixslack() {
if [[ "$1" == "undo" ]]; then
echo "disabling dark mode... you may need to enter your password."
unpack_archive
undo
repack_archive
restart_slack
echo "slack dark mode disabled!"
exit
elif [[ "$1" == "usage" || "$1" == "help" ]]; then
usage
fi
echo "enabling dark mode... you may need to enter your password."
get_css
unpack_archive
if grep -q "//$FLAG" $JS_FILE_PATH; then
undo
else
append_newline
fi
append_snippet
repack_archive
restart_slack
echo "your slack has been endarkened!"
}
fixslack "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment