-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslack_remove_wysiwyg.sh
executable file
·82 lines (64 loc) · 1.9 KB
/
slack_remove_wysiwyg.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
## taken from https://gist.github.com/scalp42/e869635c5b21f2395e5f4bd8e48ca2f4
##
set -e
SLACK_RESOURCES_DIR=/Applications/Slack.app/Contents/Resources
function command_exists() {
command -v $1 > /dev/null
return $?
}
if [ ! -d "$SLACK_RESOURCES_DIR" ]; then
echo "Couldn't find Slack resources dir ($SLACK_RESOURCES_DIR)"
echo "Is it installed?"
exit 1
else
echo "✅ Found dir $SLACK_RESOURCES_DIR"
fi
if ! command_exists npx; then
echo "Could not find npx, please install"
else
echo "✅ npx found"
fi
NPX_PATH=$(type -P npx)
# unpack
echo "🚀 unpacking asar archive for Slack (requires sudo)"
sudo "PATH=$PATH" $NPX_PATH asar extract $SLACK_RESOURCES_DIR/app.asar $SLACK_RESOURCES_DIR/app.asar.unpacked
echo "✅ done"
JS_FILE="$SLACK_RESOURCES_DIR/app.asar.unpacked/dist/ssb-interop.bundle.js"
HEADER="// WYSIWYG patch"
if grep -q "$HEADER" "$JS_FILE" >/dev/null; then
echo "🎉 Patch is already installed, exiting early"
exit 0
fi
echo "🚀 Patching $JS_FILE with code..."
cat << EOF | sudo tee -a "$JS_FILE" > /dev/null
$HEADER
const disableWysiwygEditor = (_ => {
const redux = slackDebug[slackDebug.activeTeamId].redux;
const {
wysiwyg_composer,
wysiwyg_composer_ios,
wysiwyg_composer_webapp,
...payload
} = redux.getState().experiments;
redux.dispatch(
{
type: '[19] Bulk add experiment assignments to redux',
payload
}
);
});
const disableInterval = setInterval(() => {
const isLoaded = window.slackDebug &&
window.slackDebug[window.slackDebug.activeTeamId] &&
window.slackDebug[window.slackDebug.activeTeamId].redux;
if (isLoaded) {
clearInterval(disableInterval);
setTimeout(disableWysiwygEditor, 2000);
}
}, 50);
EOF
echo "✅ done"
echo "🚀 Repackaging asar for Slack..."
sudo "PATH=$PATH" $NPX_PATH asar pack $SLACK_RESOURCES_DIR/app.asar.unpacked $SLACK_RESOURCES_DIR/app.asar
echo "🎉 all done!"