User:Gestrid/convert24hourtime.js
Jump to navigation
Jump to search
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
//Available from [https://en.wikipedia.org/wiki/User:Bility/convert24hourtime.js] under the Creative Commons Attribution-ShareAlike 3.0 Unported License. See [https://creativecommons.org/licenses/by-sa/3.0/] for how to reuse this content.
if (mw.config.get('wgAction')=='history' || mw.config.get('wgCanonicalSpecialPageName')=='Contributions') {
$(document).ready(function() {
if (mw.config.get('wgAction')=='history') {
$('span.mw-history-histlinks ~ a').each(function() {
convertTo12HourTime($(this));
});
} else {
$('ul').first().children().each(function() {
convertTo12HourTime($(this).children().first());
});
};
});
};
function convertTo12HourTime(timeElement) {
var hour = parseFloat(timeElement.html().substr(0,2));
if (hour<12) {
hour = (hour==0) ? 12 : hour;
timeElement.html(hour + timeElement.html().substr(2,3) + ' am' + timeElement.html().substr(5));
} else {
hour = (hour!=12) ? hour-12 : hour;
timeElement.html(hour + timeElement.html().substr(2,3) + ' pm' + timeElement.html().substr(5));
};
if (hour<10) {
timeElement.html(unescape('%A0%A0')+timeElement.html());
};
};