Created
October 11, 2023 15:15
-
-
Save morgan9e/6ae1d483803fb595f5990e9f4ca0354d to your computer and use it in GitHub Desktop.
hangul.html
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<script src="https://cdn.jsdelivr.net/npm/[email protected]/inko.min.js"></script> | |
<style> | |
#preview { | |
position: absolute; | |
font-size: 14px; | |
font-weight: bold; | |
justify-content: center; | |
align-items: center; | |
padding: 2px; | |
z-index: 10; | |
display: block; | |
background-color: black; | |
color: white; | |
right: 20px; | |
bottom: 20px; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="preview"></div> | |
<div style="margin: 20px 0 0 20px;"> | |
<textarea type="input" style="font-size: 15px;width: calc(100% - 40px);height: 80vh;ime-mode: disabled;" id="input-1" onkeydown="changeHanEng(event, this);" onkeyup="updatePreview(event, this);"></textarea> | |
<br/> | |
</div> | |
<script> | |
var toggleHan = 0; | |
var firstmark = 0; | |
const elem = document.getElementById("input-1"); | |
function changeHanEng(event, elem) { | |
if (event.keyCode == 225 || event.keyCode == 21) { | |
if (toggleHan) { | |
text = elem.value.split(" "); | |
last = text.pop(); | |
text.push(last.slice(0,firstmark) + inko.en2ko(last.slice(firstmark))); | |
elem.value = text.join(" "); | |
} | |
toggleHan = toggleHan?0:1; | |
firstmark = elem.value.substring(0, elem.selectionStart).split(/\s+/).pop().length; | |
} | |
if ((event.keyCode == 32 || event.keyCode == 13 ) && toggleHan) | |
{ | |
console.log("\"" + elem.value + "\"") | |
text = elem.value.split(" "); | |
last = text.pop(); | |
text.push(last.slice(0,firstmark) + inko.en2ko(last.slice(firstmark))); | |
elem.value = text.join(" "); | |
firstmark = 0; | |
} | |
} | |
function updatePreview(event, elem) { | |
const preview = document.getElementById("preview"); | |
if (toggleHan) { | |
last = elem.value.split("\n").pop().split(" ").pop(); | |
var han = inko.en2ko(last.slice(firstmark)); | |
console.log(last.slice(0,firstmark) + han); | |
if (han) { | |
preview.innerText = han; | |
} else { | |
preview.innerText = "KO"; | |
} | |
} else { | |
preview.innerText = "EN"; | |
} | |
} | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment