Last active
May 5, 2017 03:42
-
-
Save kaloncpu57/a9e420bee1856607195286843cc55d75 to your computer and use it in GitHub Desktop.
Wrap hex color codes in divs - BetterDiscord plugin piece
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
class hexColorPreview { | |
wrapAll() { | |
let messages = document.getElementsByClassName("markup"); | |
for (var i = 0; i < messages.length; i++) { | |
let msg = messages[i]; | |
if (msg.getElementsByClassName(".hex-value").length > 0) continue; //don't wrap multiple times | |
let html = msg.innerHTML; | |
html = html.replace( | |
/#(?:[0-9a-fA-F]{3}){1,2}/g, //find hex color values | |
'<div class="hex-value" style="color: $&;">$&<div class="hex-preview" style="background: $&;"></div></div>' | |
); | |
msg.innerHTML = html; | |
} | |
} | |
onMessage() { | |
this.wrapAll(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment