User:Ozuzanna/annihilate.js

/*
 * "Annihilate" - attribution give to "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 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 apiDelete(page) { new mw.Api.post({     format: 'json',      action: 'delete',      title: page,      token: token,      reason: reason      }) .done(function(d) {        if (!d.error) {          console.log('Deletion of '+page+' successful!');        } else {          console.log('Failed to delete '+page+': '+ d.error.code);        }      }) .fail(function {       console.log('Failed to delete '+page+'!');      }); }

function deleteRollback { $('.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 = $(this).attr('title');        if (title.slice(0,12) == 'Message Wall')          return;        apiDelete(title);        $(this).css({'color':'grey','text-decoration':'line-through'}).removeAttr('href');      });

$('#mw-content-text ul li a').each(function {       var title = $(this).attr('title');	if (title.split('-').length == 1)	  return;        if (title.slice(0,7) == 'Thread:' || title.slice(0,13) == 'Board Thread:') {          apiDelete(title);          $(this).css({'color':'grey','text-decoration':'line-through'}).removeAttr('href');        }      });

setTimeout((function{ 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);