Jump to content

User:BilCat/Scripts/Revert tools-uw

From Wikipedia, the free encyclopedia

/*

*/
//On diff pages this script replaces ''(Difference between revisions)''with
//different tools for reverting the edit and warning the user that made the edit.
//For instructions see talk page.
// Revert tools by Lorian
function getElementsByClass(searchClass,node,tag) {
  // Function from http://www.dustindiaz.com/getelementsbyclass/
  var classElements = new Array();
  if ( node == null )
    node = document;
  if ( tag == null )
    tag = '*';
  var els = node.getElementsByTagName(tag);
  var elsLen = els.length;
  var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
  for (i = 0, j = 0; i < elsLen; i++) {
    if ( pattern.test(els[i].className) ) {
      classElements[j] = els[i];
      j++;
    }
  }
  return classElements;
}

// _GET code from NoGray JS Library http://www.nogray.com/new_site/
var _GET = new Array();
var _uri = location.href;

var _temp_get_arr = _uri.substring(_uri.indexOf('?')+1, _uri.length).split("&");

var _temp_get_arr_1 = new Array();

for(_get_arr_i=0; _get_arr_i<_temp_get_arr.length; _get_arr_i++){
  _temp_get_arr_1 = _temp_get_arr[_get_arr_i].split("=");
  _GET[decodeURI(_temp_get_arr_1[0])] = decodeURI(_temp_get_arr_1[1]);
}

delete _uri; delete _temp_get_arr; delete _temp_get_arr_1;

function getMessage (where, user1, user2) {
  var message = prompt ('What message would you like to leave?', '');
  window.location = 'http://wiki.riteme.site/w/index.php?title=' + _GET['title'] + '&action=edit&oldid=' + _GET['oldid'] + '&'+where+'=2&user1='+user1+'&user2='+user2+'&message='+message;
}

