User:Kingpin13/kill.js

/* copied from User:Prodego/Sandbox.js */

addOnloadHook(function {    if(document.getElementById("difference")) {      mw.util.addPortletLink("p-cactions", "javascript:grawpBlock", "Kill", "ca-grawp", "Block user");     } }); function grawpBlock { var rcol = document.getElementById('bodyContent').getElementsByTagName('td').item(1); if (rcol != null) var user = rcol.getElementsByTagName('a')[3].innerHTML; var expiry = 'indefinite'; var others = '&autoblock=1&nocreate=1&noemail=' jsMsg(' '); var token = getBlockToken(user); if(user != "Prodego") { if(IPhandler(user) == true){ expiry = '1%20week'; others = '&autoblock=1&nocreate=1&allowusertalk=1'; }           blockUser(user, token, expiry, others); }       var rollback = getElementsByClassName(document, "span", "mw-rollback-link"); if (rollback[0]) { rollbacklink = rollback[0].getElementsByTagName('a')[0].href; rollbacktoken = rollbacklink.substring(rollbacklink.indexOf('&token=')+7) doRollback(rollbacktoken, user); }       else { document.getElementById('Grawpblockinfo').innerHTML+= "Edit already rolled back. "; } } function getBlockToken(user) { document.getElementById('Grawpblockinfo').innerHTML+= "Getting block token... "; var req = sajax_init_object; var params = "action=block&user=" + encodeURIComponent(user) + "&gettoken=1&format=json"; req.open("POST", wgScriptPath + "/api.php?", false); req.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); req.setRequestHeader("Content-length", params.length); req.setRequestHeader("Connection", "close"); req.send(params); response = eval('(' + req.responseText + ')'); token = response['block']['blocktoken']; delete req; return token; } function doRollback(rollbacktoken, user) { var req = sajax_init_object; title = wgPageName; var params = "action=rollback&token="+rollbacktoken+"&title="+title+"&user="+encodeURIComponent(user)+"&markbot=1&format=json"; url = wgScriptPath + "/api.php"; req.open("POST", url, true); req.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); req.setRequestHeader("Content-length", params.length); req.setRequestHeader("Connection", "close"); req.onreadystatechange = function { if(req.readyState == 4 && req.status == 200) { response = eval('(' + req.responseText + ')'); try { document.getElementById('Grawpblockinfo').innerHTML += "Rollback on "+response['rollback']['title']+" succeeded "; } catch(err) { document.getElementById('Grawpblockinfo').innerHTML += "Error " + response['error']['info']+" "; }     delete req; } }  req.send(params) }

function blockUser(user, token, expiry, others) { document.getElementById('Grawpblockinfo').innerHTML+= "Blocking... "; var req = sajax_init_object; var params = "action=block&format=json&token="+encodeURIComponent(token)+"&user="+encodeURIComponent(user)+"&expiry="+expiry+"&reason=Vandalism"+others; url = wgScriptPath + "/api.php"; req.open("POST", url, true); req.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); req.setRequestHeader("Content-length", params.length); req.setRequestHeader("Connection", "close"); req.onreadystatechange = function { if(req.readyState == 4 && req.status == 200) { response = eval('(' + req.responseText + ')'); try { document.getElementById('Grawpblockinfo').innerHTML+= response['block']['user']+" has been blocked "; } catch(err) { document.getElementById('Grawpblockinfo').innerHTML+= "Error " + response['error']['info'] + " "; }     delete req; } }  req.send(params) }