Skip to content

Instantly share code, notes, and snippets.

@lorey
Last active April 16, 2020 22:29
Show Gist options
  • Save lorey/1880513d1ce2b0a23227dcedeb9894b2 to your computer and use it in GitHub Desktop.
Save lorey/1880513d1ce2b0a23227dcedeb9894b2 to your computer and use it in GitHub Desktop.
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