User:Jr Mime/WHAM.js

// @WIKIA // Scripts of: //   WHAM //   Grunny's delete all and rollback all //   Adaptation to Wikipedia by User:Jr_Mime if (mw.config.get("wgCanonicalSpecialPageName") === 'Contributions') {

var username = mw.config.get("wgPageName").split("/")[1], token = mw.user.tokens.get("editToken"), r1 = (typeof(r1u) === 'undefined') ? 'vandalism' : r1u, r2 = (typeof(r2u) === 'undefined') ? 'reverting/deleting spam or vandalism' : r2u; $('.mw-contributions-form').before('Delete | ' +       'Rollback | ' +        ' Block | ' +        'All'); $('#WHAMrollback').on('click', function {       $('.mw-rollback-link a').each(function(i) { var obj = $(this), href = obj.attr('href'); setTimeout(function {   	$.get(href);    	console.log('Rollback number ' + i + ' successful!');    	obj.text('gone!').css({'color':'grey','text-decoration':'line-through'}).removeAttr('href').parents.eq(1).css({'color':'grey','text-decoration':'line-through'}).children.removeAttr('href').css({'color':'grey','text-decoration':'line-through'});        }, i*500); });   });    $('#WHAMblockButton').on('click', function {        new mw.Api.post({ format: 'json', action: 'block', user: username, expiry: $("#WHAMblock").val, nocreate: 0, autoblock: 0, reason: r1, bot: true, token: token }).done(function(d) { if (!d.error) { console.log(username+' has been blocked successfully!'); alert('User has been blocked!'); } else { alert('Failed to block '+username+': '+ d.error.code); }       }).fail(function { alert('Failed to block '+username+'!'); });   });    function apiDelete(page,reason) { new mw.Api.post({       format: 'json',        action: 'delete',        title: page,        reason: r2,        bot: true,        token: token        }) .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+'!');        }); }   $('#WHAMdelete').on('click', function WMdelete {        $('li .newpage ~ a').each(function { var title = $(this).attr('title'); apiDelete(title); $(this).parent.css({'color':'grey','text-decoration':'line-through'}).children.removeAttr('href').css({'color':'grey','text-decoration':'line-through'}); });   });    $('#WHAMall').on('click', function {        $("#WHAMrollback, #WHAMdelete, #WHAMblockButton").click;    }); }