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')
 
(30 intermediate revisions by one other user not shown)
Line 1:
// [[Category:Wikipedia scripts]]
/*
// <nowiki>
* 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.
*/
 
$(function()
{
Line 14 ⟶ 10:
{
case "Special":
switch(mw.config.get("wgCanonicalSpecialPageName"))
{
case "Contributions":
$(".mw-contributionschangeslist-listdate").children().each(function()
{
$(this).childrenhtml().first().text(partitionrxReplace($(this).children().first().texthtml()));
});
break;
Line 29 ⟶ 24:
$("ul").children().each(function()
{
$(this).html(regexpReplace($(this).html().replace(/()(\d\d:\d\d)(, )/g, rxPartition));
});
break;
case "Listusers":
var index, html, time;
$("ul").children().each(function()
{
$(this).html = ($(this).html().replace(/(on \d{1,2} \w+ \d{4} at )(\d\d:\d\d)()/g, rxPartition));
index = html.indexOf("Created on ");
time = partition(html.substring(index));
html = html.substring(0, index);
$(this).html(html + time);
});
break;
Line 56 ⟶ 45:
$("td > a").each(function()
{
// DMY
$(this).html(regexpReplace($(this).html()));
$("#mw-content-text"this).html($("#mw-content-text"this).html().replace(/(<\/a>\)\s(\d\d:\d\d)(,\s \d{1,2}\s \w+\s \d{4}\s)/g, partitionrxPartition));
// MD,Y
$(this).html($(this).html().replace(/()(\d\d:\d\d)(, \w+ \d{1,2}, \d{4})/g, rxPartition));
});
break;
Line 72 ⟶ 64:
{
case "history":
$("span.mw-historychangeslist-histlinks ~ adate").each(function()
{
if$(this).text(rxReplace($(this).attrtext("class") == "mw-changeslist-date"));
{
$(this).text(partition($(this).text()));
}
});
break;
case "view":
if(document.title.indexOf("Difference between revisions") > -1)
{
$("#mw-diff-ntitle1 > strong > a").html(regexpReplacerxReplace($("#mw-diff-ntitle1 > strong > a").html()));
$("#mw-diff-otitle1 > strong > a").html(regexpReplacerxReplace($("#mw-diff-otitle1 > strong > a").html()));
$(".diff-currentversion-title").text(partitionrxReplace($(".diff-currentversion-title").text()));
}
Line 93 ⟶ 81:
if($("div").hasClass("mw-revision"))
{
$("#mw-revision-date").html(regexpReplacerxReplace($("#mw-revision-date").html()));
}
// Modify user signatures.
$("#mw-content-text").html($("#mw-content-text").html().replace(/(<\/a>\)\s\d\d:\d\d,\s\d{1,2}\s\w+\s\d{4}\s)/g, partition));
break;
Line 114 ⟶ 99:
$(".mw-warning-with-logexcerpt.mw-content-ltr > ul").children().each(function()
{
$(this).html(regexpReplacerxReplace($(this).html()));
});
}
Line 121 ⟶ 106:
if($("#footer-info-lastmod").length)
{
$("#footer-info-lastmod").text(partitionrxReplace($("#footer-info-lastmod").text()));
}
});
 
/*
function partition(text)
* Used when it is unlikely non-times will be matched.
*/
var front = text.substr(0, text.indexOf(":") - 2);
function partitionrxReplace(texthtml)
var time = convert(text.substr(text.indexOf(":") - 2, 5));
{
var end = text.substr(text.indexOf(":") + 3, text.length);
// 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);
}
/*
return (front + time + end);
* Used when a very specific match needs to be made and
}
* only a substring of the match should be modified.
 
*/
function regexpReplace(html) // Regexp param?
function rxPartition(match, p1, p2, p3)
{
{
return html.replace(/(\d\d:\d\d)/g, convert);
return (p1 + convert(p2) + p3);
}
}
 
function convert(time)
{
var hour = parseFloat(time.substr(0, 2));
function convert(time)
if(hour >= 12)
{
if(var hour != 12parseFloat(time.substr(0, 2));
if(hour >= 12)
{
if(hour != hour - 12;)
{
hour = hour - 12;
{}
}
var return (hour =+ parseFloat(time.substr(0, 2) + " PM");
}
return if(hour + time.substr(2, 5) + "=== PM"0);
{
if( hour === 0)12;
}
return (fronthour + time.substr(2) + end" AM");
}
});
// </nowiki>
if(hour === 0)
{
hour = 12;
}
return (hour + time.substr(2, 5) + " AM");
}