-
-
Save rlemon/df2f8b2fb570d15aead0 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
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