Skip to content

Instantly share code, notes, and snippets.

Last active Apr 16, 2020
What would you like to do?
Block a user in Slack
// This will hide all messages from a specific user in Slack. Enjoy the silence.
// get the owner id of a message
// -> loops back through list to find owner
function getOwnerId(i) {
var current = i
var sender = current.querySelector(".c-message__sender_link");
var ownerId = sender ? sender.dataset.messageSender : null;
while (!ownerId) {
console.log("Owner not found for");
current = current.previousSibling;
if (!current){
return null;
sender = current.querySelector(".c-message__sender_link");
ownerId = sender ? sender.dataset.messageSender : null;
return ownerId;
// removes messages where the owner is some user id
function removeMessages() {
// filter excludes thread inputs that are list items, too
Array.from(document.body.querySelectorAll(".c-virtual_list__item")).filter(function (i) {return !"input")}).forEach(function (i) {
var ownerId = getOwnerId(i);
if (ownerId && ownerId == "USER ID HERE") { = 'none';
// this is a hack, couldn't get a better solution to work
// better:
window.setInterval(removeMessages, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment