Difference between revisions of "MediaWiki:Edittools.js"
From Learning Languages Through Video Games
Jump to navigationJump to searchLine 2: | Line 2: | ||
var textarea = document.getElementById('wpTextbox1'); | var textarea = document.getElementById('wpTextbox1'); | ||
if(textarea.selectionStart === undefined) { | if(textarea.selectionStart === undefined) { | ||
− | alert("Looks like the fixers won't work in this browser. | + | alert("Looks like the fixers won't work in this browser.\nIf you're running Internet Explorer, well, that's why."); |
return; | return; | ||
} | } | ||
var sel_start = textarea.selectionStart; | var sel_start = textarea.selectionStart; | ||
var sel_end = textarea.selectionEnd; | var sel_end = textarea.selectionEnd; | ||
− | |||
var selected_text = textarea.value.substring(sel_start, sel_end); | var selected_text = textarea.value.substring(sel_start, sel_end); | ||
if(!selected_text) { | if(!selected_text) { | ||
Line 13: | Line 12: | ||
return; | return; | ||
} | } | ||
− | textarea.value = textarea.value. | + | textarea.value = textarea.value.slice(0, sel_start) + fixer(selected_text) + textarea.value.slice(sel_end, -1); |
− | |||
} | } | ||
function fixJp(text) { | function fixJp(text) { | ||
− | return | + | var substitutions = { |
+ | /か゛/g, 'が', | ||
+ | /き゛/g, 'ぎ', | ||
+ | /く゛/g, 'ぐ', | ||
+ | /け゛/g, 'げ', | ||
+ | /こ゛/g, 'ご', | ||
+ | /さ゛/g, 'ざ', | ||
+ | /し゛/g, 'じ', | ||
+ | /す゛/g, 'ず', | ||
+ | /せ゛/g, 'ぜ', | ||
+ | /そ゛/g, 'ぞ', | ||
+ | /た゛/g, 'だ', | ||
+ | /ち゛/g, 'ぢ', | ||
+ | /つ゛/g, 'づ', | ||
+ | /て゛/g, 'で', | ||
+ | /と゛/g, 'ど', | ||
+ | /は゛/g, 'ば', | ||
+ | /ひ゛/g, 'び', | ||
+ | /ふ゛/g, 'ぶ', | ||
+ | /へ゛/g, 'べ', | ||
+ | /ほ゛/g, 'ぼ', | ||
+ | /は゜/g, 'ぱ', | ||
+ | /ひ゜/g, 'ぴ', | ||
+ | /ふ゜/g, 'ぷ', | ||
+ | /へ゜/g, 'ぺ', | ||
+ | /ほ゜/g, 'ぽ', | ||
+ | /カ゛/g, 'ガ', | ||
+ | /キ゛/g, 'ギ', | ||
+ | /ク゛/g, 'グ', | ||
+ | /ケ゛/g, 'ゲ', | ||
+ | /コ゛/g, 'ゴ', | ||
+ | /サ゛/g, 'ザ', | ||
+ | /シ゛/g, 'ジ', | ||
+ | /ス゛/g, 'ズ', | ||
+ | /セ゛/g, 'ゼ', | ||
+ | /ソ゛/g, 'ゾ', | ||
+ | /タ゛/g, 'ダ', | ||
+ | /チ゛/g, 'ヂ', | ||
+ | /ツ゛/g, 'ヅ', | ||
+ | /テ゛/g, 'デ', | ||
+ | /ト゛/g, 'ド', | ||
+ | /ハ゛/g, 'バ', | ||
+ | /ヒ゛/g, 'ビ', | ||
+ | /フ゛/g, 'ブ', | ||
+ | /ヘ゛/g, 'ベ', | ||
+ | /ホ゛/g, 'ボ', | ||
+ | /ハ゜/g, 'パ', | ||
+ | /ヒ゜/g, 'ピ', | ||
+ | /フ゜/g, 'プ', | ||
+ | /ヘ゜/g, 'ペ', | ||
+ | /ホ゜/g, 'ポ', | ||
+ | /ウ゛/g, 'ヴ' | ||
+ | }; | ||
+ | for(x in substitutions) { | ||
+ | text = string.replace(substitutions[x], text) | ||
+ | } | ||
+ | return text; | ||
} | } | ||
Revision as of 02:59, 20 October 2010
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 = { /か゛/g, 'が', /き゛/g, 'ぎ', /く゛/g, 'ぐ', /け゛/g, 'げ', /こ゛/g, 'ご', /さ゛/g, 'ざ', /し゛/g, 'じ', /す゛/g, 'ず', /せ゛/g, 'ぜ', /そ゛/g, 'ぞ', /た゛/g, 'だ', /ち゛/g, 'ぢ', /つ゛/g, 'づ', /て゛/g, 'で', /と゛/g, 'ど', /は゛/g, 'ば', /ひ゛/g, 'び', /ふ゛/g, 'ぶ', /へ゛/g, 'べ', /ほ゛/g, 'ぼ', /は゜/g, 'ぱ', /ひ゜/g, 'ぴ', /ふ゜/g, 'ぷ', /へ゜/g, 'ぺ', /ほ゜/g, 'ぽ', /カ゛/g, 'ガ', /キ゛/g, 'ギ', /ク゛/g, 'グ', /ケ゛/g, 'ゲ', /コ゛/g, 'ゴ', /サ゛/g, 'ザ', /シ゛/g, 'ジ', /ス゛/g, 'ズ', /セ゛/g, 'ゼ', /ソ゛/g, 'ゾ', /タ゛/g, 'ダ', /チ゛/g, 'ヂ', /ツ゛/g, 'ヅ', /テ゛/g, 'デ', /ト゛/g, 'ド', /ハ゛/g, 'バ', /ヒ゛/g, 'ビ', /フ゛/g, 'ブ', /ヘ゛/g, 'ベ', /ホ゛/g, 'ボ', /ハ゜/g, 'パ', /ヒ゜/g, 'ピ', /フ゜/g, 'プ', /ヘ゜/g, 'ペ', /ホ゜/g, 'ポ', /ウ゛/g, 'ヴ' }; for(x in substitutions) { text = string.replace(substitutions[x], text) } return text; } addOnloadHook(function() { $j('#fixer-jp').append("<input type='button' onclick='runFixer(fixJp)' value='Tempt Fate' />"); });