사용자:Hnc197/monobook.js

위키백과, 우리 모두의 백과사전.

참고: 설정을 저장한 후에 바뀐 점을 확인하기 위해서는 브라우저의 캐시를 새로 고쳐야 합니다. 구글 크롬, 파이어폭스, 마이크로소프트 엣지, 사파리: ⇧ Shift 키를 누른 채 "새로 고침" 버튼을 클릭하십시오. 더 자세한 정보를 보려면 위키백과:캐시 무시하기 항목을 참고하십시오.

<!-- // --> <pre>
// customized javascript for [[사용자:토끼군]].
// all scripts here is put in public domain, unless explicitly specified.

function l_escape(text) {
    var re = new RegExp("'","g");
    text = text.replace(re,"\\'");
    re = new RegExp("\\n","g");
    text = text.replace(re,"\\n");
    return "'" + text + "'";
}

////////////////////////////////////////////////////////////
// redesigning edit page
//   - remove toolbar and character table
//   - add new customized character table

function l_create_insertfunc(entry, value, message) {
    $ = function(str, needle, repl) {
        str = str.split(needle);
        repr = l_escape(str[0]);
        for (i = 1; i < str.length; ++i) repr += ' + ' + repl + ' + ' + l_escape(str[i]);
        return repr;
    };

    mark = arguments[3];
    if (!mark) mark = '$';
    prev = value;
    body = 'l = prompt(' + l_escape(message) + ', prev); if (!l) return null; prev = l; return ';
    if (typeof entry == 'string') body += $(entry, replacement, 'l');
    else body += '[' + $(entry[0], mark, 'l') + ', ' + $(entry[1], mark, 'l') + ']';
    return new Function('', body);
}

var l_editpage_specialchars = [
    // [accesskey, anchor, text OR [open, close] OR function returning the same or null]
    // accesskey can be one of: 1234567890~`!@#$%^&*()-_\|[]{};:'"<>/?
    ['', '\xa0·\xa0', '·'],
    ['0', '…', '…'],
    ['!', '\xa0¹\xa0', '¹'],
    ['@', '\xa0²\xa0', '²'],
    ['#', '\xa0³\xa0', '³'],
    ['', '—', '—'],
    ['', '±', '±'],
    ['', '×', '×'],
    ['', '≤', '≤'],
    ['', '≥', '≥'],
    ['1', '〈〉', ['〈', '〉']],
    ['2', '《》', ['《', '》']],
    ['3', '\xa0‘’\xa0', ['‘', '’']],
    ['4', '“”', ['“', '”']],
    ['', '→', '→'],
    ['', '←', '←'],
    [';', '[[분류]]', ['[[분류:', ']]']],
    ['/', '<ref>', ['<ref>', '</ref>']],
    ['?', '<references/>', ['== ', ' ==\n<references/>\n']],
    ['(', '<nowiki>', ['<nowiki>', '</nowiki>']],
    [')', '<math>', ['<math>', '</math>']],
    ['-', '{{lang}}', l_create_insertfunc(['{{lang|$|', '}}'], 'en', 'insert language code')],
    ['_', '{{llang}}', l_create_insertfunc(['{{llang|$|', '}}'], 'en', 'insert language code')],
    ['\\', '--~~~~', ' --~~~~'],
];

function l_editpage_insert(k) {
    repl = l_editpage_specialchars[k][2];
    if (typeof repl == 'function') {
        repl = repl();
        if (repl == null) return;
    }
    if (typeof repl == 'string') {
        // TODO: it should replace selected text if any.
        insertTags(repl, '', '');
    } else {
        insertTags(repl[0], repl[1], '');
    }
}

function l_editpage_redesign() {
    // ensure this page is edit page
    textarea = document.getElementById('wpTextbox1');
    if (!textarea) textarea = document.getElementById('wpUploadDescription');
    if (!textarea) return;

    // remove useless toolbar and character table
    if (toolbar = document.getElementById('toolbar'))
        toolbar.parentNode.removeChild(toolbar);
    if (chartables = document.getElementById('editpage-specialchars'))
        chartables.parentNode.removeChild(chartables);

    // insert new character table
    chartables = document.createElement('DIV');
    chartables.id = 'editpage-specialchars';
    delim = '특수 문자 입력: ';
    for (i = 0; i < l_editpage_specialchars.length; ++i) {
        entry = l_editpage_specialchars[i];
        link = document.createElement('A');
        link.href = '#';
        link.accessKey = entry[0];
        link.onclick = new Function('', 'l_editpage_insert(' + i + '); return false;');
        link.appendChild(document.createTextNode(entry[1]));
        chartables.appendChild(document.createTextNode(delim));
        chartables.appendChild(link);
        if (entry[0]) {
            shortcut = document.createElement('SMALL');
            shortcut.appendChild(document.createTextNode(entry[0]));
            chartables.appendChild(shortcut);
        }
        delim = ' ';
    }
    textarea.parentNode.insertBefore(chartables, textarea);
}

if (is_gecko) addOnloadHook(l_editpage_redesign);

//////////////////////////////////////////////////////////// </pre>