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')
 
(81 intermediate revisions by one other user not shown)
Line 1:
// [[Category:Wikipedia scripts]]
/*
// <nowiki>
* Install with:
$(function()
* <code><nowiki>{{subst:Iusc|User:Guywan/Scripts/12HourFormat.js}}</nowiki></code>
* or:
* <code><nowiki>importScript("User:Guywan/Scripts/12HourFormat.js"); // Backling: [[User:Guywan/Scripts/12HoursFormat.js]]</nowiki></code>
*
* This script was originally authored by User:Bility, [[User:Bility/convert24hourtime.js]],
* and altered by User:DannyS712, [[User:DannyS712/12Hours.js]], whose version I have forked
* to make some minor changes.
*/
 
var config =
{
////////////////
name : "[[User:Guywan/Scripts/12HourFormat]]",
// NAMESPACES //
version : 3.0,
////////////////
debug : false
};
switch(mw.config.get("wgCanonicalNamespace"))
 
if(mw.config.get("wgAction") == "history"
|| mw.config.get("wgCanonicalNamespace") == "Special"
|| ((mw.config.get("wgAction") == "view")
&& (document.title.indexOf("Difference between revisions") > -1)))
{
$(document).ready(function()
{
case "Special":
// Modify time when viewing page history.
if switch(mw.config.get("wgActionwgCanonicalSpecialPageName") == "history")
{
$("span.mw-history-histlinks ~ a").each(function()
{
case "Contributions":
if($(this).attr("class") === "mw-changeslist-date")
$(".mw-changeslist-date").each(function()
{
{
var time = conver(this.html().substr(0, 5));
$(this).html(rxReplace($(this).html()));
});
break;
case "Log":
this.html(converted + this.html().substr(5));
case "Userrights":
}
case "AbuseLog":
});
$("ul").children().each(function()
}
{
/*else if(mw.config.get("wgCanonicalNamespace") == "Special")
$(this).html($(this).html().replace(/()(\d\d:\d\d)(, )/g, rxPartition));
{
});
if(mw.config.get("wgCanonicalSpecialPageName") == "Contributions")
{ break;
if($("div").hasClass("mw-warning-with-logexcerpt mw-content-ltr"))
case "Listusers":
{
$("ul").children().each(function()
do_log(true);
}
else
{
$("ul").first().children().each(function()
{
$(this).html($(this).html().replace(/(on \d{1,2} \w+ \d{4} at )(\d\d:\d\d)()/g, rxPartition));
convertTo12HourTime($(this).children().first());
});
} break;
case "Project":
// TODO
break;
}
}*/ break;
// Modify time when comparing two revisions.
case "File":
else if(mw.config.get("wgAction") == "view")
// Modify time in file history table.
{
$("td > a").each(function()
var comp = "#mw-diff-ntitle1 > strong > a";
var text = "";
for(i = 0; i < 2; i++)
{
// DMY
text = partition($(comp).text());
$(this).html($(this).html().replace(/()(\d\d:\d\d)(, \d{1,2} \w+ \d{4})/g, rxPartition));
// MD,Y
console.log(text[0]);
$(this).html($(this).html().replace(/()(\d\d:\d\d)(, \w+ \d{1,2}, \d{4})/g, rxPartition));
console.log(text[1]);
});
console.log(text[2]);
break;
$(comp).text(text[0] + text[1] + text[2]);
comp = "#mw-diff-otitle1 > strong > a";
}
case "User":
text = partition($(".diff-currentversion-title").text());
// TODO
$(".diff-currentversion-title").text(text[0] + text[1] + text[2]);
} break;
}
// Modify the time that is in the footer of probably every page.
/////////////
// if($("#footer-info-lastmod").length)
// ACTIONS //
{
/////////////
var footer = partition($("#footer-info-lastmod").text());
switch(mw.config.get("wgAction"))
{
case "history":
$(".mw-changeslist-date").each(function()
{
$(this).text(rxReplace($(this).text()));
});
break;
case "view":
console.log(footer[0]);
if(document.title.indexOf("Difference between revisions") > -1)
console.log(footer[1]);
{
console.log(footer[2]);
$("#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.
$("#footer-info-lastmod").text(footer[0] + footer[1] + footer[2]);
if($("div").hasClass("mw-revision"))
}
{
});
$("#mw-revision-date").html(rxReplace($("#mw-revision-date").html()));
}
}
 
break;
function partition(text)
{
case "edit":
var front = text.substr(0, text.indexOf(":") - 2);
// TODO
console.log(front);
break;
}
///////////
var time = text.substr(text.indexOf(":") - 2, 5);
// OTHER //
console.log(time);
///////////
time = convert(time);
console.log(time);
// Modify time in warning banners.
var end = text.substr(text.indexOf(":") + 3, text.length);
if($("div").hasClass("mw-warning-with-logexcerpt mw-content-ltr"))
console.log(end);
{
$(".mw-warning-with-logexcerpt.mw-content-ltr > ul").children().each(function()
return new Array(front, time, end);
{
}
$(this).html(rxReplace($(this).html()));
});
}
 
// Modify the time in the footer of most pages.
function convert(time)
if($("#footer-info-lastmod").length)
{
{
var hour = parseFloat(time.substr(0, 2));
$("#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);
}
/*
if(hour >= 12 && 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);
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) + " PM");
}
time = if(hour + time.substr(2, 5) + "=== pm"0);
{
hour = 12;
}
return (hour + time.substr(2) + " AM");
}
});
else
// </nowiki>
{
time = (hour + time.substr(2, 5) + " am");
}
return time;
}