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')
 
(24 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.
* I have mainly streamlined the code and introduced more functionality.
*/
 
// <nowiki>
$(function()
Line 15 ⟶ 10:
{
case "Special":
switch(mw.config.get("wgCanonicalSpecialPageName"))
{
case "Contributions":
$(".mw-contributionschangeslist-listdate").children().each(function()
{
$(this).children().first().texthtml(rxReplace($(this).children().first().texthtml()));
});
break;
Line 30 ⟶ 24:
$("ul").children().each(function()
{
$(this).html(rxReplace($(this).html().replace(/()(\d\d:\d\d)(, )/g, rxPartition));
});
break;
Line 51 ⟶ 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 67 ⟶ 64:
{
case "history":
$("span.mw-historychangeslist-histlinks ~ adate").each(function()
{
if$(this).text(rxReplace($(this).attrtext("class") == "mw-changeslist-date"));
{
$(this).text(rxReplace($(this).text()));
}
});
break;
case "view":
if(document.title.indexOf("Difference between revisions") > -1)
{
Line 90 ⟶ 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 118 ⟶ 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)
console.log(match);
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>