Jump to content

User:Dgw/rollbacksummary.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.
/* This script adds a second rollback link on page histories, diff pages,
   and user contrib lists to ask for an edit summary via a prompt box.
   Thanks to Alex Smotrov's wlunwatch.js for some of the code!            */

/* ******** STABLE ******** */
/* This script is fully functional, even if it does put links in odd places at times. */

importScript('User:Voyagerfan5761/rollbackbits.js');

function rollbackSummaryOnload() {
    var links = false;
    switch(RollbackBits.GetType()) {
        case 'hist': links = document.getElementById('pagehistory').getElementsByTagName('a'); break;
        case 'diff': links = document.getElementById('mw-diff-ntitle2').getElementsByTagName('a'); break;
        case 'trib': links = document.getElementById('bodyContent').getElementsByTagName('a'); break;
    }
    for(var linkid = links.length - 1; linkid >= 0; linkid--) { //append prompt links after rollback links
        if (links[linkid].href.match(/[?&]action=rollback[&]/)) {
            var rbsumm = links[linkid].cloneNode(false);
            rbsumm.onclick = RollbackBits.PromptForSummary;
            rbsumm.innerHTML = 'revert';
            switch(RollbackBits.GetType()) {
                case 'hist':
                    links[linkid].parentNode.appendChild(document.createTextNode(' | '));
                    links[linkid].parentNode.appendChild(rbsumm); break;
                case 'diff': case 'trib':
                    links[linkid].parentNode.appendChild(document.createTextNode(' ['));
                    links[linkid].parentNode.appendChild(rbsumm);
                    links[linkid].parentNode.appendChild(document.createTextNode('] '));
            }
        }
    }
}

$(rollbackSummaryOnload);