User:Ale jrb/Scripts/unblock.js
Appearance
< User:Ale jrb | Scripts
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | Documentation for this user script can be added at User:Ale jrb/Scripts/unblock. |
// AJAX unblocking script
function unblockMain () {
this.init = function () {
if ( ( wgPageName === 'Special:BlockList' ) && ( wgAction === 'unblock' ) && ( document.getElementById ( 'unblockip' ) ) ) unblock.hookInterface ();
}
this.hookInterface = function () {
var unblockform = document.getElementById ( 'mw-unblock-table' );
unblockform.childNodes[0].childNodes[4].childNodes[3].innerHTML = '<input type="submit" tabindex="4" name="wpBlock" value="Unblock"> <input id="unblock-background" type="button" value="Background Unblock" name="wpBlock2" tabindex="3" onclick="unblock.doUnblock ();" /><br /><div id="unblock-back-status"></div>';
//var regTest = /input type="hidden" value="([^ ]+?)" name="wpEditToken"/gi;
//var matches = regTest.exec ( this.unblockform.innerHTML );
//if ( ! matches ) return false;
this.unblocktoken = encodeURIComponent ( this.getInputValue ( 'wpEditToken' ) ); //matches [1] );
}
this.doUnblock = function () {
var user = this.getInputValue ( 'wpUnblockAddress' );
var reason = this.getInputValue ( 'wpUnblockReason' );
if ( ! user ) { this.outputError ( 'You must enter a user' ); return false; }
if ( user === '' ) { this.outputError ( 'You must enter a user' ); return false; }
if ( reason !== '' ) { reason = '&reason=' + encodeURIComponent ( reason ); }
wa ( ':api' ).command ( 'unblock', 'format=xml&action=unblock&token=' + this.unblocktoken + '&user=' + encodeURIComponent ( user ) + reason, 'POST' ).wait ( function () {
if ( wa ( ':api' ).results ['unblock']['error-attr'] !== undefined ) { unblock.outputError ( wa ( ':api' ).results ['unblock']['error-attr']['info'] ); return false; } else {
unblock.outputError ( 'You have successfully unblocked ' + user + ' (<a href="' + wgServer + wgScript + '?view=User_talk:' + encodeURIComponent ( user ) + '">go to talk page</a>)' );
}
}).run ();
}
this.getInputValue = function ( inputName ) {
var inputs = document.getElementsByTagName ( 'input' );
for ( var i = 0, l = inputs.length; i < l; i ++ ) {
if ( inputs[i].getAttribute ( 'name' ) == inputName ) return inputs[i].value;
}
return false;
}
this.outputSuccess = function ( success ) {
document.getElementById ( 'unblock-back-status' ).innerHTML = '<span style="padding: 4px; color: #558855; font-weight: bold;">' + success + '</span>';
return error;
}
this.outputError = function ( error ) {
document.getElementById ( 'unblock-back-status' ).innerHTML = '<span style="padding: 4px; color: #885555; font-weight: bold;">unblock error: ' + error + '</span>';
return error;
}
}
importScript ( 'User:Ale_jrb/Scripts/waLib2.js' );
var unblock = new unblockMain ();
hookEvent ( 'load', unblock.init );