Skip to content

Instantly share code, notes, and snippets.

@hatarist
Created September 21, 2016 11:31
Show Gist options
  • Save hatarist/3e5ce09020552a9e1355316b12d6806e to your computer and use it in GitHub Desktop.
Save hatarist/3e5ce09020552a9e1355316b12d6806e to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Slack: Full Name (@username)
// @namespace http://hatari.st/
// @version 0.1
// @description nuff said
// @author igor@hatari.st
// @match https://*.slack.com/messages/*
// ==/UserScript==
(function() {
var timeout;
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.addedNodes.length !== 0) {
for(var i = 0; i < mutation.addedNodes.length; i++) {
if (mutation.addedNodes[i].className == 'day_container' || mutation.addedNodes[i].nodeName == 'TS-MESSAGE') {
addUsernames();
break;
}
}
}
});
});
function addUsernames() {
if (!document.body.classList.contains('loading')) {
var senders = document.querySelectorAll('.message_sender');
for (var i = 0; i < senders.length; i++) {
if (senders[i].textContent.indexOf(')') === -1) {
senders[i].textContent = senders[i].textContent + " (@" + senders[i].getAttribute('href').split('/')[2] + ")";
}
}
}
}
var target = document.querySelector('#msgs_div');
observer.observe(target, {childList: true, subtree: true});
window.clearInterval(timeout);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment