This repository has been archived by the owner on Aug 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
turn_slack_dark.sh
107 lines (91 loc) · 3.33 KB
/
turn_slack_dark.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/bin/bash
function set_vars() {
# Link to where the CSS resides.
css_link="https://raw.githubusercontent.com/gio-salvador/slack_dark_theme/master/dark_theme.css"
# Path to the file to be edited.
slack_edit="/Applications/Slack.app/Contents/Resources/app.asar.unpacked/src/static/ssb-interop.js"
# Lines to be added to the file.
lines="
document.addEventListener('DOMContentLoaded', function() {
let tt__customCss = \`.menu ul li a:not(.inline_menu_link) {color: #fff !important;}\`
\$.ajax({
url: \"$css_link\",
success: function(css) {
\$('<style></style>').appendTo('head').html(css + tt__customCss);
\$('<style></style>').appendTo('head').html('#reply_container.upload_in_threads .inline_message_input_container {background: padding-box #545454}');
\$('<style></style>').appendTo('head').html('.p-channel_sidebar {background: #363636 !important}');
\$('<style></style>').appendTo('head').html('#client_body:not(.onboarding):not(.feature_global_nav_layout):before {background: inherit;}');
}
});
});
}"
#echo $lines
}
function install_gnu_sed_if_absent() {
# Check gnu-sed is installed
if [ "$(which gsed | wc -l)" == "0" ]
then
brew install gsed
fi
# Check gnu-sed PATHS are correct
gnubin='export PATH="/usr/local/opt/gnu-sed/libexec/gnubin:$PATH"'
if ! grep -Fxq "$gnubin" ~/.bash_profile
then
echo "$gnubin" >> ~/.bash_profile
source ~/.bash_profile
fi
# This is not required, but it stes the path to 'man gsed'
gnuman='export MANPATH="/usr/local/opt/gnu-sed/libexec/gnuman:$MANPATH"'
if ! grep -Fxq "$gnuman" ~/.bash_profile
then
echo "$gnuman" >> ~/.bash_profile
source ~/.bash_profile
fi
}
function rollback_setup(){
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
# Display how to roll back
echo -e """#!/bin/bash
slack_edit='/Applications/Slack.app/Contents/Resources/app.asar.unpacked/src/static/ssb-interop.js'
sudo cp \$slack_edit.$DATE \$slack_edit
unset slack_edit""" > $SCRIPTPATH/turn_slack_back.sh
echo -e "INFO: To reverse settings, just run: \n bash $SCRIPTPATH/turn_slack_back.sh"
}
function edit_slack_file(){
# Make backup of file to be edited.
DATE=`date +%Y-%m-%d_%H.%M.%S`
sudo cp $slack_edit $slack_edit.$DATE
# Make the changes for dark mode if not present, by checking if the link to the
# CSS file is present.
if ! grep -q "$css_link" "$slack_edit"
then
sudo gsed -i '$ d' "$slack_edit"
echo "$lines" | sudo tee -a "$slack_edit" > /dev/null
osascript -e 'tell application "Slack" to quit'
sleep 3
open -a "Slack"
rollback_setup
else
echo -e "WARNING: Changes failed to apply because they're already present!"
exit 1
fi
}
function clean_up(){
unset css_link slack_edit lines gnubin gnuman DATE
}
function main(){
# Exit at any time if Error
set -e
# Set necessary vars
# Future note, if necessary make them arguments
set_vars
# gnu-sed is needed to delete the last line of the file which is the closing }
# Therefore on the following function it installs gnu-sed is not installed,
# possibly adding a debug function and a run quiet function.
install_gnu_sed_if_absent
# Function to actually modify the file.
edit_slack_file
# Function to clean up variables if script is run with 'source'
clean_up
}
main