User:Excirial/spamublock.js

// (function {	var namespace = mw.config.get('wgNamespaceNumber'),		pageName = mw.config.get('wgPageName'),		myUserName = mw.config.get('wgUserName'),		userName = mw.config.get('wgRelevantUserName'),		templateName = "uw-spamublock";

if([2,3].indexOf(namespace) !== -1) { mw.util.addPortletLink(			'p-cactions', 'javascript:void(0)',		   '', 't-spamublock', 'Delete user page and execute  on current user'		);

$('#t-spamublock').on('click', function {			if (confirm('This script will delete the current user page, block the user as and leave that template on their talk page, or the template specified at Special:MyPage/uw-spamublock, if present.\n\nARE YOU SURE YOU WANT TO PROCEED?')) {				$('#t-spamublock').text('Please wait...');				getTemplate;			}		}); }

var api = new mw.Api;

function getTemplate { api.get({			action: 'query',			titles: 'User:'+myUserName+'/uw-spamublock'		}).then(function(data) {			var query = data.query.pages;			if(Object.keys(query)[0] > 0) {				templateName = 'User:'+myUserName+'/uw-spamublock';			} else {				templateName += "|sig=yes";			}			templateName = "";			deleteUserPage;		}); }

function deleteUserPage { api.postWithToken("delete", {			action: 'delete',			reason: 'G11: Unambiguous advertising or promotion',			title: pageName		}).then(function(deleteData) {			$("#mw-content-text").html( " Deleted page "+pageName+" (G11: Unambiguous advertising or promotion) " );			blockUser;		},function(error) {			$("#mw-content-text").html( " Error deleting page "+pageName+": "+error+" " );		});	}

function blockUser { var blockReason = ' '; api.postWithToken("block", {			action: 'block',			allowusertalk: true,			autoblock: true,			nocreate: true,			reason: blockReason,			user: userName		}).then(function(blockData) {			$("#mw-content-text").append( " Blocked "+userName+" (account creation blocked) with an expiry time of indefinite  " );			$(' ').text(blockReason).appendTo("#spamublock-blocked-reason");			templateUser;		}, function(error) {			$("#mw-content-text").append( " Error blocking "+userName+": "+error+" " );		});	}

function templateUser { var monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"], d = new Date;

api.postWithToken( "edit", {			action: "edit",			section: 'new',			sectiontitle: monthNames[d.getMonth] + ' ' + d.getFullYear,			summary: "You have been indefinitely blocked from editing because your account is being used only for spam or advertising and your username is a violation of the username policy. (using spamublock.js)",			text: "\n"+templateName,			title: "User talk:"+userName		}).then(function(editData) {			$("#mw-content-text").append( " Edited User talk:"+userName+": Created new section with template "+templateName+" " + " Complete (reload) " );		},function(error) {			$("#mw-content-text").append( " Error editing User talk:"+userName+": "+error+" " );		});	} }); //