User:SlowPhoton/Script/AssameseDigitReplacer.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 ReplaceDigit = function() {
        $('#wpTextbox1').wikiEditor('addToToolbar', {
            'section': 'main',
            'group': 'insert',
            'tools': {
                'ReplaceDigit': {
                    label: 'অসমীয়া-আৰবী অংক পৰিবৰ্তন কৰক',
                    type: 'button',
                    icon: '//upload.wikimedia.org/wikipedia/commons/thumb/d/d5/Gold_medal_icon_bn.svg/20px-Gold_medal_icon_bn.svg.png',
                    action: {
                        type: 'callback',
                        execute: function() {
                        
							 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, "৯");
							 
							 $('#wpTextbox1').val(newText);
                        }
                    }
                }
            }
        });

    };
    
/* 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(ReplaceDigit);
    }
});