Jump to content

User:IceWelder/USEnglish.js

From Wikipedia, the free encyclopedia
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// NOTICE: This script uses Ohconfucius' EngvarB script, all credit goes to them
$.ajax('/w/index.php?title=User:Ohconfucius/script/EngvarB.js&action=raw&ctype=text/javascript', {
    dataType: 'script',
    cache: true
}).then(function() {
    ohc_retask_pipes = function(editor) {}

    ohc_ENGVAR_insert_template = function(editor, variation) {
        // Add a template to the article identifying English variant
        // Build a string with "Month YYYY"
        var date_object = new Date();
        var month_map = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
        var date_string = month_map[date_object.getMonth()] + ' ' + date_object.getFullYear();

        var template_string;
        switch (variation) {
            case 'B':
                template_string = '{{Use British English|date=' + date_string + '}}';
                break;
            case 'O':
                template_string = '{{Use Oxford spelling|date=' + date_string + '}}';
                break;
            case 'C':
                template_string = '{{Use Canadian English|date=' + date_string + '}}';
                break;
            case 'U':
                template_string = '{{Use American English|date=' + date_string + '}}';
                break;
            default:
                return;
        }

        // Matcher for every English variation template
        var template_matcher = new RegExp('{{(?:[_ ]*Template[_ ]*:)?[_ ]*(?:Use[_ ]+(?:British(?:[_ ]+\\(?(?:Oxford|IUPAC)\\)?)?|X|Hong Kong|European|Commonweal?th|Scottish|American|Australian|Canadian|Indian|Irish|Hiberno|Jamaican|Nigerian|Bangladeshi|Pakistani|Singapore(?:an)?|South African|Trinidadian|New Zealand|US|U.S.|Oxford|IUPAC)(?:(?:[_ ]+|-)English)?(?:[_ ]+Oxford)?(?:[_ ]+spelling)?|Engvar(?:Au?|Ox?|[BC])|U?BE|EB|Use BrE|En-(?:US|GB(?:-oxendict)?|CA|NZ))(?:/sandbox)?[_ ]*(?:|\\|[ ]*date[ ]*=[^{}|]*)[ ]*}}', 'gi');

        // If not already tagged
        if (!editor.contains(template_matcher)) {
            // Prepend new template
            editor.prepend(template_string + '\r\n');
        } else {
            // Replace old template
            editor.replace(template_matcher, template_string);
        }
    }

    ohc_ENGVAR_edit_summary = function(editor, variation) {
        // Add a tag to the summary box
        var variation_string;
        switch (variation) {
            case 'B':
                variation_string = 'British English';
                break;
            case 'O':
                variation_string = 'Oxford spelling';
                break;
            case 'C':
                variation_string = 'Canadian English';
                break;
            case 'U':
                variation_string = 'American English';
                break;
            default:
                return;
        }

        editor.appendEditSummary(variation_string);
    }
});