사용자:Ash/vector.js

리버티게임, 모두가 만들어가는 자유로운 게임

참고: 설정을 저장한 후에 바뀐 점을 확인하기 위해서는 브라우저의 캐시를 새로 고쳐야 합니다.

  • 파이어폭스 / 사파리: Shift 키를 누르면서 새로 고침을 클릭하거나, Ctrl-F5 또는 Ctrl-R을 입력 (Mac에서는 ⌘-R)
  • 구글 크롬: Ctrl-Shift-R키를 입력 (Mac에서는 ⌘-Shift-R)
  • 인터넷 익스플로러 / 엣지: Ctrl 키를 누르면서 새로 고침을 클릭하거나, Ctrl-F5를 입력.
  • 오페라: Ctrl-F5를 입력.
// <pre>
// 안드로메다어 번역기
// 지원 자판: 두벌식, 세벌식 390, 세벌식 최종
// 원본 스크립트: http://incubator.wikimedia.org/w/index.php?title=User:Leque/monobook.js&action=edit&oldid=76535
 
var keyboard_table = {
    "2set_1st":
    { 0:'r', 1:'R', 2:'s', 3:'e', 4:'E', 5:'f',
      6:'a', 7:'q', 8:'Q', 9:'t',10:'T',11:'d',
     12:'w',13:'W',14:'c',15:'z',16:'x',17:'v',
     18:'g',
    },
    "2set_2nd":
    { 0:'k',  1:'o',  2:'i',  3:'O',   4:'j',   5:'p',
      6:'u',  7:'P',  8:'h',  9:'hk', 10:'ho', 11:'hl',
     12:'y', 13:'n', 14:'nj',15:'np', 16:'nl', 17:'b',
     18:'m', 19:'ml',20:'l',
    },
    "2set_3rd":
    { 0:'',   1:'r',  2:'R',  3:'rt',  4:'s',  5:'sw',
      6:'sg', 7:'e',  8:'f',  9:'fr', 10:'fa',11:'fq',
     12:'ft',13:'fx',14:'fv',15:'fg', 16:'a', 17:'q',
     18:'qt',19:'t', 20:'T', 21:'d',  22:'w', 23:'c',
     24:'z', 25:'x', 26:'v', 27:'g',
    },
    "3set_390_1st":
    { 0:'k', 1:'kk', 2:'h', 3:'u', 4:'uu', 5:'y',
      6:'i', 7:';',  8:';;',9:'n',10:'nn',11:'j',
     12:'l',13:'ll',14:'o',15:'0',16:'\'',17:'o',
     18:'m',
    },
    "3set_390_2nd":
    { 0:'f',  1:'r',  2:'6',  3:'R',   4:'t',   5:'c',
      6:'e',  7:'7',  8:'v',  9:'/f', 10:'/r', 11:'/d',
     12:'4', 13:'b', 14:'9t',15:'9c', 16:'9d', 17:'5',
     18:'g', 19:'8', 20:'d',
    },
    "3set_390_3rd":
    { 0:'',   1:'x',  2:'xx',  3:'xq',  4:'s',  5:'s!',
      6:'S',  7:'A',  8:'w',   9:'D',  10:'C', 11:'w3',
     12:'wq',13:'wW',14:'wQ', 15:'w1', 16:'z', 17:'3',
     18:'X',19:'q', 20:'2',  21:'a',  22:'!', 23:'Z',
     24:'E', 25:'W', 26:'Q',  27:'1',
    },
    "3set_391_1st":
    { 0:'k', 1:'kk', 2:'h', 3:'u', 4:'uu', 5:'y',
      6:'i', 7:';',  8:';;',9:'n',10:'nn',11:'j',
     12:'l',13:'ll',14:'o',15:'0',16:'\'',17:'o',
     18:'m',
    },
    "3set_391_2nd":
    { 0:'f',  1:'r',  2:'6',  3:'G',   4:'t',   5:'c',
      6:'e',  7:'7',  8:'v',  9:'/f', 10:'/r', 11:'/d',
     12:'4', 13:'b', 14:'9t',15:'9c', 16:'9d', 17:'5',
     18:'g', 19:'8', 20:'d',
    },
    "3set_391_3rd":
    { 0:'',   1:'x',  2:'!',  3:'xq',  4:'s',  5:'E',
      6:'S',  7:'A',  8:'w',   9:'@',  10:'F', 11:'D',
     12:'T',13:'%',14:'$', 15:'R', 16:'z', 17:'3',
     18:'X',19:'q', 20:'2',  21:'a',  22:'#', 23:'Z',
     24:'C', 25:'W', 26:'Q',  27:'1',
    },
}
function isHangeul(code) {
    if (code >= 0xac00 && code <= 0xd7af) return true;
    else return false;
}
 
