Unicode Finder
by LinguList
HTML
<h1>Unicode Resolver and Chinese Character Finder</h1>
<input id="charcode" type="text"
placeholder="type your *** characters here" style="width: 200px;"
onkeyup="getCharCode()"/>
<br>
<div id="output" />
CSS
input {
border: 5px solid pink;
color: black;
margin-bottom: 10px;
background-color: white;
}
td {
border: 1px solid lightgray;
}
th {
border: 1px solid black;
}
JavaScript
function getUnicode(char) {
var code = char.charCodeAt(0).toString(16).toUpperCase();
while (code.length < 4) {
code = "0" + code;
}
return code;
}
function isChinese(char) {
var code = char.charCodeAt(0);
console.log(code);
if (
(0x3400 <= code && code <= 0x9fff) ||
(0x20000 <= code && code <= 0x2ceaf) ||
(0x2f800 <= code && code <= 0x2fa1f)
) {
return true;
}
return false;
}
function getCharCode() {
var unicode;
var node = document.getElementById("charcode");
var table = '<table><tr><th>Character</th><th>Unicode</th><th>Chinese</th><th>Reference</th></tr>';
for (var i = 0; i < node.value.length; i += 1) {
unicode = getUnicode(node.value[i]);
table += "<tr><td>" + node.value[i];
table += "</td><td>U+" + unicode;
if (isChinese(node.value[i])) {
table += "</td><td>yes";
}
else {
table += "</td><td>no";
}
table += '</td><td><a target="_black" href="https://www.unicode.org/cgi-bin/GetUnihanData.pl?codepoint=' + unicode + '">CHECK</a></td></tr>';
}
table += "</table>";
document.getElementById("output").innerHTML = table;
}