MediaWiki:Edittools.js
From Learning Languages Through Video Games
Jump to navigationJump to searchNote: 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) { const 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; } const sel_start = textarea.selectionStart; const sel_end = textarea.selectionEnd; const 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) { let substitutions = {}; if(document.getElementById('ja-merge-dakuten').value) { substitutions = { 'か゛': 'が', 'き゛': 'ぎ', 'く゛': 'ぐ', 'け゛': 'げ', 'こ゛': 'ご', 'さ゛': 'ざ', 'し゛': 'じ', 'す゛': 'ず', 'せ゛': 'ぜ', 'そ゛': 'ぞ', 'た゛': 'だ', 'ち゛': 'ぢ', 'つ゛': 'づ', 'て゛': 'で', 'と゛': 'ど', 'は゛': 'ば', 'ひ゛': 'び', 'ふ゛': 'ぶ', 'へ゛': 'べ', 'ほ゛': 'ぼ', 'は゜': 'ぱ', 'ひ゜': 'ぴ', 'ふ゜': 'ぷ', 'へ゜': 'ぺ', 'ほ゜': 'ぽ', 'カ゛': 'ガ', 'キ゛': 'ギ', 'ク゛': 'グ', 'ケ゛': 'ゲ', 'コ゛': 'ゴ', 'サ゛': 'ザ', 'シ゛': 'ジ', 'ス゛': 'ズ', 'セ゛': 'ゼ', 'ソ゛': 'ゾ', 'タ゛': 'ダ', 'チ゛': 'ヂ', 'ツ゛': 'ヅ', 'テ゛': 'デ', 'ト゛': 'ド', 'ハ゛': 'バ', 'ヒ゛': 'ビ', 'フ゛': 'ブ', 'ヘ゛': 'ベ', 'ホ゛': 'ボ', 'ハ゜': 'パ', 'ヒ゜': 'ピ', 'フ゜': 'プ', 'ヘ゜': 'ペ', 'ホ゜': 'ポ', 'ウ゛': 'ヴ' }; } if(document.getElementById('ja-periods').value) { substitutions['\\.'] = '。'; substitutions[','] = '、'; } if(document.getElementById('ja-hyphens').value) { substitutions['-'] = 'ー'; } if(document.getElementById('ja-spaces').value) { substitutions[' '] = '\u3000'; } if(document.getElementById('ja-exclam').value) { substitutions['\\!'] = '!'; substitutions['\\?'] = '?'; } for(const x of substitutions) { const 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() { document.getElementById('fixer-ja').insertAdjacentHTML('beforeend', "<input id='ja-merge-dakuten' type='checkbox' checked='checked' /> Merge dakuten and handakuten (か゛ → が)<br />" + "<input id='ja-periods' type='checkbox' /> Replace periods and Western commas with maru and Japanese commas<br />" + "<input id='ja-hyphens' type='checkbox' /> Replace hyphens w/ long vowel marks<br />" + "<input id='ja-spaces' type='checkbox' /> Replace half-width spaces with full-width spaces<br />" + "<input id='ja-exclam' type='checkbox' /> Replace half-width punctuation with full-width punctuation<br />" + "<br />" + "<input type='button' onclick='runFixer(fixJa)' value='Run Japanese fixer' />" ); /*document.getElementById('kanafier').insertAdjacentHTML('beforeend', "<input type='button' onclick='runFixer(kanafy)' value='Run kanafier (NOT WORKING YET)' /");*/ });