User:Ozuzanna/annihilate.js

/*
 * @author Ozuzanna

if (mw.config.get("wgCanonicalSpecialPageName") === "Contributions") { var formHTML = '\  \ \          Block length: \  \ \               \ \          Block? \          Rollback all? \          Delete all? \      \   ';

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

function deleteAll { var title = encodeURIComponent($('li .newpage ~ a').html); var url = wgServer+'/api.php?action=query&prop=info&intoken=delete&titles='+title+'&format=json'; var deleteReason = document.getElementById('del-reason').value; $.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); 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');	 }); });  }

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

function init { if (document.getElementById('block-user').checked) { blockUser; }     if (document.getElementById('rollback-all').checked) { rollbackAll; }        if (document.getElementById('delete-all').checked) { deleteAll; }     $('#contribs-control-panel').closeModal; setTimeout( (function{ location.reload; }), 2000);   }

$(".chat-ban-log").after(' | Control Panel');

$("#contribs-control-panel").click(function {      $.showCustomModal('Control Panel', formHTML, { id: 'form-control-panel', width: 500, buttons: [{ message: 'All', handler: function { rollbackAll; deleteAll; blockUser; $('#form-control-panel').closeModal; setTimeout( (function{ location.reload; }), 2000);             }          }, {             message: 'Confirm', defaultButton: true, handler: function { init; }        }, {             message: 'Cancel', handler: function { $('#form-control-panel').closeModal; }        }]     });  }); }