addOnloadHook(function (){
  if (location.href.match(/diff=/)) {
    // Get username of submitter
    var user1 = getElementsByClass('diff-otitle',null,'td'); user1 = user1[0].getElementsByTagName('a')[2].innerHTML;
    var user2 = getElementsByClass('diff-ntitle',null,'td'); user2 = user2[0].getElementsByTagName('a')[3].innerHTML;
    document.getElementById('difference').innerHTML = '(<a href="http://wiki.riteme.site/w/index.php?title=' + _GET['title'] + '&action=edit&oldid=' + _GET['oldid'] + '&revert=1&user1='+user1+'&user2='+user2+'">Revert</a> / <a href="javascript:var message = getMessage(\'revert\', \''+user1+'\', \''+user2+'\');">Message</a>) (<a href="http://wiki.riteme.site/w/index.php?title=' + _GET['title'] + '&action=edit&oldid=' + _GET['oldid'] + '&vandalism=1&user1='+user1+'&user2='+user2+'">Vandalism</a> / <a href="javascript:var message = getMessage(\'vandalism\', \''+user1+'\', \''+user2+'\');">Message</a>) (Warn: <a href="http://wiki.riteme.site/w/index.php?title=User_talk:'+user2+'&action=edit&section=new&warn=1">Level 1</a> / <a href="http://wiki.riteme.site/w/index.php?title=User_talk:'+user2+'&action=edit&section=new&warn=2">Level 2</a> / <a href="http://wiki.riteme.site/w/index.php?title=User_talk:'+user2+'&action=edit&section=new&warn=3">Level 3</a> / <a href="http://wiki.riteme.site/w/index.php?title=User_talk:'+user2+'&action=edit&section=new&warn=4">Level 4</a> / <a href="http://wiki.riteme.site/w/index.php?title=User_talk:'+user2+'&action=edit&section=new&warn=5">Only warning</a> / <a href="http://wiki.riteme.site/w/index.php?title=User_talk:'+user2+'&action=edit&section=new&warn=6">Test</a> / <a href="http://wiki.riteme.site/w/index.php?title=User_talk:'+user2+'&action=edit&section=new&warn=7">Blatant</a> / <a href="http://wiki.riteme.site/w/index.php?title=User_talk:'+user2+'&action=edit&section=new&warn=8">Longterm</a> / <a href="http://wiki.riteme.site/w/index.php?title=User_talk:'+user2+'&action=edit&section=new&warn=9">Blanking</a>)';
  } else if (location.href.match(/revert=1/)) {
    document.getElementById('wpSummary').value = 'Reverted edits by [[Special:Contributions/'+_GET['user2']+'|'+_GET['user2']+']] to version ' + _GET['oldid']+' by [[Special:Contributions/'+_GET['user1']+'|'+_GET['user1']+']]';
    document.getElementById('editform').submit();
  } else if (location.href.match(/revert=2/)) {
    document.getElementById('wpSummary').value = 'Reverted edits by [[Special:Contributions/'+_GET['user2']+'|'+_GET['user2']+']] to version ' + _GET['oldid']+' by [[Special:Contributions/'+_GET['user1']+'|'+_GET['user1']+']] ('+_GET['message']+')';
    document.getElementById('editform').submit();
  } else if (location.href.match(/vandalism=1/)) {
    document.getElementById('wpSummary').value = 'Reverted vandalism by [[Special:Contributions/'+_GET['user2']+'|'+_GET['user2']+']] to version ' + _GET['oldid']+' by [[Special:Contributions/'+_GET['user1']+'|'+_GET['user1']+']]';
    document.getElementById('editform').submit();
  } else if (location.href.match(/vandalism=2/)) {
    document.getElementById('wpSummary').value = 'Reverted vandalism by [[Special:Contributions/'+_GET['user2']+'|'+_GET['user2']+']] to version ' + _GET['oldid']+' by [[Special:Contributions/'+_GET['user1']+'|'+_GET['user1']+']] ('+_GET['message']+')';
    document.getElementById('editform').submit();
  } else if (location.href.match(/warn=1/)) {
    document.getElementById('wpSummary').value = 'May 2012';
    document.getElementById('wpTextbox1').value = '{{sub'+'st:uw-vandalism1|}} ~~'+'~~';
    document.getElementById('editform');
  } else if (location.href.match(/warn=2/)) {
    document.getElementById('wpSummary').value = 'May 2012';
    document.getElementById('wpTextbox1').value = '{{sub'+'st:uw-vandalism2|}} ~~'+'~~';
    document.getElementById('editform');
  } else if (location.href.match(/warn=3/)) {
    document.getElementById('wpSummary').value = 'May 2012';
    document.getElementById('wpTextbox1').value = '{{sub'+'st:uw-vandalism3|}} ~~'+'~~';
    document.getElementById('editform');
  } else if (location.href.match(/warn=4/)) {
    document.getElementById('wpSummary').value = 'May 2012';
    document.getElementById('wpTextbox1').value = '{{sub'+'st:uw-vandalism4|}} ~~'+'~~';
    document.getElementById('editform');
  } else if (location.href.match(/warn=5/)) {
    document.getElementById('wpSummary').value = 'May 2012';
    document.getElementById('wpTextbox1').value = '{{sub'+'st:uw-vandalism4im|}} ~~'+'~~';
    document.getElementById('editform');
  } else if (location.href.match(/warn=6/)) {
    document.getElementById('wpSummary').value = 'May 2012';
    document.getElementById('wpTextbox1').value = '{{sub'+'st:uw-test1|}} ~~'+'~~';
    document.getElementById('editform');
  } else if (location.href.match(/warn=7/)) {
    document.getElementById('wpSummary').value = 'May 2012';
    document.getElementById('wpTextbox1').value = '{{sub'+'st:uw-bv|}} ~~'+'~~';
    document.getElementById('editform');
  } else if (location.href.match(/warn=8/)) {
    document.getElementById('wpSummary').value = 'May 2012';
    document.getElementById('wpTextbox1').value = '{{sub'+'st:uw-longterm|}} ~~'+'~~';
    document.getElementById('editform');
  } else if (location.href.match(/warn=9/)) {
    document.getElementById('wpSummary').value = 'May 2012';
    document.getElementById('wpTextbox1').value = '{{sub'+'st:uw-delete1|}} ~~'+'~~';
    document.getElementById('editform');
  }
});
/*

*/