Skip to content

Instantly share code, notes, and snippets.

@rlemon

rlemon/file.js Secret

Created February 20, 2015 22:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rlemon/df2f8b2fb570d15aead0 to your computer and use it in GitHub Desktop.
Save rlemon/df2f8b2fb570d15aead0 to your computer and use it in GitHub Desktop.
setTimeout(function() {
[].forEach.call(chat.querySelectorAll('.user-container .message'), visualHexColors);
}, 1000); // some users are never parsed. this solves that. (I have other shit in the timeout)
new MutationObserver(function(records) {
records.forEach(function(record) {
[].forEach.call(record.addedNodes, visualHexColors);
});
}).observe(chat, {
childList: true,
subtree: true
});
function visualHexColors(node) {
if (node.classList && node.classList.contains('message') && !node.classList.contains('pending')) {
[].forEach.call(node.childNodes, function(child) {
if (/#(?:[0-9a-f]{3}){1,2}/ig.test(child.textContent)) {
child.innerHTML = child.innerHTML.replace(/#(?:[0-9a-f]{3}){1,2}/ig, function(match) {
return '<span style="width:12px;height:12px;border:1px solid #222;background-color:' + match + ';display:inline-block;"></span>' + match;
});
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment