-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
58 lines (52 loc) · 2.05 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>Text Inspector</title>
<meta name="description" content="shows the bytes making up a UTF-8 or UTF-16 sequence">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="apple-touch-icon" href="/apple-touch-icon.png">
<script type="text/javascript" src="codepoint-names.js"></script>
<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function(){
const textBox = document.getElementById("text");
const resultBox = document.getElementById("result");
const update = e => {
const toLine = codepoint => {
const charCode = codepoint.codePointAt(0);
const name = NAMES[charCode] ? NAMES[charCode] : '';
let hexCharCode = charCode.toString(16);
hexCharCode = hexCharCode.length <= 2 ? hexCharCode.padStart(2, "0") : hexCharCode.padStart(4, "0");
return hexCharCode.padStart(6, " ") + '\t' + name;
}
result = [...e.target.value].map(toLine).join('\n')
resultBox.innerText = result;
};
textBox.addEventListener('input', update);
textBox.focus();
});
</script>
<style>
/* TODO: dark mode */
#text {
/* https://stackoverflow.com/questions/5219175/how-to-make-an-element-width-100-minus-padding */
box-sizing: border-box;
width: 100%;
font-family: "Noto Sans", sans-serif;
font-size: 1rem;
}
#result {
font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
font-size: 1rem;
}
#encoding-select label {
margin-right: 15px;
}
</style>
</head>
<body>
<textarea id="text" placeholder="UTF-8 text"></textarea>
<pre id="result"></pre>
</body>
</html>