MediaWiki:NumerAlpha.js
Ir para navegação
Ir para pesquisar
Nota: Após publicar, você pode ter que limpar o "cache" do seu navegador para ver as alterações.
- Firefox / Safari: Pressione Shift enquanto clica Recarregar, ou pressione Ctrl-F5 ou Ctrl-R (⌘-R no Mac)
- Google Chrome: Pressione Ctrl-Shift-R (⌘-Shift-R no Mac)
- Internet Explorer/Edge: PressioneCtrl enquanto clica Recarregar, ou Pressione Ctrl-F5
- Opera: Pressione Ctrl-F5.
// from: https://stackoverflow.com/questions/9083037/convert-a-number-into-a-roman-numeral-in-javascript
// To be used in Template:CardCatalog and other places as well
function mainFunc() {
function romanize(num) {
if (isNaN(num)) return NaN;
const digits = String(+num).split(""),
key = [
"",
"C",
"CC",
"CCC",
"CD",
"D",
"DC",
"DCC",
"DCCC",
"CM",
"",
"X",
"XX",
"XXX",
"XL",
"L",
"LX",
"LXX",
"LXXX",
"XC",
"",
"I",
"II",
"III",
"IV",
"V",
"VI",
"VII",
"VIII",
"IX",
];
let roman = "";
let i = 3;
while (i--) roman = (key[+digits.pop() + i * 10] || "") + roman;
return Array(+digits.join("") + 1).join("M") + roman;
}
const incrementElemsNumeral = document.querySelectorAll(
".increment-numeralpha-numeral"
);
for (let [i, element] of incrementElemsNumeral.entries()) {
element.innerHTML = `${++i}. ${element.innerHTML}`;
}
const incrementElemsRoman = document.querySelectorAll(
".increment-numeralpha-roman"
);
for (let [i, element] of incrementElemsRoman.entries()) {
element.innerHTML = `${romanize(++i)}. ${element.innerHTML}`;
}
}
if (document.readyState === "complete" || document.readyState !== "loading") {
mainFunc();
} else {
document.addEventListener("DOMContentLoaded", mainFunc);
}