Jump to content

User:Dgw/rollbacksummary.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Dgw (talk | contribs) at 23:47, 10 January 2008 (partial script; have to take dinner break). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
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.
/* This script add a second rollback link on page histories
   and diff pages to ask for an edit summary via a prompt box.
   Thanks to Alex Smotrov's wlunwatch.js for some of the code! */

/* ***********************************************************
   DO NOT USE! STILL UNDER DEVELOPMENT!
   *********************************************************** */

function rollbackSummaryOnload(pagetype) {
var links = switch(pagetype) {
    case 'hist': document.getElementById('pagehistory').getElementsByTagName('a'); break;
    case 'diff': document.getElementById('mw-diff-ntitle2').getElementsByTagName('a'); break;
}
for (var i = 0; i < links.length; i++){ //append (summ) links after rollback links
    if (!links[i].href.match(/[?&]action=rollback[&]/)) continue;
        var rbsumm = document.createElement('a');
        rbsumm.href = links[i].href;
        rbsumm.onclick = promptForRollbackSummary;
        var nextEl = links[i].nextSibling.nextSibling; //item after
        nextEl.parentNode.insertBefore(document.createTextNode(' ['), nextEl);
        nextEl.parentNode.insertBefore(rbsumm, nextEl);
        nextEl.parentNode.insertBefore(document.createTextNode('] '), nextEl);
    }
}

function whatKindOfRollback() {
    if(document.getElementById('pagehistory')) return 'hist';
    if(document.getElementById('mw-diff-ntitle2')) return 'diff';
    return false;
}

if(whatKindOfRollback()) addOnloadHook(rollbackSummaryOnload);