Jump to content

User:Paranomia/checkblocked.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
function get_blocked_json( user ) {
	document.getElementById( 'contentSub' ).innerHTML += '<br><strong>Checking if user is blocked.' + '\n' + 'Please wait...</strong>';
	gml_xmlhttp = sajax_init_object();
	if ( !gml_xmlhttp )
	{
		return;
	}
	var pageurl = wgScriptPath + '/api.php?action=query&list=blocks&bkusers=' + escape( user ) + '&format=json';
	gml_xmlhttp.open( "GET", pageurl, true );
	gml_xmlhttp.onreadystatechange = alertblocked;
	gml_xmlhttp.send(null);
}
function alertblocked() {
	if ( gml_xmlhttp.readyState !== 4 )
	{
		return;
	}
	json = gml_xmlhttp.responseText;
	var obj = eval( '(' + json + ')' );
	var string = "Not blocked";
	if ( obj.query.blocks.length > 0 ){
		string = 'User has been blocked by: <a href="' + wgServer + '/wiki/User:' + obj.query.blocks[0].by + '">' + obj.query.blocks[0].by + '<\/a>;<br />	expiring: ' + obj.query.blocks[0].expiry + ';<br />because: ' + obj.query.blocks[0].reason + '.';
	}
	document.getElementById( 'contentSub' ).innerHTML += '<br /><span style="color:blue;"><strong>' + string + '</strong></span>';
}