User:Joeytje50/ChatBans.js

// if ((wgUserGroups.indexOf('sysop')!=-1||wgUserGroups.indexOf('chatmoderator')!=-1)&&(wgTitle=='Chat/Bans'||wgTitle.indexOf('Chat/Bans/Archive ')!=-1)) {

var banpage = !(wgTitle.indexOf('Chat/Bans/Archive ')==-1) var d = new Date var monthNames = ["January","February","March","April","May","June","July","August","September","October","November","December"]; $('#ChatBanAdd').html(' Add new banned user See Template:Bans for documentation and shorthand inputs. Banned user:  Banning moderator: '+(banpage?' (default: yourself)':)+' '+(banpage?:' ')+'Date of the ban: '+(banpage?'  Today  ':)+''+(banpage?' Other':)+'  Ban expiry:   Ban reason:   Other notes (optional):   Submit ')

$('#btoday').click(function {	if ($(this).is(':checked')) {		$('#bdate #bother').attr('disabled','disabled')	} else {		$('#bdate #bother').removeAttr('disabled')	} }) $('#bother').keyup(function {	if ($(this).val!='') {		$('#bdate #btoday').attr('disabled','disabled')	} else {		$('#bdate #btoday').removeAttr('disabled')	} })

function callAPI(data, method, callback) { data['format'] = 'json'; $.ajax({		data: data,		dataType: 'json',		url: wgScriptPath + '/api.php',		type: method,		cache: false,		success: function(response) {			if (response.error)				alert('API error: ' + response.error.info);			else 				callback(response);		},		error: function(xhr, error) { alert('AJAX error: ' + error) }	}); }

$('#bsubmit').click(function { $(this).attr('disabled','disabled').html('Loading...') var bandate = $('#bdate input[disabled]').length!=0?$('#bdate input:not([disabled])').val: var template =  callAPI({ 'action': 'query', 'prop': 'info|revisions', 'intoken': 'edit', 'titles': wgPageName, 'rvprop': 'content', 'rvlimit': '1', 'indexpageids': 'true', }, 'GET', function(response) { var page = response.query.pages[response.query.pageids[0]]; var content = page.revisions[0]['*']; content = content+'\n'+template; callAPI({		'minor': 'yes',		'summary': (banpage?'Added template for banned user.':'Adding to the bans archive.'),		'action': 'edit',		'title': wgPageName,		'basetimestamp': page.revisions[0].timestamp,		'startimestamp': page.starttimestamp,		'token': page.edittoken,		'text': content	}, 'POST', function(response) {		alert('Your edit has been submitted. The page will now be reloaded.')		document.location.href = wgArticlePath.replace('$1', wgPageName)+'?action=purge'	}); }); }) }