Skip to content

Commit 00dc62b

Browse files
committed
first commit
0 parents  commit 00dc62b

3 files changed

Lines changed: 119 additions & 0 deletions

File tree

index.html

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<html>
2+
<head>
3+
<script src="script.js"></script>
4+
<link rel="stylesheet" href="style.css">
5+
</head>
6+
<body>
7+
8+
<!-- credits https://codepen.io/NShadeIV/pen/jOrJPpX -->
9+
10+
<ul>
11+
<li><i></i><i></i><input /></li>
12+
<li><i></i><i></i><input /></li>
13+
<li><i></i><i></i><input /></li>
14+
<li><i></i><i></i><input /></li>
15+
<li><i></i><i></i><input /></li>
16+
</ul>
17+
<div id="command"></div>
18+
<div id="preview"></div>
19+
20+
21+
</body>
22+
</html>

script.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
function docReady(fn) {
2+
// see if DOM is already available
3+
if (document.readyState === "complete" || document.readyState === "interactive") {
4+
// call on next available tick
5+
setTimeout(fn, 1);
6+
} else {
7+
document.addEventListener("DOMContentLoaded", fn);
8+
}
9+
}
10+
11+
docReady(function() {
12+
13+
14+
const reg = {
15+
'000000': '0',
16+
'0000AA': '1',
17+
'00AA00': '2',
18+
'00AAAA': '3',
19+
'AA0000': '4',
20+
'AA00AA': '5',
21+
'FFAA00': '6',
22+
'AAAAAA': '7',
23+
'555555': '8',
24+
'5555FF': '9',
25+
'55FF55': 'a',
26+
'55FFFF': 'b',
27+
'FF5555': 'c',
28+
'FF55FF': 'd',
29+
'FFFF55': 'e',
30+
'FFFFFF': 'f'
31+
};
32+
const blend = ([a1, a2], r) => a1.map((p, i) => Math.round(p * (1 - r) + a2[i] * r));
33+
const toHex = rgb => rgb.map(n => n.toString(16).padStart(2,'0')).join('');
34+
Array.from(document.getElementsByTagName('i')).forEach(i => i.setAttribute('style', 'background-color:#ffffff'));
35+
setInterval(() => {
36+
let command = '', preview = '', last;
37+
Array.from(document.getElementsByTagName('li')).forEach(li => {
38+
const colors = Array.from(li.getElementsByTagName('i'))
39+
.map(span => getComputedStyle(span).backgroundColor)
40+
.map(rgb => Array.from(rgb.matchAll(/\d+/g)).map(([c]) => Number.parseInt(c)));
41+
const text = (li.getElementsByTagName('input')[0].value || '').trim().split('');
42+
const coloredText = text.map((c, idx) => {
43+
const pct = idx / Math.max(1, text.length - 1);
44+
return {c, rgb: blend(colors, pct)};
45+
});
46+
command += coloredText.map(o => {
47+
const hex = toHex(o.rgb).toUpperCase()
48+
const curr = reg[hex] || '#' + hex;
49+
const ret = curr == last ? o.c : `&${curr}${o.c}`;
50+
last = curr;
51+
return ret;
52+
}).join('');
53+
54+
preview += coloredText.map(o => `<span style='color:#${toHex(o.rgb)}'>${o.c}</span>`).join('');
55+
});
56+
document.getElementById('command').innerText = command;
57+
document.getElementById('preview').innerHTML = preview;
58+
}, 1000)
59+
60+
});

style.css

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
body {
2+
background-color: black;
3+
color: white;
4+
font-size: 30px;
5+
font-family: arial;
6+
}
7+
i {
8+
display: inline-block;
9+
width: 50px; height: 50px;
10+
border: 1px solid black;
11+
vertical-align: middle;
12+
margin-right: 2px;
13+
box-sizing: border-box;
14+
}
15+
input {
16+
height: 50px;
17+
box-sizing: border-box;
18+
vertical-align: middle;
19+
font-size: 30px;
20+
padding: 0 10px;
21+
}
22+
ul {
23+
padding: 0;
24+
margin: 20px 0;
25+
}
26+
li {
27+
margin: 2px 0;
28+
list-style: none;
29+
}
30+
div {
31+
min-height: 50px;
32+
line-height: 50px;
33+
border: 1px solid white;
34+
margin: 20px 0;
35+
padding: 0 10px;
36+
box-sizing: border-box;
37+
}

0 commit comments

Comments
 (0)