Jump to content

User:Wumbolo/pronouns.js

From Wikipedia, the free encyclopedia
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.
(function($, mw) {
    'use strict';

    var wgPageName = mw.config.get('wgPageName');
    var wgUserName = mw.config.get('wgUserName');
    var wgNamespaceNumber = mw.config.get('wgNamespaceNumber');
    var wgPageNameSlashPos = wgPageName.indexOf("/");

    if (wgNamespaceNumber === 2 || wgNamespaceNumber === 3) {
        $.getJSON(
                mw.util.wikiScript('api'), {
                    action: "expandtemplates",
                    format: "json",
                    text: "{{gender|" + wgPageName.substring(wgPageName.indexOf(":") + 1, wgPageNameSlashPos == -1 ? wgPageName.length : wgPageNameSlashPos) + "}}",
                    prop: "wikitext"
                }
            ).done(function(data) {
                $('#mw-content-text').prepend('<p>(' + data.expandtemplates.wikitext + ')</p>');
            })
            .fail(function(data) {
                return;
            });
    }
})(jQuery, mediaWiki);