User:Ozuzanna/annihilate.js

/*
 * "Annihilate" - a modified combined version of "WHAM!" and "Nuke + Block"
 * "WHAM!" - http://dev.wikia.com/wiki/WHAM/code.js
 * "Nuke + Block" - http://community.wikia.com/wiki/User:Lil'_Miss_Rarity/wikia.js
 * Used to quickly dispose of spammers on Community Central; feel free to modify variables to suit your needs if you'd like to use this too on your wiki.
 * @author Ozuzanna

if (mw.config.get("wgCanonicalSpecialPageName") === "Contributions") { $(".chat-ban-log").after(" | Annihilate");

$(".chat-ban-log").after(" | Delete + Rollback");

function deleteRollback { $('.mw-rollback-link a').each(function {	 var href = $(this).attr('href');	 $.get(href);	 $(this).text('gone!').css('color','grey').removeAttr('href');     }); var title = encodeURIComponent($('li .newpage ~ a').html); var url = wgServer+'/api.php?action=query&prop=info&intoken=delete&titles='+title+'&format=json'; var deleteReason = 'spam'; $.getJSON(url, function(data) {	var p; for (var p in data.query.pages) { break; };	var ET = data.query.pages[p].deletetoken;	var ET = ET.slice(0, -2);	var ET = ET+'%2B\\';	$('li .newpage ~ a').each(function { var title = encodeURIComponent($(this).html); var url = wgServer+'/api.php?action=delete&title='+title+'&reason='+deleteReason+'&format=json&token='+ET; $.post(url,function {		  $('li .newpage ~ a').css({'color':'grey','text-decoration':'line-through'}).removeAttr('href');	   }); });      });    }

$("#contribs-rollback-del").click(function {      deleteRollback;    });

$("#contribs-annihilate").click(function {      deleteRollback;        var duration;      if ($('a.mw-redirect:contains("Why create an account?")').length == 1) {        duration = "3 months";      } else {        duration = "infinite";      }        $.ajax({ url: "/api.php", type: "POST", dataType: "JSON", data: { action: "block", user: mw.config.get("wgPageName").split("/")[1], expiry: duration, reason: "spam", nocreate: 0, autoblock: 0, format: "json", token: mw.user.tokens.values.editToken },           success: function (d) { if (!d.error) { alert("Request successful!"); } else { alert("Request failed: " + d.error.code); }           },            error: function  { alert("Request failed!"); }       });     }); }