Skip to content

Instantly share code, notes, and snippets.

@lorey
Last active Apr 16, 2020
Embed
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");
console.log(current);
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 !i.id.endsWith("input")}).forEach(function (i) {
var ownerId = getOwnerId(i);
if (ownerId && ownerId == "USER ID HERE") {
i.style.display = 'none';
}
})
}
// this is a hack, couldn't get a better solution to work
// better: https://stackoverflow.com/questions/3219758/detect-changes-in-the-dom
window.setInterval(removeMessages, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment