User:SlowPhoton/Script/AssameseTextCleaner.js

From Meta, a Wikimedia project coordination wiki

Note: After publishing, 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: Press Ctrl-F5.
/*
    Test Code
*/

$(document).ready(function() {

    var CleanupText = function() {
        $('#wpTextbox1').wikiEditor('addToToolbar', {
            'section': 'main',
            'group': 'insert',
            'tools': {
                'CleanupText': {
                    label: 'অসমীয়া লিখোতে হোৱা কেইটামান সাধাৰণ ভুল প্ৰতিস্থাপন কৰক',
                    type: 'button',
                    icon: '//upload.wikimedia.org/wikipedia/commons/6/67/Assamese_letter_ra.svg',
                    action: {
                        type: 'callback',
                        execute: function() {
                        
							 getText = $('#wpTextbox1').val();
							 
							 newText = getText.replace(/  +/g, " ");
							 newText = newText.replace(/র/g, "ৰ");
							 newText = newText.replace(/{{ /g, "{{");
							 newText = newText.replace(/৷/g, "।");              // bengali currency numerator four
							 newText = newText.replace(/ ।/g, "।");
							 newText = newText.replace(/।/g, "। ");
							 newText = newText.replace(/।।/g, "॥");
							 newText = newText.replace(/। ।/g, "॥");
							 newText = newText.replace(/ !/g, "!");
							 newText = newText.replace(/ ;/g, ";");
							 newText = newText.replace(/ \?/g, "?");
							 // newText = newText.replace(/\(/g, " (");
							 // newText = newText.replace(/\)/g, ") ");
							 // newText = newText.replace(/\{/g, " {");
							 // newText = newText.replace(/\}/g, "} ");
							 // newText = newText.replace(/\[/g, " [");
							 // newText = newText.replace(/\]/g, "] ");
							 // newText = newText.replace(/\] \]/g, "]]");
							 // newText = newText.replace(/\[ \[/g, "[[");
							 // newText = newText.replace(/\} \}/g, "}}");
							 // newText = newText.replace(/\{ \{/g, "{{");
							 newText = newText.replace(/অাা|অা|আা/g, "আ"); 
							 newText = newText.replace(/ো|াে/g, "ো");
							 newText = newText.replace(/ড৹|ড০|ড°|ডঃ|ডo|ড0/g, "ড॰");
							 // newText = newText.replace(/,/g, ", ");
							 newText = newText.replace(/বাংলা/g, "বঙালী" );
							 newText = newText.replace(/বঙালীদেশ/g, "বাংলাদেশ");
							 newText = newText.replace(/মাৰ্কিন/g, "আমেৰিকান");
							 newText = newText.replace(/আমেৰিকান যুক্তৰাষ্ট্ৰ/g, "আমেৰিকা যুক্তৰাষ্ট্ৰ");
							 newText = newText.replace(/মানকাছাৰ/g, "মানকাচৰ");
							 newText = newText.replace(/মানকাচাৰ/g, "মানকাচৰ");
							 newText = newText.replace(/বঙালি/g, "বঙালী");
							 newText = newText.replace(/বাঙালি/g, "বঙালী");
							 newText = newText.replace(/বাঙালী/g, "বঙালী");
							 newText = newText.replace(/কেৰেলা/g, "কেৰালা");
							 newText = newText.replace(/পদ্ম বিভূষণ/g, "পদ্মবিভূষণ");
							 newText = newText.replace(/পদ্ম ভূষণ/g, "পদ্মভূষণ");
							 newText = newText.replace(/পাঞ্জাৱ/g, "পঞ্জাব");
							 newText = newText.replace(/পঞ্জাৱ/g, "পঞ্জাব");
							 newText = newText.replace(/পাঞ্জাব/g, "পঞ্জাব");
							 newText = newText.replace(/বৃটিছ/g, "ব্ৰিটিছ");
							 newText = newText.replace(/বৃটিচ/g, "ব্ৰিটিছ");
							 newText = newText.replace(/ব্ৰিটিচ/g, "ব্ৰিটিছ");
							 newText = newText.replace(/অকাডেমী/g, "অকাডেমি");
							 //newText = newText.replace(/একাডেমী/g, "অকাডেমি");
							 newText = newText.replace(/ফ্লিম/g, "ফিল্ম");
							 newText = newText.replace(/তামোলী/g, "তামুলী");
							 newText = newText.replace(/ৱিকিপেডিয়া/g, "ৱিকিপিডিয়া");
							 newText = newText.replace(/পাকিস্থান/g, "পাকিস্তান");
							 newText = newText.replace(/হিন্দুস্থান/g, "হিন্দুস্তান");
							 newText = newText.replace(/হিন্দুঃস্থান/g, "হিন্দুস্তান");
							 newText = newText.replace(/তেলেগু/g, "তেলুগু");
							 newText = newText.replace(/মলয়ালম/g, "মালয়ালম");
							 newText = newText.replace(/মালায়ালম/g, "মালয়ালম");
							 newText = newText.replace(/মালায়ম/g, "মালয়ালম");
							 newText = newText.replace(/মালায়লম/g, "মালয়ালম");
							 newText = newText.replace(/মালায়ালাম/g, "মালয়ালম");
							 newText = newText.replace(/পশ্চিমবঙ্গ/g, "পশ্চিমবংগ");
							 newText = newText.replace(/গোঁহাই/g, "গোহাঁই");
							 newText = newText.replace(/জেভেলিন/g, "জেভলীন");
							 newText = newText.replace(/জেভেলীন/g, "জেভলীন");
							 newText = newText.replace(/আন্তৰ্জাতিক/g, "আন্তঃৰাষ্ট্ৰীয়");
							 // newText = newText.replace(/পিছত/g, "পাছত");
							 newText = newText.replace(/access-date/g, "accessdate");
							 newText = newText.replace(/ {{cn}}/g, "{{cn}}");
							 newText = newText.replace(/ {{Sfn/g, "{{Sfn");
							 newText = newText.replace(/ {{sfn/g, "{{sfn");
							 
							 // newText = newText.replace(/0/g, "০");
							 // newText = newText.replace(/1/g, "১");
							 // newText = newText.replace(/2/g, "২");
							 // newText = newText.replace(/3/g, "৩");
							 // newText = newText.replace(/4/g, "৪");
							 // newText = newText.replace(/5/g, "৫");
							 // newText = newText.replace(/6/g, "৬");
							 // newText = newText.replace(/7/g, "৭");
							 // newText = newText.replace(/8/g, "৮");
							 // newText = newText.replace(/9/g, "৯");
							 
							 // newText = newText.replace(/’/g, "'");
							 // newText = newText.replace(/‘/g, "'");
							 // newText = newText.replace(/||/g, " || ");
							 
							 newText = newText.replace(/  +/g, " ");
							 newText = newText.replace(/ <ref/g, "<ref");
							 // newText = newText.replace(/ '/g, "'");
							 // newText = newText.replace(/ "/g, '"');
							 newText = newText.replace(/^ +| +$/gm, "");
							 newText = newText.replace(/। ”/g, "।”");
							 
							 $('#wpTextbox1').val(newText);
							 
							 //if (mw.config.get("wgSiteName") !== "ৱিকিউৎস"){
							//	$("#wpSummary").val("বৰ্ণাশুদ্ধি নিবাৰণ; র->ৰ");
							// }
                        }
                    }
                }
            }
        });

    };
    
/* Check if view is in edit mode and that the required modules are available. Then, customize the toolbar … */
    if ($.inArray(mw.config.get('wgAction'), ['edit', 'submit']) !== -1) {
        $.when(mw.loader.using('ext.wikiEditor'), $.ready)
            .then(CleanupText);
    }
});