MediaWiki:Wikincat-footerMessage/en e MediaWiki:NumerAlpha.js: mudanças entre as páginas

De Wikincat
(Diferenças entre páginas)
Ir para navegação Ir para pesquisar
Sem resumo de edição
 
Sem resumo de edição
 
Linha 1: Linha 1:
// from: https://stackoverflow.com/questions/9083037
Cover images provided by <a href="https://openlibrary.org/" target="_blank">Open Library</a>. Contact: <a href="http://www.google.com/recaptcha/mailhide/d?k=01vfp7qxqOJAuZvMSG0Rc0mw==&amp;c=cwl1ltEdvZATsTyzLVW_S5prB04CDY9MZmntU9ehpMc=" onclick="window.open('http://www.google.com/recaptcha/mailhide/d?k\07501vfp7qxqOJAuZvMSG0Rc0mw\75\75\46c\75cwl1ltEdvZATsTyzLVW_S5prB04CDY9MZmntU9ehpMc\075', '', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=300'); return false;" title="e-mail">e-mail</a>.
// To be used in Template:CardCatalog and other places as well

/* jshint esversion: 10 */

function mainFunc() {
function romanize(num) {
if (isNaN(num)) return NaN;
const digits = String(+num).split('');
const 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);
}

Edição atual tal como às 14h04min de 18 de março de 2024

// from: https://stackoverflow.com/questions/9083037
// To be used in Template:CardCatalog and other places as well

/* jshint esversion: 10 */

function mainFunc() {
  function romanize(num) {
    if (isNaN(num)) return NaN;
    const digits = String(+num).split('');
    const 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);
}