Created
March 30, 2022 08:28
-
-
Save mingkyme/87219abb5df7e19c42a2e4bf175aaaea to your computer and use it in GitHub Desktop.
Kor to Eng to Kor
This file contains hidden or 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
| var ENG = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLVBNM"; | |
| var ์์ดํ์ดํ = "rRseEfaqQtTdwWczxvgkoiOjpuPhynbml"; | |
| var ํ๊ธํ์ดํ = "ใฑใฒใดใทใธในใ ใ ใ ใ ใ ใ ใ ใ ใ ใ ใ ใ ใ ใ ใ ใ ใ ใ ใ ใ ใ ใ ใ ใ ใ ใ กใ ฃ"; | |
| var ์ด์ฑ๋ชจ์ = "ใฑใฒใดใทใธในใ ใ ใ ใ ใ ใ ใ ใ ใ ใ ใ ใ ใ "; | |
| var ์ค์ฑ๋ชจ์ = "ใ ใ ใ ใ ใ ใ ใ ใ ใ ใ ใ ใ ใ ใ ใ ใ ใ ใ ใ กใ ขใ ฃ"; | |
| var ์ข ์ฑ๋ชจ์ = "ใฑใฒใณใดใตใถใทในใบใปใผใฝใพใฟใ ใ ใ ใ ใ ใ ใ ใ ใ ใ ใ ใ ใ "; | |
| function ํ๊ธ์กฐํฉํ๊ธฐ(src) { | |
| if (src == null) { | |
| return ''; | |
| } | |
| var result = { | |
| ์ฌ์ฉํ๊ธ์์ : src.length | |
| } | |
| switch (src.length) { | |
| case 0: | |
| result.์กฐํฉ๋ํ๊ธ = src; | |
| break; | |
| case 1: // case 1,2 | |
| result.์กฐํฉ๋ํ๊ธ = convert์ํ(src); | |
| break; | |
| case 2: // case 3,4,5 | |
| var ch1 = src.charAt(0), ch2 = src.charAt(1); | |
| // 3. ์์ + ์์ : ใบ | |
| if (is์์(ch1) && is์์(ch2)) { | |
| var ๊ฒฐํฉ์์ = ์์๊ฒฐํฉํ๊ธฐ(convert์ํ(ch1), convert์ํ(ch2)); | |
| if (๊ฒฐํฉ์์) { | |
| result.์กฐํฉ๋ํ๊ธ = ๊ฒฐํฉ์์; | |
| } else { | |
| result = ํ๊ธ์กฐํฉํ๊ธฐ(src.substring(1, 2)); | |
| } | |
| } | |
| // 4. ์์ + ๋ชจ์ : ๊ฐ | |
| else if (is์์(ch1) && is๋ชจ์(ch2)) { | |
| result.์กฐํฉ๋ํ๊ธ = combineํ๊ธ(convert์ํ(ch1), convert์ํ(ch2)); | |
| } | |
| // 5. ๋ชจ์ + ๋ชจ์ : ใ | |
| else if (is๋ชจ์(ch1) && is๋ชจ์(ch2)) { | |
| var ๊ฒฐํฉ๋ชจ์ = ๋ชจ์๊ฒฐํฉํ๊ธฐ(convert์ํ(ch1), convert์ํ(ch2)); | |
| if (๊ฒฐํฉ๋ชจ์) { | |
| result.์กฐํฉ๋ํ๊ธ = ๊ฒฐํฉ๋ชจ์; | |
| } else { | |
| result = ํ๊ธ์กฐํฉํ๊ธฐ(src.substring(1, 2)); | |
| } | |
| } else { | |
| result = ํ๊ธ์กฐํฉํ๊ธฐ(src.substring(1, 2)); | |
| } | |
| break; | |
| case 3:// case 6, 7 | |
| var ch1 = src.charAt(0), ch2 = src.charAt(1), ch3 = src.charAt(2); | |
| // 6. ์์ + ๋ชจ์ + ์์ : ๊ฐ | |
| if (is์์(ch1) && is๋ชจ์(ch2) && is์์(ch3)) { | |
| result.์กฐํฉ๋ํ๊ธ = combineํ๊ธ(convert์ํ(ch1), convert์ํ(ch2), convert์ํ(ch3)); | |
| } | |
| // 7. ์์ + ๋ชจ์ + ๋ชจ์ : ๊ณผ | |
| else if (is์์(ch1) && is๋ชจ์(ch2) && is๋ชจ์(ch3)) { | |
| var ๊ฒฐํฉ๋ชจ์ = ๋ชจ์๊ฒฐํฉํ๊ธฐ(convert์ํ(ch2), convert์ํ(ch3)); | |
| if (๊ฒฐํฉ๋ชจ์) { | |
| result.์กฐํฉ๋ํ๊ธ = combineํ๊ธ(convert์ํ(ch1), ๊ฒฐํฉ๋ชจ์); | |
| } else { | |
| result = ํ๊ธ์กฐํฉํ๊ธฐ(src.substring(1, 3)); | |
| } | |
| } else { | |
| result = ํ๊ธ์กฐํฉํ๊ธฐ(src.substring(1, 3)); | |
| } | |
| break; | |
| case 4:// | |
| var ch1 = src.charAt(0), ch2 = src.charAt(1), ch3 = src.charAt(2), ch4 = src.charAt(3); | |
| // 8. ์์ + ๋ชจ์ + ์์ + ์์ : ๋ญ | |
| if (is์์(ch1) && is๋ชจ์(ch2) && is์์(ch3) && is์์(ch4)) { | |
| var ๊ฒฐํฉ์์ = ์์๊ฒฐํฉํ๊ธฐ(convert์ํ(ch3), convert์ํ(ch4)); | |
| if (๊ฒฐํฉ์์) { | |
| result.์กฐํฉ๋ํ๊ธ = combineํ๊ธ(convert์ํ(ch1), convert์ํ(ch2), ๊ฒฐํฉ์์); | |
| } else { | |
| result = ํ๊ธ์กฐํฉํ๊ธฐ(src.substring(1, 4)); | |
| } | |
| } | |
| // 9. ์์ + ๋ชจ์ + ๋ชจ์ + ์์ : ๊ด | |
| else if (is์์(ch1) && is๋ชจ์(ch2) && is๋ชจ์(ch3) && is์์(ch4)) { | |
| var ๊ฒฐํฉ๋ชจ์ = ๋ชจ์๊ฒฐํฉํ๊ธฐ(convert์ํ(ch2), convert์ํ(ch3)); | |
| if (๊ฒฐํฉ๋ชจ์) { | |
| result.์กฐํฉ๋ํ๊ธ = combineํ๊ธ(convert์ํ(ch1), ๊ฒฐํฉ๋ชจ์, convert์ํ(ch4)); | |
| } else { | |
| result = ํ๊ธ์กฐํฉํ๊ธฐ(src.substring(1, 4)); | |
| } | |
| } else { | |
| result = ํ๊ธ์กฐํฉํ๊ธฐ(src.substring(1, 4)); | |
| } | |
| break; | |
| case 5:// | |
| var ch1 = src.charAt(0), ch2 = src.charAt(1), ch3 = src.charAt(2), ch4 = src.charAt(3), ch5 = src.charAt(4); | |
| // ์์ + ๋ชจ์ + ๋ชจ์ + ์์ + ์์ : ๊ด | |
| if (is์์(ch1) && is๋ชจ์(ch2) && is๋ชจ์(ch3) && is์์(ch4) && is์์(ch5)) { | |
| var ๊ฒฐํฉ๋ชจ์ = ๋ชจ์๊ฒฐํฉํ๊ธฐ(convert์ํ(ch2), convert์ํ(ch3)); | |
| var ๊ฒฐํฉ์์ = ์์๊ฒฐํฉํ๊ธฐ(convert์ํ(ch4), convert์ํ(ch5)); | |
| if (๊ฒฐํฉ๋ชจ์ && ๊ฒฐํฉ์์) { | |
| result.์กฐํฉ๋ํ๊ธ = combineํ๊ธ(convert์ํ(ch1), ๊ฒฐํฉ๋ชจ์, ๊ฒฐํฉ์์); | |
| } else { | |
| result = ํ๊ธ์กฐํฉํ๊ธฐ(src.substring(1, 5)); | |
| } | |
| } else { | |
| result = ํ๊ธ์กฐํฉํ๊ธฐ(src.substring(1, 5)); | |
| } | |
| break; | |
| } | |
| return result; | |
| } | |
| function korToEng(src) { | |
| var res = ""; | |
| if (src.length == 0) { | |
| return res; | |
| } | |
| for (var i = 0; i < src.length; i++) { | |
| var ch = src.charAt(i); | |
| var nCode = ch.charCodeAt(0); | |
| var result = ''; | |
| var ์ด์ฑ, ์ค์ฑ, ์ข ์ฑ; | |
| if (44032 <= nCode && nCode <= 55203) { | |
| nCode -= 44032; | |
| ์ด์ฑ = ์ด์ฑ๋ชจ์.charAt(Math.floor(nCode / (21 * 28))); | |
| ์ค์ฑ = ์ค์ฑ๋ชจ์.charAt(Math.floor(nCode / 28) % 21); | |
| ์ข ์ฑ = ์ข ์ฑ๋ชจ์.charAt(nCode % 28 - 1); | |
| res += convertํ์(์ด์ฑ); | |
| var ๋ชจ์๋ถํด = ๋ชจ์๋ถํดํ๊ธฐ(์ค์ฑ); | |
| if (๋ชจ์๋ถํด) { | |
| res += convertํ์(๋ชจ์๋ถํด); | |
| } else { | |
| res += convertํ์(์ค์ฑ); | |
| } | |
| var ์์๋ถํด = ์์๋ถํดํ๊ธฐ(์ข ์ฑ); | |
| if (์์๋ถํด) { | |
| res += convertํ์(์์๋ถํด); | |
| } else { | |
| res += convertํ์(์ข ์ฑ); | |
| } | |
| } else if (์ด์ฑ๋ชจ์.indexOf(ch) > -1) { | |
| res += convertํ์(ch); | |
| } else if (์ค์ฑ๋ชจ์.indexOf(ch) > -1) { | |
| var ๋ชจ์๋ถํด = ๋ชจ์๋ถํดํ๊ธฐ(ch); | |
| if (๋ชจ์๋ถํด) { | |
| res += convertํ์(๋ชจ์๋ถํด); | |
| } else { | |
| res += convertํ์(ch); | |
| } | |
| } else if (์ข ์ฑ๋ชจ์.indexOf(ch) > -1) { | |
| var ์์๋ถํด = ์์๋ถํดํ๊ธฐ(ch); | |
| if (์์๋ถํด) { | |
| res += convertํ์(์์๋ถํด); | |
| } else { | |
| res += convertํ์(ch); | |
| } | |
| } else { | |
| res += ch; | |
| } | |
| } | |
| return res; | |
| } | |
| function convert์ํ(src) { | |
| var result = ''; | |
| for (var i = 0; i < src.length; i++) { | |
| var ch = src.charAt(i); | |
| var index = ์์ดํ์ดํ.indexOf(ch); | |
| if (index >= 0) { | |
| result += ํ๊ธํ์ดํ.charAt(index); | |
| } else { | |
| result += ch; | |
| } | |
| } | |
| return result; | |
| } | |
| function convertํ์(src) { | |
| var result = ''; | |
| for (var i = 0; i < src.length; i++) { | |
| var ch = src.charAt(i); | |
| var index = ํ๊ธํ์ดํ.indexOf(ch); | |
| if (index >= 0) { | |
| result += ์์ดํ์ดํ.charAt(index); | |
| } else { | |
| result += ch; | |
| } | |
| } | |
| return result; | |
| } | |
| function is์์ดํ์ดํ(ch) { | |
| return ์์ดํ์ดํ.indexOf(ch) >= 0; | |
| } | |
| function is๋ชจ์(ch) { | |
| return ์์ดํ์ดํ.indexOf(ch) >= 19; | |
| } | |
| function is์์(ch) { | |
| return ์์ดํ์ดํ.indexOf(ch) < 19 && ์์ดํ์ดํ.indexOf(ch) >= 0; | |
| } | |
| function engToKor(src) { | |
| var res = ""; | |
| if (src.length == 0) | |
| return res; | |
| var ์ด์ฑ์์น = -1, ์ค์ฑ์์น = -1, ์ข ์ฑ์์น = -1; // ์ด์ฑ, ์ค์ฑ, ์ข ์ฑ | |
| for (var i = 0; i < src.length; i++) { | |
| var result = ํ๊ธ์กฐํฉํ๊ธฐ(src.slice(Math.max(src.length - 5 - i, 0), src.length - i)); | |
| // console.log(result); | |
| i += result.์ฌ์ฉํ๊ธ์์ - 1; | |
| res = result.์กฐํฉ๋ํ๊ธ + res; | |
| } | |
| return res; | |
| } | |
| function combineํ๊ธ(์ด์ฑ, ์ค์ฑ, ์ข ์ฑ) { | |
| return String.fromCharCode(44032 + ์ด์ฑ๋ชจ์.indexOf(์ด์ฑ) * 21 * 28 + ์ค์ฑ๋ชจ์.indexOf(์ค์ฑ) * 28 + ์ข ์ฑ๋ชจ์.indexOf(์ข ์ฑ) + 1); | |
| } | |
| function ๋ชจ์๊ฒฐํฉํ๊ธฐ(ch1, ch2) { | |
| var result = null; | |
| if (ch1 == 'ใ ' && ch2 == 'ใ ') { // ใ | |
| result = 'ใ '; | |
| } else if (ch1 == 'ใ ' && ch2 == 'ใ ') { // ใ | |
| result = 'ใ '; | |
| } else if (ch1 == 'ใ ' && ch2 == 'ใ ฃ') { // ใ | |
| result = 'ใ '; | |
| } else if (ch1 == 'ใ ' && ch2 == 'ใ ') { // ใ | |
| result = 'ใ '; | |
| } else if (ch1 == 'ใ ' && ch2 == 'ใ ') { // ใ | |
| result = 'ใ '; | |
| } else if (ch1 == 'ใ ' && ch2 == 'ใ ฃ') { // ใ | |
| result = 'ใ '; | |
| } else if (ch1 == 'ใ ก' && ch2 == 'ใ ฃ') { // ใ ข | |
| result = 'ใ ข'; | |
| } | |
| return result; | |
| } | |
| function ๋ชจ์๋ถํดํ๊ธฐ(ch) { | |
| switch (ch) { | |
| case 'ใ ': | |
| return 'ใ ใ '; | |
| case 'ใ ': | |
| return 'ใ ใ '; | |
| case 'ใ ': | |
| return 'ใ ใ ฃ'; | |
| case 'ใ ': | |
| return 'ใ ใ '; | |
| case 'ใ ': | |
| return 'ใ ใ '; | |
| case 'ใ ': | |
| return 'ใ ใ ฃ'; | |
| case 'ใ ข': | |
| return 'ใ กใ ฃ'; | |
| } | |
| return null; | |
| } | |
| function ์์๊ฒฐํฉํ๊ธฐ(ch1, ch2) { | |
| var result = null; | |
| if (ch1 == 'ใฑ' && ch2 == 'ใ ') { // ใณ | |
| result = 'ใณ'; | |
| } else if (ch1 == 'ใด' && ch2 == 'ใ ') { // ใต | |
| result = 'ใต'; | |
| } else if (ch1 == 'ใด' && ch2 == 'ใ ') { // ใถ | |
| result = 'ใถ'; | |
| } else if (ch1 == 'ใน' && ch2 == 'ใฑ') { // ใบ | |
| result = 'ใบ'; | |
| } else if (ch1 == 'ใน' && ch2 == 'ใ ') { // ใป | |
| result = 'ใป'; | |
| } else if (ch1 == 'ใน' && ch2 == 'ใ ') { // ใผ | |
| result = 'ใผ'; | |
| } else if (ch1 == 'ใน' && ch2 == 'ใ ') { // ใฝ | |
| result = 'ใฝ'; | |
| } else if (ch1 == 'ใน' && ch2 == 'ใ ') { // ใพ | |
| result = 'ใพ'; | |
| } else if (ch1 == 'ใน' && ch2 == 'ใ ') { // ใฟ | |
| result = 'ใฟ'; | |
| } else if (ch1 == 'ใน' && ch2 == 'ใ ') { // ใ | |
| result = 'ใ '; | |
| } else if (ch1 == 'ใ ' && ch2 == 'ใ ') { // ใ | |
| result = 'ใ '; | |
| } | |
| return result; | |
| } | |
| function ์์๋ถํดํ๊ธฐ(ch) { | |
| switch (ch) { | |
| case 'ใณ': | |
| return 'ใฑใ '; | |
| case 'ใต': | |
| return 'ใดใ '; | |
| case 'ใถ': | |
| return 'ใดใ '; | |
| case 'ใบ': | |
| return 'ในใฑ'; | |
| case 'ใป': | |
| return 'ในใ '; | |
| case 'ใผ': | |
| return 'ในใ '; | |
| case 'ใฝ': | |
| return 'ในใ '; | |
| case 'ใพ': | |
| return 'ในใ '; | |
| case 'ใฟ': | |
| return 'ในใ '; | |
| case 'ใ ': | |
| return 'ในใ '; | |
| case 'ใ ': | |
| return 'ใ ใ '; | |
| } | |
| return null; | |
| } | |
| function K2E2K(src){ | |
| if (ENG.indexOf(src[0]) == -1){ | |
| return korToEng(src); | |
| }else{ | |
| return engToKor(src); | |
| } | |
| } | |
| var seApp = Application('System Events'); | |
| var app = Application.currentApplication(); | |
| seApp.includeStandardAdditions = true; | |
| app.includeStandardAdditions = true; | |
| s = seApp.theClipboard(); | |
| s = K2E2K(s); | |
| // console.log(K2E2K(s)); | |
| app.setTheClipboardTo(s); | |
| s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment