User:Nesqwik/common.js
From Growtopia Wiki
More actions
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.
(function () {
"use strict";
function convertTo12Hour(text) {
return text.replace(/\b([01]?\d|2[0-3]):([0-5]\d)\b(?!\s*[AaPp][Mm])/g, function (_, h, m) {
h = parseInt(h, 10);
const period = h >= 12 ? "PM" : "AM";
h = h % 12 || 12;
return h + ":" + m + "\u202F" + period;
});
}
function reformatPageTimestamps() {
const selectors = [
".page-info__text",
"#footer-info-lastmod",
"#lastmod",
".printfooter",
"#mw-revision-info",
];
selectors.forEach(function (sel) {
const el = document.querySelector(sel);
if (el) {
el.innerHTML = convertTo12Hour(el.innerHTML);
}
});
}
mw.hook("wikipage.content").add(reformatPageTimestamps);
$(document).ready(reformatPageTimestamps);
})();