This repository has been archived by the owner on Mar 25, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
slack-dark-mode.sh
executable file
·82 lines (59 loc) · 3.46 KB
/
slack-dark-mode.sh
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env bash
# Usage: ./slack-dark-mode.sh (see README.md for other commands)
# Homebaked Slack Dark Mode. After executing this script restart Slack for changes to take effect.
# Adopted from https://gist.github.com/a7madgamal/c2ce04dde8520f426005e5ed28da8608
SLACK_DIRECT_LOCAL_SETTINGS="Library/Application\ Support/Slack/local-settings.json"
SLACK_STORE_LOCAL_SETTINGS="Library/Containers/com.tinyspeck.slackmacgap/Data/Library/Application\ Support/Slack/local-settings.json"
OSX_SLACK_RESOURCES_DIR="/Applications/Slack.app/Contents/Resources"
LINUX_SLACK_RESOURCES_DIR="/usr/lib/slack/resources"
UPDATE_ONLY="false"
for arg in "$@"; do
shift
case "$arg" in
-[uU]|--[uU]pdate) UPDATE_ONLY="true" ;;
-[lL]|--[lL]ight) LIGHT_MODE="true" ;;
*) echo "Option doesn't exist"; exit 1 ;;
esac
done
if [[ -z $OSX_SLACK_RESOURCES_DIR ]] || [[ -z $LINUX_SLACK_RESOURCES_DIR ]]; then echo "Please make sure Slack is installed /Applications (macOS) or /usr/local/slack (Linux)" && exit 1; fi
echo && echo "This script requires sudo privileges." && echo "You'll need to provide your password."
NPX_PATH=$(type -P npx)
if [[ "$?" != "0" ]]; then echo "Please install NodeJS for your OS." && echo "macOS users will also need to install Homebrew from https://brew.sh" && exit 1; fi
if [[ -d $OSX_SLACK_RESOURCES_DIR ]]; then
SLACK_RESOURCES_DIR=$OSX_SLACK_RESOURCES_DIR
fi
if [[ -d $LINUX_SLACK_RESOURCES_DIR ]]; then SLACK_RESOURCES_DIR=$LINUX_SLACK_RESOURCES_DIR; fi
if [[ "$1" == "-u" ]]; then UPDATE_ONLY="true"; fi
SLACK_EVENT_LISTENER="event-listener.js"
SLACK_FILEPATH="$SLACK_RESOURCES_DIR/app.asar.unpacked/dist/ssb-interop.bundle.js"
THEME_FILEPATH="$SLACK_RESOURCES_DIR/dark-theme.css"
#curl -sSL -o "$THEME_FILEPATH" "https://cdn.rawgit.com/laCour/slack-night-mode/master/css/raw/black.css"
if [[ "$UPDATE_ONLY" == "true" ]]; then echo && echo "Updating Dark Theme Code for Slack... "; fi
if [[ "$UPDATE_ONLY" == "false" ]]; then
echo && echo "Adding Dark Theme Code to Slack... "
fi
if [[ -z $HOME ]]; then HOME=$(ls -d ~); fi
if [[ "$LIGHT_MODE" == "true" ]]; then
echo "Removing Dark Theme... " && echo "Please refresh/restart Slack (ctrl/cmd + R) for changes to take affect." && sudo rm -f $THEME_FILEPATH
exit
fi
# Copy CSS to Slack Folder
sudo cp -af dark-theme.css "$THEME_FILEPATH"
# If we Have a Custom File, Append to the End
if [[ -f custom-dark-theme.css ]]; then
echo "Adding Custom CSS to Dark Theme... " && cat custom-dark-theme.css >> "$THEME_FILEPATH"
fi
if [[ "$UPDATE_ONLY" == "false" ]]; then
# Modify Local Settings
if [[ -f "$HOME/$SLACK_DIRECT_LOCAL_SETTINGS" ]]; then sed -i 's/"bootSonic":"[^"]*"/"bootSonic":"never"/g' "$HOME/$SLACK_DIRECT_LOCAL_SETTINGS"; fi
if [[ -f "$HOME/$SLACK_STORE_LOCAL_SETTINGS" ]]; then sudo sed -i 's/"bootSonic":"[^"]*"/"bootSonic":"never"/g' "$HOME/$SLACK_STORE_LOCAL_SETTINGS"; fi
# Unpack Asar Archive for Slack
sudo "PATH=$PATH" $NPX_PATH asar extract $SLACK_RESOURCES_DIR/app.asar $SLACK_RESOURCES_DIR/app.asar.unpacked
# Add JS Code to Slack
sudo tee -a "$SLACK_FILEPATH" > /dev/null < $SLACK_EVENT_LISTENER
# Insert the CSS File Location in JS
sudo sed -i -e s@SLACK_DARK_THEME_PATH@$THEME_FILEPATH@g $SLACK_FILEPATH
# Pack the Asar Archive for Slack
sudo "PATH=$PATH" $NPX_PATH asar pack $SLACK_RESOURCES_DIR/app.asar.unpacked $SLACK_RESOURCES_DIR/app.asar
fi
echo && echo "Done! After executing this script restart Slack for changes to take effect."