MediaWiki:Edittools.js

From Learning Languages Through Video Games
Revision as of 03:05, 20 October 2010 by Furrykef (talk | contribs)
Jump to navigationJump to search

Note: After saving, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
function runFixer(fixer) {
    var textarea = document.getElementById('wpTextbox1');
    if(textarea.selectionStart === undefined) {
        alert("Looks like the fixers won't work in this browser.\nIf you're running Internet Explorer, well, that's why.");
        return;
    }
    var sel_start = textarea.selectionStart;
    var sel_end = textarea.selectionEnd;
    var selected_text = textarea.value.substring(sel_start, sel_end);
    if(!selected_text) {
        alert("No text was selected!");
        return;
    }
    textarea.value = textarea.value.slice(0, sel_start) + fixer(selected_text) + textarea.value.slice(sel_end, -1);
}

function fixJp(text) {
    var substitutions = {
        'か゛': 'が',
        'き゛': 'ぎ',
        'く゛': 'ぐ',
        'け゛': 'げ',
        'こ゛': 'ご',
        'さ゛': 'ざ',
        'し゛': 'じ',
        'す゛': 'ず',
        'せ゛': 'ぜ',
        'そ゛': 'ぞ',
        'た゛': 'だ',
        'ち゛': 'ぢ',
        'つ゛': 'づ',
        'て゛': 'で',
        'と゛': 'ど',
        'は゛': 'ば',
        'ひ゛': 'び',
        'ふ゛': 'ぶ',
        'へ゛': 'べ',
        'ほ゛': 'ぼ',
        'は゜': 'ぱ',
        'ひ゜': 'ぴ',
        'ふ゜': 'ぷ',
        'へ゜': 'ぺ',
        'ほ゜': 'ぽ',
        'カ゛': 'ガ',
        'キ゛': 'ギ',
        'ク゛': 'グ',
        'ケ゛': 'ゲ',
        'コ゛': 'ゴ',
        'サ゛': 'ザ',
        'シ゛': 'ジ',
        'ス゛': 'ズ',
        'セ゛': 'ゼ',
        'ソ゛': 'ゾ',
        'タ゛': 'ダ',
        'チ゛': 'ヂ',
        'ツ゛': 'ヅ',
        'テ゛': 'デ',
        'ト゛': 'ド',
        'ハ゛': 'バ',
        'ヒ゛': 'ビ',
        'フ゛': 'ブ',
        'ヘ゛': 'ベ',
        'ホ゛': 'ボ',
        'ハ゜': 'パ',
        'ヒ゜': 'ピ',
        'フ゜': 'プ',
        'ヘ゜': 'ペ',
        'ホ゜': 'ポ',
        'ウ゛': 'ヴ'
    };
    for(x in substitutions) {
        var regexp = new RegExp(substitutions[x], 'g');
        text = string.replace(regexp, text)
    }
    return text;
}

addOnloadHook(function() {
    $j('#fixer-jp').append("<input type='button' onclick='runFixer(fixJp)' value='Run Japanese fixer' />");
});