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
 * @author Ozuzanna

var nuke = -1, sitename = mw.config.get('wgSiteName'), username = mw.config.get("wgPageName").split("/")[1], duration = "infinite";
 * (function($, mw) {

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

if (sitename === "Community Central") $(".chat-ban-log").after(' | Nuke');

function deleteRollback { $('#mw-content-text ul li a').each(function {       var thread = $(this).attr('title');          if (thread.slice(7) === 'Thread:')            nuke++;      });

$('.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'),	   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'); });	 });      });

setTimeout((function{ if (nuke !== -1 && sitename === "Community Central") { location.replace("/wiki/Special:Nuke/"+username); }        else { location.reload; }      }), 3000);    }

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

$("#contribs-annihilate").click(function {     if (mw.config.get("wgTitle").split('.').length == 4)        duration = "3 months"; //if unregistered

$.ajax({           url: "/api.php",            type: "POST",            dataType: "JSON",            data: {                action: "block",                user: username,                expiry: duration,                reason: "spam",                nocreate: 0,                autoblock: 0,                format: "json",                token: mw.user.tokens.values.editToken            },            success: function (d) {                if (!d.error) {                    deleteRollback;                           } else {                    alert("Request failed: " + d.error.code);                }            },            error: function  {                alert("Request failed!");            }        }); }); } }) (this.jQuery, this.mediaWiki);