User:Erwin/xwikirollback.js

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/**
 * xwikirollback
 * Allows for tools to make rollbacklinks by adding
 * "&xwikirollback" to the query string of a link to
 * a diff page.
 *
 */

$( function ()
{
    //Check if we're comparing revisions and we want to rollback the edit
    if (document.location.href.indexOf('diff=') != -1 && document.location.href.indexOf('&xwikirollback') != -1) {
        //The rollback link is in a span with the "mw-rollback-link" class
        var s = getElementsByClassName(document, 'span', 'mw-rollback-link');
        //If there's no such span or more than one don't do anything
        if (s.length != 1 ) {
            return false;
        } else {
            //There should only be one link in this span, i.e. the rollback link
            var a = s[0].getElementsByTagName('a');
            if (a.length != 1 ) {
                return false;
            } else {
                //Check if it's indeed a rollback link
                if (a[0].href.indexOf('action=rollback') != -1) {
                    window.location = a[0].href;
                }
            }
        }
    }
}
)