User:Olipro/rollback.js

From Uncyclopedia, the content-free encyclopedia
Jump to navigation Jump to search

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

  • Internet Explorer: hold down the Ctrl key and click the Refresh or Reload button, or press Ctrl+F5.
  • Firefox: hold down the Shift key while clicking Reload; alternatively press Ctrl+F5 or Ctrl-Shift-R.
  • Opera, Konqueror and Safari users can just click the Reload button.
  • Chrome: press Ctrl+F5 or Shift+F5
// <pre><nowiki>
//Olipro's Recent Changes Auto-Rollback tool.
//Only works for admins of course.

function loadtheCode() {
    addRollback();
    doReverts();
}

if(mybrowser.search(/MSIE/i) != -1 || mybrowser.search(/Safari/i) != -1)
{
    addOnLoadHook(loadtheCode);
} else if(mybrowser.search(/Firefox/i) == -1) {
    document.addEventListener('load', loadtheCode, false);
} else {
    document.addEventListener('DOMContentLoaded', loadtheCode, false);
}

function addRollback() {
    if(document.title.indexOf("Recent changes") == 0 && document.title.indexOf("Recent changes") != -1) {
        var items = document.getElementsByTagName('ul')[0].getElementsByTagName('li');
        for(i in items) {
            if(items[i].getElementsByTagName('a')[0].innerHTML != 'diff')
                continue;
            var title = items[i].getElementsByTagName('a')[2].getAttribute('href');
            var uname = items[i].getElementsByTagName('a')[3].innerHTML;
            title = title.substring(6,title.length);
            items[i].innerHTML += ' [<a href="/index.php?title='+title+'&amp;action=history&amp;rollback=true&amp;uname='+escape(uname)+'">rollback</a>]';
        }
    }
}
function doReverts() {
    if(document.title.indexOf("- History") == -1 || location.href.indexOf("rollback=true") == -1)
        return;

    uname = document.getElementById('pagehistory').getElementsByTagName('li')[0];
    uname = uname.getElementsByTagName('a')[2].innerHTML;
    if(location.href.indexOf('uname='+escape(uname)) == -1) {
        alert('Edit conflict, revert cancelled.');
        return;
    }
    var spanner = new Array();
    spanner = document.getElementsByTagName('span');
    for(i in spanner) {
        if(spanner[i].getAttribute('class') == 'mw-rollback-link') {
             spanner = spanner[i].getElementsByTagName('a')[0].getAttribute('href');
             break;
        }
    }
    if(spanner)
        location.href = spanner;
}
// </nowiki></pre>