User:Anomie/lastmod.js: Difference between revisions

Content deleted Content added
fix ymd format
add relative mode
Line 9:
 
/// Configuration:
 
// Recognized values are "dmy" or "mdy"; anything else results in YYYY-MM-DD
// format output.
if(typeof(window.LastModDateFormat)=='undefined') LastModDateFormat="dmy";
 
if(typeof(window.LastModRelative)=='undefined') LastModRelative=false;
 
if(typeof(window.LastModUseUTC)=='undefined') LastModUseUTC=false;
 
if(typeof(window.LastModMonths)=='undefined') LastModMonths=['January','February','March','April','May','June','July','August','September','October','November','December'];
 
 
addOnloadHook(function(){
Line 35 ⟶ 41:
if(typeof(r.query.pages[wgArticleId].revisions[0].timestamp)=='undefined') return;
m=r.query.pages[wgArticleId].revisions[0].timestamp.match(/^(\d\d\d\d)-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)Z$/);
if(LastModUseUTC){
m[2]-=1;
} else {
var dt=new Date(Date.UTC(m[1],m[2]-1,m[3],m[4],m[5],m[6]));
m[1]=dt.getFullYear();
m[2]=dt.getMonth();
m[3]=dt.getDate();
m[4]=dt.getHours().toString(); if(m[4].length==1) m[4]='0'+m[4];
m[5]=dt.getMinutes().toString(); if(m[5].length==1) m[5]='0'+m[5];
m[6]=dt.getSeconds().toString(); if(m[6].length==1) m[6]='0'+m[6];
}
 
var dt;
if(LastModDateFormat=='dmy'LastModRelative){
dt=m[3]+' '+LastModMonths[m[2]]+' '+m[1];
} else if(LastModDateFormat var n=='dmy'new Date(){;
dt=LastModMonths[m[2]]+'var '+m[3]+'showhours=true, '+m[1]showminutes=true;
var d=n.getUTCFullYear()-m[1]; if(d!=0){ dt.push(d+' year'+((d==1)?'':'s')); showhours=false; }
d=n.getUTCMonth()+1-m[2]; if(d!=0){ dt.push(d+' month'+((d==1)?'':'s')); showhours=false; }
d=n.getUTCDate()-m[3];
if(LastModUseUTCd!=0){
dt.push(d+' day'+((d==1)?'':'s'));
if(d>=7) showhours=false;
if(d>1) showminutes=false;
m[2]-=1;}
if(showhours){
d=n.getUTCHours()-m[4]; if(d!=0) dt.push(d+' hours'+((d==1)?'':'s'));
if(showminutes) d=n.getUTCMinutes()-m[5]; if(d!=0) dt.push(d+' minutes'+((d==1)?'':'s'));
}
dt='about '+dt.join(', ')+' ago';
} else {
m[2]++; if(m[2]<10LastModUseUTC) m[2]='0'+m[2];{
m[3]=m[3].toString(); if( m[32].length=-=1) m[3]='0'+m[3];
dt=m[1]+'-'+m[2]+'-'+m[3];} else {
var dt=new Date(Date.UTC(m[1],m[2]-1,m[3],m[4],m[5],m[6]));
}
dt+=' '+ m[4]+':'+m[51]=dt.getFullYear();
m[12]=dt.getFullYeargetMonth();
m[23]=dt.getMonthgetDate();
m[4]=dt.getHours().toString(); if(m[4].length==1) m[4]='0'+m[4];
m[5]=dt.getMinutes().toString(); if(m[5].length==1) m[5]='0'+m[5];
m[6]=dt.getSeconds().toString(); if(m[6].length==1) m[6]='0'+m[6];
}
 
if(LastModDateFormat=='dmy'){
dt=m[3]+' '+LastModMonths[m[2]]+' '+m[1];
} else if(LastModDateFormat=='dmy'){
dt=LastModMonths[m[2]]+' '+m[3]+', '+m[1];
} else {
m[2]++; if(m[2]<10) m[2]='0'+m[2];
m[3]=m[3].toString(); if(m[3].length==1) m[3]='0'+m[3];
dt=m[1]+'-'+m[2]+'-'+m[3];
}
dt+=' '+m[4]+':'+m[5];
}
 
var s=document.createElement('SPAN');