MediaWiki:NumerAlpha.js: mudanças entre as edições

Conteúdo deletado Conteúdo adicionado
Criou página com '// 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 functi...'
 
Sem resumo de edição
 
(2 revisões intermediárias pelo mesmo usuário não estão sendo mostradas)
Linha 1:
// 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
 
/* jshint esversion: 10 */
function romanize(num) {
 
if (isNaN(num)) return NaN;
function mainFunc() {
const digits = String(+num).split(""),
function romanize(num) {
key = [
if (Number.isNaN(num)) return NaN;
"",
const digits = String(+num).split(""''),;
"C",
const key "CC",= [
"CCC"'',
"CD"'C',
"D"'CC',
"DC"'CCC',
"DCC"'CD',
"DCCC"'D',
"CM"'DC',
""'DCC',
"X"'DCCC',
"XX"'CM',
"XXX"'',
"XL"'X',
"L"'XX',
"LX"'XXX',
"LXX"'XL',
"LXXX"'L',
"XC"'LX',
""'LXX',
"I"'LXXX',
"II"'XC',
"III"'',
"IV"'I',
"V"'II',
"VI"'III',
"VII"'IV',
"VIII"'V',
"IX"'VI',
"C"'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 += 1)}. ${element.innerHTML}`;
}
 
const incrementElemsRoman = document.querySelectorAll(
" '.increment-numeralpha-roman"',
);
 
for (let [i, element] of incrementElemsRoman.entries()) {
element.innerHTML = `${romanize(++(i += 1))}. ${element.innerHTML}`;
}
}
 
if (document.readyState === 'complete' || document.readyState !== 'loading') {
for (let [i, element] of incrementElemsRoman.entries()) {
mainFunc();
element.innerHTML = `${romanize(++i)}. ${element.innerHTML}`;
} else {
document.addEventListener('DOMContentLoaded', mainFunc);
}