User:Mike Dillon/Scripts/tabs.js

This is an old revision of this page, as edited by Mike Dillon (talk | contribs) at 03:00, 27 April 2007 (remove alt-g from purge). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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.
// Requires: [[User:Mike Dillon/Scripts/addlilink.js]]

/* <pre><nowiki> */

// Duplicate link tab from the top to the bottom of the content area
addOnloadHook(function () {
    // Clone the original tabs and change the id to "mytabs"
    var tabs = document.getElementById('p-cactions').cloneNode(true);
    tabs.id = 'mytabs';

    // Find individual tabs with ids and prefix the ids with "mytabs-"
    var listitems = tabs.getElementsByTagName('LI');
    for (var i=0; i < listitems.length; i++) {
        if(listitems[i].id) listitems[i].id = 'mytabs-' + listitems[i].id;
    }

    // Add the cloned tabs at the end of the "column-content" div
    document.getElementById('column-content').appendChild(tabs);
});

// Add a new list item to the page tabs
function addTab(url, name, id, title, key) {
    // Add tab to the top tabs
    addPortletLink('p-cactions', url, name, id, title, key);

    // Add tab to the bottom if the tabs have been cloned
    addPortletLink('mytabs', url, name, 'mytabs-' + id, title, key);
}

// Add a 'purge' and 'last' links to the tabs
addOnloadHook(function () {
    var x = document.getElementById('ca-history');
    if(!x) return;

    if(x.children) x = x.children[0].href;
    else x = x.childNodes[0].href;

    addTab(x.replace(/action=history/, "action=purge"),
        'purge', 'ca-purge', 'Purge the internal cache for this page');
    addTab(x.replace(/action=history/, "diff=cur&oldid=prev"),
        'last', 'ca-last', 'Show most recent diff');
});

/* </nowiki></pre> */