User:Func/wpfunc/blockiphelp.js
Appearance
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:Func/wpfunc/blockiphelp. |
// <pre><nowiki>
function BlockIpHelp()
{
var form = document.getElementById( 'blockip' );
if ( ! form || form.tagName != 'FORM' || ! form.wpBlockAddress ) return;
var span = document.createElement( 'SPAN' );
form.span = span; // avoid globals
// to the right of the IP or username field
//
form.wpBlockAddress.parentNode.insertBefore( span, form.wpBlockAddress.nextSibling );
function ipMessage( message, selectedIndex, color )
{ var span = document.createElement( 'SPAN' );
span.appendChild( document.createTextNode( ' ' + ( message || '' ) ) );
span.style.color = color || '#000000';
span.style.fontWeight = 'bold';
span.selectedIndex = selectedIndex || 0;
return span;
}
var expiry = {
'other' : 0,
'15 minutes' : 1,
'1 hour' : 2,
'3 hours' : 3,
'24 hours' : 4,
'48 hours' : 5,
'1 week' : 6,
'1 month' : 7,
'indefinite' : 8
};
span.ipNone = ipMessage();
span.ipNot = ipMessage( 'Not an IP.' , expiry[ '24 hours' ], '#009900' ); // green
span.ipUnknown = ipMessage( 'Unknown IP.' , expiry[ '1 hour' ], '#999900' ); // yellow
span.ipAOL = ipMessage( 'AOL IP address.', expiry[ '15 minutes' ], '#990000' ); // red
span.appendChild( span.ipNot ); // place holder
span.showMessage = function( span )
{ this.replaceChild( span, this.firstChild );
}
form.wpBlockAddress.onchange = function()
{
var ip = IpDottedToLong( this.value );
if ( ip === null ) this.form.span.showMessage( this.form.span.ipNone );
else if ( isNaN( ip ) ) this.form.span.showMessage( this.form.span.ipNot );
else if ( IsAOL( ip ) ) this.form.span.showMessage( this.form.span.ipAOL ); // what else, EarthLink?
else this.form.span.showMessage( this.form.span.ipUnknown );
this.form.wpBlockExpiry.selectedIndex = this.form.span.selectedIndex;
}
form.wpBlockAddress.onchange();
}
if ( window.addEventListener ) window.addEventListener( 'load', BlockIpHelp, false );
else if ( window.attachEvent ) window.attachEvent( 'onload', BlockIpHelp );
function IpDottedToLong( ip ) //-> number, Number.NaN for username, or null
{
if ( ! ip ) return null;
if ( ( ip.constructor != String ) ||
( (ip = ip.split( '.' )).length != 4 ) ) return Number.NaN;
//
for ( var i = 0; i < 4; i++ )
if ( isNaN( ip[ i ] = Number( ip[ i ] ) ) ||
ip[ i ] < 0 ||
ip[ i ] > 255 ) return Number.NaN;
// I "think" JavaScript numbers can handle this....
//
return ip[ 0 ] * 256 * 256 * 256 + // JS lacks an exponent op, I refuse to use Math.pow()
ip[ 1 ] * 256 * 256 +
ip[ 2 ] * 256 +
ip[ 3 ];
}
function IsAOL( ip )
{
if ( ip < 1074528256 ) return false; // 64. 12. 0. 0 ..
else if ( ip <= 1074593791 ) return true; // .255.255
else if ( ip < 2511208448 ) return false; // 149.174. 0. 0 ..
else if ( ip <= 2511273983 ) return true; // .255.255
else if ( ip < 2560819200 ) return false; // 152.163. 0. 0 ..
else if ( ip <= 2560884735 ) return true; // .255.255
else if ( ip < 2894069760 ) return false; // 172.128. 0. 0 ..
else if ( ip <= 2899574783 ) return true; // .211.255.255
else if ( ip < 3277651968 ) return false; // 195. 93. 0. 0 ..
else if ( ip <= 3277684735 ) return true; // .127.255
else if ( ip < 3327197184 ) return false; // 198. 81. 0. 0 ..
else if ( ip <= 3327205375 ) return true; // . 31.255
else if ( ip < 3393404928 ) return false; // 202. 67. 64. 0 ..
else if ( ip <= 3393421311 ) return true; // .127.255
else if ( ip < 3451650048 ) return false; // 205.188. 0. 0 ..
else if ( ip <= 3451715583 ) return true; // .255.255
else if ( ip < 3486007296 ) return false; // 207.200. 64. 0 ..
else if ( ip <= 3486023679 ) return true; // .127.255
else return false;
}
// </nowiki></pre>