User:Guywan/Scripts/12HourFormat.js: Difference between revisions

Content deleted Content added
No edit summary
mNo edit summary
Line 1:
// This is the Deployment Version:
/* [[Category:Wikipedia scripts]]
// See User:Guywan/Scripts/12HourFormat.js for annotated code.
* This script was originally authored by User:Bility, [[User:Bility/convert24hourtime.js]].
* Considerable contributions by User:DannyS712, [[User:DannyS712/12Hours.js]].
* Expansion and streamlining by User:Guywan, [[User:Guywan/Scripts/12HourFormat.js]].
*
* Suggestions and bugfinding by:
* User:1989
* User:Amorymeltzer
*/
 
// <nowiki>
$(function()
{
////////////////
// NAMESPACES //
////////////////
switch(mw.config.get("wgCanonicalNamespace"))
{
Line 27 ⟶ 15:
});
break;
case "Log":
case "Userrights":
Line 36 ⟶ 23:
});
break;
case "Listusers":
$("ul").children().each(function()
Line 42 ⟶ 28:
$(this).html($(this).html().replace(/(on \d{1,2} \w+ \d{4} at )(\d\d:\d\d)()/g, rxPartition));
});
break;
case "Project":
// TODO
break;
}
break;
case "File":
// Modify time in file history table.
$("td > a").each(function()
{
Line 59 ⟶ 39:
$(this).html($(this).html().replace(/()(\d\d:\d\d)(, \w+ \d{1,2}, \d{4})/g, rxPartition));
});
break;
case "User":
// TODO
break;
}
/////////////
// ACTIONS //
/////////////
switch(mw.config.get("wgAction"))
{
Line 78 ⟶ 49:
});
break;
case "view":
if(document.title.indexOf("Difference between revisions") > -1)
Line 86 ⟶ 56:
$(".diff-currentversion-title").text(rxReplace($(".diff-currentversion-title").text()));
}
// Modify time in permalink pages.
if($("div").hasClass("mw-revision"))
{
$("#mw-revision-date").html(rxReplace($("#mw-revision-date").html()));
}
break;
case "edit":
// TODO
break;
}
///////////
// OTHER //
///////////
// Modify time in warning banners.
if($("div").hasClass("mw-warning-with-logexcerpt mw-content-ltr"))
{
Line 111 ⟶ 69:
});
}
 
// Modify the time in the footer of most pages.
if($("#footer-info-lastmod").length)
{
Line 118 ⟶ 74:
}
});
 
/*
* Used when it is unlikely non-times will be matched.
*/
function rxReplace(html)
{
return html.replace(/(\d\d:\d\d)/g, convert);
}
 
/*
* Used when a very specific match needs to be made and
* only a substring of the match should be modified.
*/
function rxPartition(match, p1, p2, p3)
{
return (p1 + convert(p2) + p3);
}
 
function convert(time)
{
var hour = parseFloat(time.substr(0, 2));
if(hour >= 12)
{
Line 146 ⟶ 91:
hour = hour - 12;
}
return (hour + time.substr(2) + " PM");
}
if(hour === 0)
{
hour = 12;
}
return (hour + time.substr(2) + " AM");
}