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], token = mw.user.tokens.get('editToken'), reason = 'spam', 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 page = $(this).attr('title');        if (page.indexOf("Thread:") !== 1)          nuke++;      });

$('.mw-rollback-link a').each(function {       var href = $(this).attr('href');	$.get(href);        $(this).text('gone!').css('color','grey').removeAttr('href');      });

$('li .newpage ~ a').each(function {       var title = encodeURIComponent($(this).text);        new mw.Api.post({ format: 'json', action: 'delete', title: title, token: token, reason: reason })       .done(function(d) { if (!d.error) { console.log('Deletion of '+title+' successful!'); $('li .newpage ~ a').css({'color':'grey','text-decoration':'line-through'}).removeAttr('href'); } else { alert('Failed to delete '+title+': '+ d.error.code); }       })        .fail(function { alert('Failed to delete '+title+'!'); });    });

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        new mw.Api.post({ format: 'json', action: 'block', user: username, expiry: duration, nocreate: 0, autoblock: 0, token: token, reason: reason })       .done(function(d) { if (!d.error) { console.log(username+' has been blocked successfully!'); deleteRollback; } else { alert('Failed to block '+username+': '+ d.error.code); }       })        .fail(function { alert('Failed to block '+username+'!'); });   });  } }) (this.jQuery, this.mediaWiki);