User:DannyS712/12Hours.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
This user script seems to have a documentation page at User:DannyS712/12Hours. |
// Install with:
// <code><nowiki> {{subst:Iusc|User:DannyS712/12Hours.js}} </nowiki></code>
// or with
// <code><nowiki> importScript( 'User:DannyS712/12Hours.js' ); // Backlink: [[User:DannyS712/12Hours.js]] </nowiki></code>
//
// Special thanks to User:Bility and their script, [[User:Bility/convert24hourtime.js]], which I forked.
// If forking this script, please note my contributions / give me credit
var config = {
name: '[[User:DannyS712/12Hours|12Hours]]',
version: 2.3,
debug: false
};
if (mw.config.get('wgAction') === 'history' || mw.config.get('wgCanonicalNamespace') === 'Special' || mw.config.get('wgAction') === 'view') {
$(document).ready(function() {
if (mw.config.get('wgAction')=='history') $('span.mw-history-histlinks ~ a').each(function() {
if (($(this).attr("class") === "mw-changeslist-date") || $(this).attr("class") === "mw-changeslist-date userlink") convertTo12HourTime($(this));
});
else if (mw.config.get('wgCanonicalNamespace')=='Special') {
if (mw.config.get('wgCanonicalSpecialPageName')=='Contributions'){
if ($('div').hasClass('mw-warning-with-logexcerpt mw-content-ltr')) do_log(true);
else $('ul').first().children().each(function() {convertTo12HourTime($(this).children().first());});
}
else if (mw.config.get('wgCanonicalSpecialPageName')=='Log') do_log(false);
else if (mw.config.get('wgCanonicalSpecialPageName')=='Userrights') do_log(false);
}
else if (document.title.indexOf("Difference between revisions") > -1) do_dif();
else if (window.location.href.indexOf("oldid") > -1) {
convertTo12HourTime ( $('#mw-revision-date') );
}
});
}
function do_log ( second ){
$('ul').first().children().each(function() {
var html = $(this).html();
if (config.debug) console.log( html );
html = html.replace(/(\d\d:\d\d)/g, on_log);
if (config.debug) console.log(html);
$(this).html( html );
//convertTo12HourTime_log($(this));
});
if (second){
if (config.debug) console.log("blocked");
$('ul').eq(1).children().each(function() {
var html = $(this).html();
if (config.debug) console.log( html );
html = html.replace(/(\d\d:\d\d)/g, on_log);
if (config.debug) console.log(html);
$(this).html( html );
});
}
}
function on_log ( match, offset, string ){
if (config.debug) console.log( match, convertTo12HourTime_log(match) );
return convertTo12HourTime_log(match);
}
function on_diff ( rev_time_act ){
var just_time = rev_time_act.substr(0, 5);
var rev_time_rst = rev_time_act.substr(5);
var new_time = convertFromTime(just_time);
return ( new_time + rev_time_rst);
}
function convertTo12HourTime(timeElement) {
var time = timeElement.html().substr(0,5);
var converted = convertFromTime( time, true );
timeElement.html(converted + timeElement.html().substr(5));
}
function convertTo12HourTime_log( time ) {
var converted = convertFromTime( time, true );
return converted;
}
function convertFromTime( time, space ){
var hour = parseFloat(time.substr(0,2));
if (hour<12) {
hour = (hour===0) ? 12 : hour;
time = (hour + time.substr(2,5) + ' am');
} else {
hour = (hour!=12) ? hour-12 : hour;
time = (hour + time.substr(2,5) + ' pm');
}
if (hour<10) {
if (space) time = (unescape('%A0%A0')+time);
}
return time;
}
function do_dif(){
var rev_time_text = $("#mw-diff-ntitle1 > strong > a").text();
var rev_time_pre;
var rev_time_rest;
if ( rev_time_text.substr(0, 15) === "Revision as of " ){
rev_time_pre = "Revision as of ";
rev_time_rest = rev_time_text.substr(15);
} else if ( rev_time_text.substr(0, 22) === "Latest revision as of " ){
rev_time_pre = "Latest revision as of ";
rev_time_rest = rev_time_text.substr(22);
}
$("#mw-diff-ntitle1 > strong > a").text( rev_time_pre + on_diff(rev_time_rest));
var rev_time_text2 = $("#mw-diff-otitle1 > strong > a").text();
var rev_time_pre2;
var rev_time_rest2;
if ( rev_time_text2.substr(0, 15) === "Revision as of " ){
rev_time_pre2 = "Revision as of ";
rev_time_rest2 = rev_time_text2.substr(15);
}
$("#mw-diff-otitle1 > strong > a").text( rev_time_pre2 + on_diff(rev_time_rest2));
}