Skip to content

Instantly share code, notes, and snippets.

@mingkyme
Created March 30, 2022 08:28
Show Gist options
  • Select an option

  • Save mingkyme/87219abb5df7e19c42a2e4bf175aaaea to your computer and use it in GitHub Desktop.

Select an option

Save mingkyme/87219abb5df7e19c42a2e4bf175aaaea to your computer and use it in GitHub Desktop.
Kor to Eng to Kor
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