User:Pi Delport/monobook.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.
// Helpful: [[Wikipedia:WikiProject User scripts/Guide]]

// Helpers

function contains(xs, x) {
    return 0 <= xs.indexOf(x);
}

function notnull(x) {
    if (x == null) throw TypeError(x);
    return x;
}

// Personal navigation

$(function() {
    function pagehref (page) {
        return mw.config.get('wgArticlePath').replace('$1', page.replace(/ /g, '_'));
    }
    function addLink(page, label, id) {
        // mw.util.addPortletLink(portlet, href, text, id,
        //                tooltip, accesskey, nextnode)
        mw.util.addPortletLink('p-personal', pagehref(page), label, id,
                       page, '',  document.getElementById('pt-userpage'));
    }
    addLink('User:Piet Delport/Task list', 'task list', 'pt-tasklist');
    addLink('User:Piet Delport/Edit summary snippets', 'edit snippets', 'pt-editsnippets');
});

// Avoid wrapping edit summaries (it makes lists of them hard to read)

if (contains(['Recentchanges', 'Recentchangeslinked', 'Watchlist'], mw.config.get('wgCanonicalSpecialPageName')) || mw.config.get('wgAction') == 'history') {
    addOnloadHook(function() {
        notnull(document.getElementById('bodyContent')).style.whiteSpace = 'nowrap';
    });
}

// Editing toolbar

if (mw.config.get('wgAction') == 'edit' || mw.config.get('wgAction') == 'submit') {
    addOnloadHook(function() {
        // Drop dubious buttons.
        mwEditButtons = mwEditButtons.filter(function (button) {
            return !contains([
                'mw-editbutton-extlink',
                'mw-editbutton-image',
                'mw-editbutton-media',
                'mw-editbutton-math',
                'mw-editbutton-nowiki',
            ], button.imageId);
        });
        // Em dashed signature.
        mwEditButtons = mwEditButtons.map(function (button) {
            if (button.tagOpen == '--~~'+'~~') {
                button.tagOpen = '~'+'~~';
            }
            return button;
        });
    });

    // See [[MediaWiki:Common.js]];  i don't want those.
    mwCustomEditButtons = [{
        "imageFile": "http://upload.wikimedia.org/wikipedia/commons/1/1b/Button_miss_signature.png",
        "speedTip": "Unsigned post",
        "tagOpen": "{"+"{unsigned|",
        "tagClose": "|}"+"}",
        "sampleText": "Name",
    }];

    importScript('User:Js/ajaxPreview.js');
}

// Other extensions

importScript('MediaWiki:Gadget-edittop.js');

importScript('User:Lupin/popups.js');
popupHideDelay = 0;

importScript('User:Dschwen/highlightredirects.js');