function break_syllables(code) {
    var result = new Array(0, 0, 0);
    code -= 0xac00;
    result[2] = code % 28;
    result[1] = Math.floor(((code % 588) - result[2]) / 28);
    result[0] = Math.floor(code / 588);
    return result;
}
 
var conversionFunctions = {
    "2set": function(str){
        var c = str.charCodeAt(0);
        if(!isHangeul(c)) return str;
        var a=break_syllables(c);
        return keyboard_table['2set_1st'][a[0]]+keyboard_table['2set_2nd'][a[1]]+keyboard_table['2set_3rd'][a[2]];
    },
    "3set_390": function(str){
        var c = str.charCodeAt(0);
        if(!isHangeul(c)) return str;
        var a=break_syllables(c);
        return keyboard_table['3set_390_1st'][a[0]]+keyboard_table['3set_390_2nd'][a[1]]+keyboard_table['3set_390_3rd'][a[2]];
    },
    "3set_final": function(str){
        var c = str.charCodeAt(0);
        if(!isHangeul(c)) return str;
        var a=break_syllables(c);
        return keyboard_table['3set_391_1st'][a[0]]+keyboard_table['3set_391_2nd'][a[1]]+keyboard_table['3set_391_3rd'][a[2]];
    },
};
 
var menu_items = {
    "두벌식": "2set",
    "세벌식 390": "3set_390",
    "세벌식 최종": "3set_final",
}
 
 
function getParameter(search, param) {
    var r;
 
    if (r = search.match("[?&;]" + param + "=([-._~a-zA-Z0-9]*)")) {
	return r[1];
    } else {
	return null;
    }
}
 
function convertAndromeda(kind) {
    var converter = conversionFunctions[kind];
    var elems = document.getElementsByTagName("*");
    var i, j;
 
    for (i = 0; i < elems.length; i++) {
	var elem = elems.item(i);
	var nodes = elem.childNodes;
 
	for (j = 0; j < nodes.length; j++) {
	    if (nodes.item(j).nodeType == 3) {
		var text_node = nodes.item(j);
		text_node.nodeValue = text_node.nodeValue.replace(/./g, function(str) { return converter(str) });
	    }
	}
    }
 
}
 
function initAndromedaConverter() {
    var anchor, li;
    var menu = document.getElementById("ca-edit").parentNode;
 
    for (var label in menu_items) {
	var v = menu_items[label];
	anchor = document.createElement("a");
	anchor.appendChild(document.createTextNode(label));
	anchor.href = document.location.pathname + "?variant=" + v;
 
        spann = document.createElement("span");
        spann.appendChild(anchor);
 
	li = document.createElement("li");
	li.id = "char-trans:" + v;
	li.appendChild(spann);
 
	menu.appendChild(li);
    }
 
    var variant = getParameter(document.location.search, "variant");
    if (variant)
	convertAndromeda(variant);
}
 
if (window.addEventListener) {
    window.addEventListener("load", initAndromedaConverter, false);
} else if (window.attachEvent) {
    window.attachEvent("onload", initAndromedaConverter);
}
 
//</pre>