#!/usr/bin/env bash
set -e
set -o pipefail
set -u
OUTPUTFILE="/Applications/Slack.app/Contents/Resources/app.asar.unpacked/src/static/ssb-interop.js"
# ensure that the script is not run as root or sudo
if [[ $EUID = 0 ]]; then
echo "Do not run as root or sudo. It should be run as the user running Slack. You will be prompted if sudo access is needed."
exit
fi
if [[ $OSTYPE =~ darwin* ]] ; then
# close Slack
echo "Closing Slack"
osascript -e 'quit app "Slack"' || true > /dev/null
#add the code
echo "Adding the necessary code"
sudo tee -a "$OUTPUTFILE" > /dev/null <<'EOF'
document.addEventListener('DOMContentLoaded', function() {
$.ajax({
url: 'https://cdn.rawgit.com/laCour/slack-night-mode/master/css/raw/black.css',
success: function(css) {
$("<style></style>").appendTo('head').html(css);
}
});
});
EOF
# restart Slack
echo "Restarting Slack"
#osascript -e 'open app "Slack"' || true > /dev/null
open -a Slack
else
echo "Only OSX or MacOS is currently supported"
exit
fi