Skip to content

Instantly share code, notes, and snippets.

@ryanhatfield
Last active October 4, 2023 06:13
Show Gist options
  • Save ryanhatfield/8fd2d0af54c1205738214c717e0bfa9a to your computer and use it in GitHub Desktop.
Save ryanhatfield/8fd2d0af54c1205738214c717e0bfa9a to your computer and use it in GitHub Desktop.
Hide Slack Sidebar Icons
#! /usr/bin/env bash
##############
##
## A script to inject a custom style into Slack that hides the new sidebar icons.
## This script has very little error catching or extra debug output
##
## Run at your own risk.
## Anything done here can be "uninstalled" by reinstalling Slack
##
## To run Slack in debug mode, run the following:
## export SLACK_DEVELOPER_MENU=true; open -a Slack
## With that, Slack will have a new Developer item under the View menu
##
##############
# directory with the app.asar file, default for OSX
# on linux, just search for the app.asar file
RESOURCE_DIR="/Applications/Slack.app/Contents/Resources/"
# location of the preload file
PRELOAD_FILE="$RESOURCE_DIR/app/dist/preload.bundle.js"
# this script will add an extra style element to the head tag
read -r -d '' SCRIPT <<'EOF'
document.addEventListener("DOMContentLoaded", function () {
let tt__customCss = `
.p-channel_sidebar__user_avatar > .c-avatar { display: none !important; }
`;
var head = document.head;
var iconStyle = document.createElement("style");
iconStyle.appendChild(document.createTextNode(tt__customCss));
head.appendChild(iconStyle);
});
EOF
# check for the npx command
if ! command -v "npx" &> /dev/null
then
echo "npx command could not be found, install node https://nodejs.org/en/"
exit
fi
# open resource dir; on linux, just search for the app.asar file
cd "$RESOURCE_DIR" || exit 04
# check for pre-existing app dir
if [ -d "app" ]
then
echo "app dir alredy exists, skipping backup"
else
# unpack asar resource
npx asar extract app.asar app
# move packaged asar, so electron reads from the app folder
mv app.asar app.asar.bak
fi
# check to see if we've already added our script, there's better ways to do this I'm sure
if ! grep 'iconStyle' &> /dev/null < "$PRELOAD_FILE"
then
echo "$SCRIPT" >> "$PRELOAD_FILE"
echo "installed, close and reopen Slack if it's running"
else
echo "iconStyle script already installed"
exit 06
fi
@imasupersadpanda
Copy link

Kickass. Thanks a ton @marcopelegrini!

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