User:Ozuzanna/annihilate.js

/*  var nuke, duration;
 * "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
 * (function($, mw) {
 * (function($, mw) {

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

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), url = wgServer+'/api.php?action=query&prop=info&intoken=delete&titles='+title+'&format=json', deleteReason = 'spam'; $.getJSON(url, function(data) {	var p; for (p in data.query.pages) { break; }	var ET = data.query.pages[p].deletetoken;	ET = ET.slice(0, -2);       ET += '%2B\\';	$('li .newpage ~ a').each(function { var title = encodeURIComponent($(this).html), href = $(this).attr('href'); if (href.slice(0,7) === 'Thread:') nuke = 1; 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 {     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) { deleteRollback; if (nuke === 1) { window.location.replace("/wiki/Special:Nuke/" + (mw.config.get("wgPageName").split("/")[1])); }                   else { setTimeout( (function{ location.reload; }), 3000);                    }                               } else { alert("Request failed: " + d.error.code); }           },            error: function  { alert("Request failed!"); }       });     });  } }) (this.jQuery, this.mediaWiki);