User:Illuminoid/common.js
From the Super Mario Wiki, the Mario encyclopedia
Jump to navigationJump 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.
$(function() {
//12-hour time 14:32
const pattern = /([01]\d|2[0-3])(:[0-5]\d)/g;
const nsNum = mw.config.get("wgNamespaceNumber");
if ((nsNum === -1 || nsNum % 2 !== 0 || nsNum === 4) && mw.config.get("wgAction") === "View") {
$('.mw-parser-output').each(function() {
var newHtml = $(this).html().replace(pattern, function() {
var args = arguments;
const hour = args[1];
if (Number(hour) > 11) {
var display_hour = (Number(hour) - 12).toString();
if (hour === "12") {
display_hour = "12";
}
else {
if (display_hour.length < 2) {
display_hour = "0" + display_hour;
}
}
return display_hour + args[2] + " p.m.";
}
else {
if (hour === "00") {
return "12" + args[2] + " a.m.";
}
return args[0] + " a.m.";
}
});
if (newHtml !== $(this).html()) $(this).html(newHtml);
});
}
//Remove square brackets from code links
const codeLinks = $('.code-link');
for (var i = 0; i < codeLinks.length; i++) {
codeLinks[i].textContent = codeLinks[i].textContent.replace(/\[\[(.+)\]\]/g, "$1");
}
//Minor fix on [[Special:Contributions]]
if (mw.config.get("wgCanonicalSpecialPageName") === "Contributions") {
const contribInfo = $(".mw-contributions-editor-info")[0];
contribInfo.textContent = contribInfo.textContent.replace("edits", "contributions");
}
});