A Pen by Alexander Williamson on CodePen.
Created
March 13, 2021 17:58
-
-
Save alexander-williamson/704d6d563f7ca1ab782a52405a7d986a to your computer and use it in GitHub Desktop.
QWGYRzm
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
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BmbxuPwQa2lc/FVzBcNJ7UAyJxM6wuqIj61tLrc4wSX0szH/Ev+nYRRuWlolflfl" crossorigin="anonymous"> | |
<div class="editor"> | |
<h2>Input</h2> | |
<textarea id="editor" name="input-textarea" onchange="update(this)" placeholder="Try ^6hello world"> | |
</textarea> | |
<ul class="examples"> | |
<li><button type="button" onClick="window.rainbow()">Rainbow</button> | |
</ul> | |
</div> | |
<div class="output"> | |
<h2>Output</h2> | |
<div id="results">Output</div> | |
</div> |
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
rainbow = () => { | |
const editor = document.getElementById("editor"); | |
editor.innerHTML = "^1Red ^2Green ^3Orange ^4Blue ^5Aqua ^6Purple ^7White ^8Grey ^9Black"; | |
update(editor) | |
} | |
update = e => { | |
let result = e.value; | |
result = result.replace(/\^1([^\^]+)/, `<span style="color:red;">$1</span>`); | |
result = result.replace(/\^2([^\^]+)/, `<span style="color:green;">$1</span>`); | |
result = result.replace(/\^3([^\^]+)/, `<span style="color:orange;">$1</span>`); | |
result = result.replace(/\^4([^\^]+)/, `<span style="color:blue;">$1</span>`); | |
result = result.replace(/\^5([^\^]+)/, `<span style="color:aqua;">$1</span>`); | |
result = result.replace(/\^6([^\^]+)/, `<span style="color:purple;">$1</span>`); | |
result = result.replace(/\^7([^\^]+)/, `<span style="color:white;">$1</span>`); | |
result = result.replace(/\^8([^\^]+)/, `<span style="color:grey;">$1</span>`); | |
result = result.replace(/\^9([^\^]+)/, `<span style="color:black;">$1</span>`); | |
document.getElementById("results").innerHTML = result; | |
} |
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
.editor, .output { | |
padding: 0.5em; | |
margin: 0.5em; | |
} | |
.editor textarea { | |
min-width: 10em; | |
min-height: 10em; | |
} | |
.output #results { | |
background-color: #b3b3b3; | |
min-width: 10em; | |
min-height: 10em; | |
border: 1px solid black; | |
margin: 0.5em; | |
padding: 0.5em; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment