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

Content deleted Content added
No edit summary
Tags: Mobile edit Mobile web edit
No edit summary
Line 17:
};
 
$(function()
if(mw.config.get("wgAction") == "history"
|| mw.config.get("wgAction") == "view"
|| mw.config.get("wgAction") == "edit"
|| mw.config.get("wgCanonicalNamespace") == "Special")
{
if(mw.config.get("wgCanonicalNamespace") == "Special")
$(function()
{
switch(mw.config.get("wgCanonicalSpecialPageName"))
// Modify time when viewing page history.
if(mw.config.get("wgAction") == "history")
{
case "Contributions":
$("span.mw-history-histlinks ~ a").each(function()
$(".mw-contributions-list").children().each(function()
{
if($(this).attr("class") === "mw-changeslist-date")
{
var time = $(this).children().first().text(partition($(this).children().first().text()));
});
break;
$(this).text(time[0] + time[1] + time[2]);
}
});case "Log":
case "Userrights":
$("ul").children().each(function()
{
$(this).html(regexpReplace($(this).html(), 1, 5));
});
break;
case "Project":
// TODO
break;
}
}
else if(mw.config.get("wgAction") == "edit")
else if(mw.config.get("wgCanonicalNamespace") == "File")
{
// Modify time in file history table.
$("td > a").each(function()
{
var text = $(this).text();
if($("div").hasClass("mw-warning-with-logexcerpt mw-content-ltr"))
{
var htmlindex = $text.indexOf(".mw-logline-delete:").html();
if(index > -1)
{
var time = text.substr(index - 2, 6);
// Will convert anything in a table matching the pattern "dd:dd," where d is a digit.
$(".mw-logline-delete").html(regexpReplace(html));
if(time.match(/\d\d:\d\d,/)) { $(this).text(partition(text)); }
}
});
}
else if(mw.config.get("wgCanonicalNamespace") == "File")
{
switch(mw.config.get("wgAction"))
// Modify time in file history table.
{
$("td > a").each(function()
case "history":
$("span.mw-history-histlinks ~ a").each(function()
{
var text = if($(this).textattr("class") == "mw-changeslist-date");
var index = text.indexOf(":");
if(index > -1)
{
var time = $(this).text(partition($(this).substrtext(index - 2, 6)));
// Will convert anything in the table matching the pattern "dd:dd," where d is a digit.
if(time.match(/\d\d:\d\d,/))
{
text = partition(text);
$(this).text(text[0] + text[1] + text[2]);
}
}
});
} break;
else if(mw.config.get("wgCanonicalNamespace") == "Special")
case "view":
{
if(document.title.indexOf("Difference between revisions") > -1)
// Modify time when viewing user contributions.
if(mw.config.get("wgCanonicalSpecialPageName") == "Contributions")
{
var comp = "#mw-diff-ntitle1 > strong > a";
$(".mw-contributions-list").children().each(function()
for(i = 0; i < 2; i++)
{
{
var text = partition($(this).children().first().text());
$(comp).html($(comp).html().replace(/(\d\d:\d\d)/g, convert(temp.substr(temp.indexOf(":") - 2, 5))));
comp = "#mw-diff-otitle1 > strong > a";
$(this).children().first().text(text[0] + text[1] + text[2]);
});
}
// Modify time when viewing user log info.
else if(mw.config.get("wgCanonicalSpecialPageName") == "Log")
{
$("ul").first().children().each(function()
{
var html = $(this).html();
$(".diff-currentversion-title").html(partition($(".diff-currentversion-title").text()));
$(this).html(regexpReplace(html));
});
}
break;
// Modify time in user rights page.
else if(mw.config.get("wgCanonicalSpecialPageName") == "Userrights")
case "edit":
{
// Modify time in the "This page has been moved or deleted" banner.
$("ul").children().each(function()
if($("div").hasClass("mw-warning-with-logexcerpt mw-content-ltr"))
{
{
var html = $(this).html();
$(".mw-logline-delete").html(regexpReplace($(".mw-logline-delete").html(), 1, 5));
$(this).html(regexpReplace(html));
});
}
} break;
}
// Modify time when comparing two revisions.
 
else if((mw.config.get("wgAction") == "view") && (document.title.indexOf("Difference between revisions") > -1))
// Modify the time in the footer of most pages.
{
if($("#footer-info-lastmod").length)
var comp = "#mw-diff-ntitle1 > strong > a";
{
var text = "";
$("#footer-info-lastmod").text(partition($("#footer-info-lastmod").text()));
for(i = 0; i < 2; i++)
}
{
});
text = partition($(comp).text());
$(comp).text(text[0] + text[1] + text[2]);
comp = "#mw-diff-otitle1 > strong > a";
}
text = partition($(".diff-currentversion-title").text());
$(".diff-currentversion-title").text(text[0] + text[1] + text[2]);
}
// Modify the time in the footer of most pages.
if($("#footer-info-lastmod").length)
{
var footer = partition($("#footer-info-lastmod").text());
$("#footer-info-lastmod").text(footer[0] + footer[1] + footer[2]);
}
});
}
 
function partition(text)
{
var front = text.substr(0, text.indexOf(":") - 2);
var time = convert(text.substr(text.indexOf(":") - 2, 5));
var end = text.substr(text.indexOf(":") + 3, text.length);
return new Array(front,font + time, + end);
}
 
function regexpReplace(texthtml, start, num)
{
varreturn timehtml.replace(/(\d\d:\d\d)/g, = textconvert(html.substr(1start, 5num)));
return text.replace(/(\d\d\:\d\d)/g, convert(time));
}
 
Line 150 ⟶ 122:
var hour = parseFloat(time.substr(0, 2));
if(hour >= 12 && hour !== 0)
{
if(hour != hour - 12;)
{
hour = hour - 12;
}
time =return (hour + time.substr(2, 5) + " PM");
}
else
if(hour === 0)
{
hour = 12;
time = (hour + time.substr(2, 5) + " AM");
}
return (hour + time.substr(2, 5) + " AM");
}