Created
September 21, 2016 11:31
-
-
Save hatarist/3e5ce09020552a9e1355316b12d6806e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Slack: Full Name (@username) | |
// @namespace http://hatari.st/ | |
// @version 0.1 | |
// @description nuff said | |
// @author [email protected] | |
// @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