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

Content deleted Content added
No edit summary
maintenance: TypeError: undefined is not an object (evaluating 'html.replace')
 
(18 intermediate revisions by one other user not shown)
Line 1:
// [[Category:Wikipedia scripts]]
/*
* This script was originally authored by User:Bility, [[User:Bility/convert24hourtime.js]].
* Considerable contributions by User:DannyS712, [[User:DannyS712/12Hours.js]], whose version I have forked.
* Expansion and streamlining by User:Guywan, [[User:Guywan/Scripts/12HourFormat.js]].
*
* Suggestions by bugfinding by:
* User:1989
* User:Amorymeltzer
*/
 
// <nowiki>
$(function()
Line 19 ⟶ 10:
{
case "Special":
switch(mw.config.get("wgCanonicalSpecialPageName"))
{
Line 34 ⟶ 24:
$("ul").children().each(function()
{
$(this).html(rxReplace($(this).html().replace(/()(\d\d:\d\d)(, )/g, rxPartition));
});
break;
Line 55 ⟶ 45:
$("td > a").each(function()
{
// DMY
$(this).html($(this).html().replace(/()(\d\d:\d\d)(, \d{1,2} \w+ \d{4})/g, rxPartition));
// MD,Y
// $("#mw-content-text"this).html($("#mw-content-text"this).html().replace(/( )(\d\d:\d\d)(, \w+ \d{1,2} \w+, \d{4} )/g, rxPartition));
});
break;
Line 73 ⟶ 66:
$(".mw-changeslist-date").each(function()
{
$(this).text(rxReplace($(this).text()));
});
break;
case "view":
if(document.title.indexOf("Difference between revisions") > -1)
{
Line 91 ⟶ 83:
$("#mw-revision-date").html(rxReplace($("#mw-revision-date").html()));
}
// Modify user signatures.
//$("#mw-content-text").html($("#mw-content-text").html().replace(/( )(\d\d:\d\d)(, \d{1,2} \w+ \d{4} )/g, rxPartition));
break;
Line 119 ⟶ 108:
$("#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.
return html.replace(/(\d\d:\d\d)/g, convert);
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)
* 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);
if(hour != 12)
}
function convert(time)
{
var hour = parseFloat(time.substr(0, 2));
if(hour >= 12)
{
if(hour != hour - 12;)
{
hour = hour - 12;
}
return (hour + time.substr(2, 5) + " AMPM");
}
return if(hour + time.substr(2, 5) + "=== PM"0);
{
if( hour != 12);
}
return (hour + time.substr(2) + " AM");
}
});
if(hour === 0)
{
hour = 12;
}
return (hour + time.substr(2, 5) + " AM");
}
// </nowiki>