Difference between revisions of "MediaWiki:Edittools.js"
From Learning Languages Through Video Games
Jump to navigationJump to searchLine 15: | Line 15: | ||
} | } | ||
− | function | + | function fixJa(text) { |
− | var substitutions = { | + | var substitutions = {}; |
− | 'か゛': 'が', | + | if($j('ja-merge-daukten').checked) { |
− | + | substitutions = { | |
− | + | 'か゛': 'が', | |
− | + | 'き゛': 'ぎ', | |
− | + | 'く゛': 'ぐ', | |
− | + | 'け゛': 'げ', | |
− | + | 'こ゛': 'ご', | |
− | + | 'さ゛': 'ざ', | |
− | + | 'し゛': 'じ', | |
− | + | 'す゛': 'ず', | |
− | + | 'せ゛': 'ぜ', | |
− | + | 'そ゛': 'ぞ', | |
− | + | 'た゛': 'だ', | |
− | + | 'ち゛': 'ぢ', | |
− | + | 'つ゛': 'づ', | |
− | + | 'て゛': 'で', | |
− | + | 'と゛': 'ど', | |
− | + | 'は゛': 'ば', | |
− | + | 'ひ゛': 'び', | |
− | + | 'ふ゛': 'ぶ', | |
− | + | 'へ゛': 'べ', | |
− | + | 'ほ゛': 'ぼ', | |
− | + | 'は゜': 'ぱ', | |
− | + | 'ひ゜': 'ぴ', | |
− | + | 'ふ゜': 'ぷ', | |
− | + | 'へ゜': 'ぺ', | |
− | + | 'ほ゜': 'ぽ', | |
− | + | 'カ゛': 'ガ', | |
− | + | 'キ゛': 'ギ', | |
− | + | 'ク゛': 'グ', | |
− | + | 'ケ゛': 'ゲ', | |
− | + | 'コ゛': 'ゴ', | |
− | + | 'サ゛': 'ザ', | |
− | + | 'シ゛': 'ジ', | |
− | + | 'ス゛': 'ズ', | |
− | + | 'セ゛': 'ゼ', | |
− | + | 'ソ゛': 'ゾ', | |
− | + | 'タ゛': 'ダ', | |
− | + | 'チ゛': 'ヂ', | |
− | + | 'ツ゛': 'ヅ', | |
− | + | 'テ゛': 'デ', | |
− | + | 'ト゛': 'ド', | |
− | + | 'ハ゛': 'バ', | |
− | + | 'ヒ゛': 'ビ', | |
− | + | 'フ゛': 'ブ', | |
− | + | 'ヘ゛': 'ベ', | |
− | + | 'ホ゛': 'ボ', | |
− | + | 'ハ゜': 'パ', | |
− | + | 'ヒ゜': 'ピ', | |
− | + | 'フ゜': 'プ', | |
− | + | 'ヘ゜': 'ペ', | |
− | }; | + | 'ホ゜': 'ポ', |
+ | 'ウ゛': 'ヴ' | ||
+ | }; | ||
+ | } | ||
+ | if($j('ja-periods').checked) { | ||
+ | substitutions['.'] = '。'; | ||
+ | } | ||
+ | if($j('ja-hyphens').checked) { | ||
+ | substitutions['-'] = 'ー'; | ||
+ | } | ||
+ | if($j('ja-spaces').checked) { | ||
+ | substitutions[' '] = '\u3000'; | ||
+ | } | ||
for(x in substitutions) { | for(x in substitutions) { | ||
var regexp = new RegExp(x, 'g'); | var regexp = new RegExp(x, 'g'); | ||
Line 83: | Line 95: | ||
addOnloadHook(function() { | addOnloadHook(function() { | ||
− | $j('#fixer- | + | $j('#fixer-ja').append( |
− | |||
"<input id='ja-merge-dakuten' type='checkbox' checked='checked' /> Merge dakuten and handakuten<br />" + | "<input id='ja-merge-dakuten' type='checkbox' checked='checked' /> Merge dakuten and handakuten<br />" + | ||
"<input id='ja-periods' type='checkbox' /> Replace periods with maru<br />" + | "<input id='ja-periods' type='checkbox' /> Replace periods with maru<br />" + | ||
"<input id='ja-hyphens' type='checkbox' /> Replace hypens w/ long vowel marks<br />" + | "<input id='ja-hyphens' type='checkbox' /> Replace hypens w/ long vowel marks<br />" + | ||
"<input id='ja-spaces' type='checkbox' /> Replace half-width spaces with full-width spaces<br />" + | "<input id='ja-spaces' type='checkbox' /> Replace half-width spaces with full-width spaces<br />" + | ||
− | "<input type='button' onclick='runFixer( | + | "<input type='button' onclick='runFixer(fixJa)' value='Run Japanese fixer' />" |
); | ); | ||
/*$j('#kanafier').append("<input type='button' onclick='runFixer(kanafy)' value='Run kanafier (NOT WORKING YET)' /")*/ | /*$j('#kanafier').append("<input type='button' onclick='runFixer(kanafy)' value='Run kanafier (NOT WORKING YET)' /")*/ | ||
}); | }); |
Revision as of 03:39, 12 September 2011
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 fixJa(text) { var substitutions = {}; if($j('ja-merge-daukten').checked) { substitutions = { 'か゛': 'が', 'き゛': 'ぎ', 'く゛': 'ぐ', 'け゛': 'げ', 'こ゛': 'ご', 'さ゛': 'ざ', 'し゛': 'じ', 'す゛': 'ず', 'せ゛': 'ぜ', 'そ゛': 'ぞ', 'た゛': 'だ', 'ち゛': 'ぢ', 'つ゛': 'づ', 'て゛': 'で', 'と゛': 'ど', 'は゛': 'ば', 'ひ゛': 'び', 'ふ゛': 'ぶ', 'へ゛': 'べ', 'ほ゛': 'ぼ', 'は゜': 'ぱ', 'ひ゜': 'ぴ', 'ふ゜': 'ぷ', 'へ゜': 'ぺ', 'ほ゜': 'ぽ', 'カ゛': 'ガ', 'キ゛': 'ギ', 'ク゛': 'グ', 'ケ゛': 'ゲ', 'コ゛': 'ゴ', 'サ゛': 'ザ', 'シ゛': 'ジ', 'ス゛': 'ズ', 'セ゛': 'ゼ', 'ソ゛': 'ゾ', 'タ゛': 'ダ', 'チ゛': 'ヂ', 'ツ゛': 'ヅ', 'テ゛': 'デ', 'ト゛': 'ド', 'ハ゛': 'バ', 'ヒ゛': 'ビ', 'フ゛': 'ブ', 'ヘ゛': 'ベ', 'ホ゛': 'ボ', 'ハ゜': 'パ', 'ヒ゜': 'ピ', 'フ゜': 'プ', 'ヘ゜': 'ペ', 'ホ゜': 'ポ', 'ウ゛': 'ヴ' }; } if($j('ja-periods').checked) { substitutions['.'] = '。'; } if($j('ja-hyphens').checked) { substitutions['-'] = 'ー'; } if($j('ja-spaces').checked) { substitutions[' '] = '\u3000'; } for(x in substitutions) { var regexp = new RegExp(x, 'g'); text = text.replace(regexp, substitutions[x]) } return text; } function kanafy(text) { /* TODO */ alert("Hey, what's your problem? I said this is not working yet!"); return text; } addOnloadHook(function() { $j('#fixer-ja').append( "<input id='ja-merge-dakuten' type='checkbox' checked='checked' /> Merge dakuten and handakuten<br />" + "<input id='ja-periods' type='checkbox' /> Replace periods with maru<br />" + "<input id='ja-hyphens' type='checkbox' /> Replace hypens w/ long vowel marks<br />" + "<input id='ja-spaces' type='checkbox' /> Replace half-width spaces with full-width spaces<br />" + "<input type='button' onclick='runFixer(fixJa)' value='Run Japanese fixer' />" ); /*$j('#kanafier').append("<input type='button' onclick='runFixer(kanafy)' value='Run kanafier (NOT WORKING YET)' /")*/ });