MediaWiki:Cvu.js

$(function {

function getParam(name) { name = name.replace(/[\[]/, '\\\[').replace(/[\]]/, '\\\]'); var regex = new RegExp('[\\?&]' + name + '=([^&#]*)'); var results = regex.exec(window.location.href); if (results == null) { return ''; } else { return decodeURIComponent(results[1]); }	}

function showSuccess { alert('Thank you for your submission! The page will now be reloaded.'); document.location.replace(wgScript + '?title=' + encodeURIComponent(wgPageName) + '&action=purge'); }	function showError(msg) { alert(msg); $('#cvuSubmit').removeAttr('disabled').val('Submit'); }	function callAPI(data, method, callback) { data['format'] = 'json'; $.ajax({			data: data,			dataType: 'json',			url: wgScriptPath + '/api.php',			type: method,			success: function(response) {				if (response.error) {					showError('API error: ' + response.error.info);				} else {					callback(response);				}			},			error: function(xhr, error) { showError('AJAX error: ' + error); },			timeout: 10000 // msec		}); }	function cvuSubmit { var editor = $.trim($('#cvuEditor').val); var vpagename = $.trim($('#cvuPage').val); $('#cvuSubmit').attr('disabled', 'disabled').val('Loading...'); if(editor == '') {		       showError('Please enter a user name.'); return false; }		callAPI({			'action': 'query',			'prop': 'info|revisions',			'intoken': 'edit',			'titles': wgPageName,			'rvprop': 'content',			'rvlimit': '1'		}, 'GET', function(response) {			var pages = response.query.pages;			var page = null;			for (var i in pages) {				page = pages[i];			}			var content0 = page.revisions[0]['*'];                       var template = '\{\{cvuid\|insert vandal\}\}';

if (content0.match(template) == null) { showError('An error occurred.'); }

if(vpagename == '' || vpagename == null) {                               vpagename = '}' + '}'; }                       else {                               vpagename = '|' + vpagename + '}' + '}'; }

content0 = content0.replace(template, '{' + '{cvuid|' + editor + vpagename); callAPI({				'minor': 'yes',				'summary': 'Reported new user: [' + '[Special:Contributions/' + editor + '|' + editor + ']' + ']',				'action': 'edit',				'title': wgPageName,				'basetimestamp': page.revisions[0].timestamp,				'startimestamp': page.starttimestamp,				'token': page.edittoken,				'text': content0			}, 'POST', function(response) {				if (response.edit.result == 'Success') {					showSuccess;				} else {					showError('An error occurred while submitting the edit.');				}			}); });		return false;	}

if(wgPageName=='RuneScape:Counter-Vandalism_Unit') { var $div = $('#cvu_guide'); var $form = $(' ');

var ppLink = 'Due to vandalism, this page has been protected from editing.'; if ($.inArray('sysop', wgRestrictionEdit) > -1 && $.inArray('sysop', wgUserGroups) == -1) { $form.append(ppLink + ' Please contact an administrator to update the price.'); } else if ($.inArray('autoconfirmed', wgRestrictionEdit) > -1 && $.inArray('autoconfirmed', wgUserGroups) == -1) { $form.append(ppLink + ' Please log in to update the price.'); } else { $form.submit(cvuSubmit); $form.append($(' ').text('Report a vandal:')); var $p1 = $('').append('Please report a vandal by inserting the username or IP address and the page they are vandalizing.'); $form.append($p1); var $p2 = $(''); $p2.append($(' ').attr({'for': 'cvuEditor'}).text('Username:')); $p2.append($(' ').attr({'id': 'cvuEditor', 'type': 'text', 'size': 9})); $p2.append($(' ').attr({'for': 'cvuPage'}).text('  Page:')); $p2.append($(' ').attr({'id': 'cvuPage', 'type': 'text', 'size': 9})); $p2.append($(' ').css({'margin': '0 1em 0 1em'}).attr({'id': 'cvuSubmit', 'type': 'submit'}).val('Submit')); $form.append($p2); }		if ($div != null) { $div.empty.append($form); }	}

if(wgPageName=='User:Suppa_chuppa/Sandbox_4') { /*var elements = []; $("#cvu_remove").each(function { elements.push($(this).className) }); //jQuery.each(elements, function(i, val) {               //$("#" + i).append(document.createTextNode(" - " + val));                         //var user = i.className.replace(/ /g,"_");                //}); var remove = elements[0]; //document.getElementById('cvu_remove').className; var $a = $(''); $('#cvu_remove').each(function {$(this).empty.append($a)}); //$('#cvu_remove').empty.text(elements[0]);*/

var spans = document.getElementsByTagName("span"); var len = spans.length; for (var i = 0; i < len; i++) {                        var class_name; var this_span = spans[i]; if (this_span.id == 'cvu_remove') {                               class_name = this_span.className; var $a = $(''); $('#cvu_remove.' + class_name.replace(/ /g,".")).empty.append($a); }               }        }

if(wgPageName=='User:Suppa_chuppa/Sandbox_4' && getParam('remove')) { } });