User:Guywan/Scripts/12HourFormat.js
// [[Category:Wikipedia scripts]]
// <nowiki>
$(function()
{
////////////////
// NAMESPACES //
////////////////
switch(mw.config.get("wgCanonicalNamespace"))
{
case "Special":
switch(mw.config.get("wgCanonicalSpecialPageName"))
{
case "Contributions":
$(".mw-changeslist-date").each(function()
{
$(this).html(rxReplace($(this).html()));
});
break;
case "Log":
case "Userrights":
case "AbuseLog":
$("ul").children().each(function()
{
$(this).html($(this).html().replace(/()(\d\d:\d\d)(, )/g, rxPartition));
});
break;
case "Listusers":
$("ul").children().each(function()
{
$(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()
{
// DMY
$(this).html($(this).html().replace(/()(\d\d:\d\d)(, \d{1,2} \w+ \d{4})/g, rxPartition));
// MD,Y
$(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"))
{
case "history":
$(".mw-changeslist-date").each(function()
{
$(this).text(rxReplace($(this).text()));
});
break;
case "view":
if(document.title.indexOf("Difference between revisions") > -1)
{
$("#mw-diff-ntitle1 > strong > a").html(rxReplace($("#mw-diff-ntitle1 > strong > a").html()));
$("#mw-diff-otitle1 > strong > a").html(rxReplace($("#mw-diff-otitle1 > strong > a").html()));
$(".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"))
{
$(".mw-warning-with-logexcerpt.mw-content-ltr > ul").children().each(function()
{
$(this).html(rxReplace($(this).html()));
});
}
// Modify the time in the footer of most pages.
if($("#footer-info-lastmod").length)
{
$("#footer-info-lastmod").text(rxReplace($("#footer-info-lastmod").text()));
}
/*
* Used when it is unlikely non-times will be matched.
*/
function rxReplace(html)
{
// Note a call to html on nonexistent elements returns undefined e.g. $('.sssssss').html(). Guard against this being passed in.
html = 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)
{
if(hour != 12)
{
hour = hour - 12;
}
return (hour + time.substr(2) + " PM");
}
if(hour === 0)
{
hour = 12;
}
return (hour + time.substr(2) + " AM");
}
});
// </nowiki>
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.