User:PleaseStand/userinfo-dev.js: Difference between revisions

Content deleted Content added
fix IP address detection
m use whole message keys in buildDurationMessage()
Line 117:
items.push( mw.message(
'ps-userinfo-registration',
buildDurationMessage( 'ps-userinfo-', info.registration, new Date() ).text(),
info.gender
).parse() );
Line 135:
items.push( mw.message(
'ps-userinfo-lastedited',
buildDurationMessage( 'ps-userinfo-', info.lastEdited, new Date() ).text(),
info.name
).parse() );
Line 195:
/**
* Convert a duration to a message object.
* @param {string} prefix Message prefix
* @param {Date} start The duration's start
* @param {Date} end The duration's end
* @return {mediaWiki.Message}
*/
function buildDurationMessage( prefix, start, end ) {
var age = ( end - start ) / 1000; // start with seconds
if ( age < 60 ) {
return mw.message( prefix + 'ps-userinfo-seconds', Math.floor( age ) );
}
 
age /= 60; // convert to minutes
if ( age < 60 ) {
return mw.message( prefix + 'ps-userinfo-minutes', Math.floor( age ) );
}
 
age /= 60; // convert to hours
if ( age < 24 ) {
return mw.message( prefix + 'ps-userinfo-hours', Math.floor( age ) );
}
 
age /= 24; // convert to days
if ( age < 7 ) {
return mw.message( prefix + 'ps-userinfo-days', Math.floor( age ) );
}
 
age /= 7; // convert to weeks
if ( age < 4.3481 ) {
return mw.message( prefix + 'ps-userinfo-weeks', Math.floor( age ) );
}
 
age /= 4.3481; // convert to months
if ( age < 12 ) {
return mw.message( prefix + 'ps-userinfo-months', Math.floor( age ) );
}
 
Line 234 ⟶ 233:
var years = Math.floor( age / 12 ), months = Math.floor( age % 12 );
if ( months ) {
return mw.message( prefix + 'ps-userinfo-years-months', years, months );
}
return mw.message( prefix + 'ps-userinfo-years', years );
}