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

Content deleted Content added
No edit summary
Tags: Mobile edit Mobile web edit
maintenance: TypeError: undefined is not an object (evaluating 'html.replace')
 
(12 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]].
* Expansion and streamlining by User:Guywan, [[User:Guywan/Scripts/12HourFormat.js]].
*
* Suggestions and bugfinding by:
* User:1989
* User:Amorymeltzer
*/
 
// <nowiki>
$(function()
Line 15 ⟶ 6:
// NAMESPACES //
////////////////
console.log("script");
switch(mw.config.get("wgCanonicalNamespace"))
{
case "Special":
console.log("special");
switch(mw.config.get("wgCanonicalSpecialPageName"))
{
Line 54 ⟶ 43:
case "File":
// Modify time in file history table.
console.log("file");
$("td > a").each(function()
{
// DMY
console.log("table");
$(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;
Line 81 ⟶ 71:
case "view":
if(document.title.indexOf("Difference between revisions") > -1)
{
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)
{
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)
{
// Note a call to html on nonexistent elements returns undefined e.g. $('.sssssss').html(). Guard against this being passed in.
if(hour != 12)
html = html || '';
{
return html.replace(/(\d\d:\d\d)/g, convert);
hour = hour - 12;
}
return (hour + time.substr(2) + " PM");
}
/*
if(hour === 0)
* 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);
hour = 12;
}
function convert(time)
return (hour + time.substr(2) + " AM");
*{
}
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>