Difference between revisions of "MediaWiki:Edittools.js"

From Learning Languages Through Video Games
Jump to navigationJump to search
(Purging jQuery and making a few other fixes (won't know if this will work till I try it))
Line 1: Line 1:
 
function runFixer(fixer) {
 
function runFixer(fixer) {
     var textarea = document.getElementById('wpTextbox1');
+
     const textarea = document.getElementById('wpTextbox1');
 
     if(textarea.selectionStart === undefined) {
 
     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.");
 
         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;
+
     const sel_start = textarea.selectionStart;
     var sel_end = textarea.selectionEnd;
+
     const sel_end = textarea.selectionEnd;
     var selected_text = textarea.value.substring(sel_start, sel_end);
+
     const selected_text = textarea.value.substring(sel_start, sel_end);
 
     if(!selected_text) {
 
     if(!selected_text) {
 
         alert("No text was selected!");
 
         alert("No text was selected!");
Line 16: Line 16:
  
 
function fixJa(text) {
 
function fixJa(text) {
     var substitutions = {};
+
     let substitutions = {};
     if($j('#ja-merge-dakuten').is(':checked')) {
+
     if(document.getElementById('ja-merge-dakuten').value) {
 
         substitutions = {
 
         substitutions = {
 
             'か゛': 'が',
 
             'か゛': 'が',
Line 72: Line 72:
 
         };
 
         };
 
     }
 
     }
     if($j('#ja-periods').is(':checked')) {
+
     if(document.getElementById('ja-periods').value) {
 
         substitutions['\\.'] = '。';
 
         substitutions['\\.'] = '。';
         substitutions[','] = '、'
+
         substitutions[','] = '、';
 
     }
 
     }
     if($j('#ja-hyphens').is(':checked')) {
+
     if(document.getElementById('ja-hyphens').value) {
 
         substitutions['-'] = 'ー';
 
         substitutions['-'] = 'ー';
 
     }
 
     }
     if($j('#ja-spaces').is(':checked')) {
+
     if(document.getElementById('ja-spaces').value) {
 
         substitutions[' '] = '\u3000';
 
         substitutions[' '] = '\u3000';
 
     }
 
     }
     if($j('#ja-exclam').is(':checked')) {
+
     if(document.getElementById('ja-exclam').value) {
 
         substitutions['\\!'] = '!';
 
         substitutions['\\!'] = '!';
 
         substitutions['\\?'] = '?';
 
         substitutions['\\?'] = '?';
 
     }
 
     }
     for(x in substitutions) {
+
     for(const x of substitutions) {
         var regexp = new RegExp(x, 'g');
+
         const regexp = new RegExp(x, 'g');
         text = text.replace(regexp, substitutions[x])
+
         text = text.replace(regexp, substitutions[x]);
 
     }
 
     }
 
     return text;
 
     return text;
Line 100: Line 100:
  
 
addOnloadHook(function() {
 
addOnloadHook(function() {
     $j('#fixer-ja').append(
+
     document.getElementById('fixer-ja').insertAdjacentHTML('beforeend',
 
         "<input id='ja-merge-dakuten' type='checkbox' checked='checked' /> Merge dakuten and handakuten (か゛ &rarr; が)<br />" +
 
         "<input id='ja-merge-dakuten' type='checkbox' checked='checked' /> Merge dakuten and handakuten (か゛ &rarr; が)<br />" +
 
         "<input id='ja-periods' type='checkbox' /> Replace periods and Western commas with maru and Japanese commas<br />" +
 
         "<input id='ja-periods' type='checkbox' /> Replace periods and Western commas with maru and Japanese commas<br />" +
Line 109: Line 109:
 
         "<input type='button' onclick='runFixer(fixJa)' value='Run Japanese fixer' />"
 
         "<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)' /")*/
+
     /*document.getElementById('#kanafier').insertAdjacentHTML('beforeend', "<input type='button' onclick='runFixer(kanafy)' value='Run kanafier (NOT WORKING YET)' /");*/
 
});
 
});

Revision as of 01:12, 13 May 2022

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 (か゛ &rarr; が)<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)' /");*/
});