Created
January 11, 2019 01:51
-
-
Save Allen-B1/6fa0f1801fd09ce0ca1acef349eae9b2 to your computer and use it in GitHub Desktop.
Colorize text
This file contains hidden or 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
<html> | |
<head><title>Colorizer</title></head> | |
<body> | |
<input type="text" id="input"> | |
<div id="out"></div> | |
<script> | |
rc = () => "#" + (Math.random()).toString(16).slice(-6) | |
function color(text) { | |
var out = "" | |
for (let i = 0; i < text.length; i++) { | |
out += '<span style="color:' + rc() + '">' + text[i].replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">") + '</span>' | |
} | |
return out | |
} | |
document.getElementById("input").oninput = function() { | |
document.getElementById("out").innerHTML = color(this.value) | |
} | |
document.onload = function() { | |
document.getElementById("input").focus() | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment