Jump to content

User:Habst/mostLinks.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
console.log(`{| class="wikitable sortable"
! Rank !! Athlete !! Wins
|-
` + Object.entries([...document.querySelectorAll('a[href^="/wiki/"]'), ...document.querySelectorAll('a[href^="/w/index.php?title"]')].map(a => a.href.split('/').at(-1).split('title=').at(-1).split('&')[0]).filter(pg => !pg.includes('USA_Indoor_Track_and_Field_Championships') && !pg.includes('styles.css') && !['USA_Track_%26_Field', 'The_Athletics_Congress', 'Amateur_Athletic_Union'].includes(pg)).reduce((acc, pg) => {
  acc[pg] ??= 0
  acc[pg]++;
  return acc;
}, {})).sort((a, b) => b[1] - a[1]).slice(0, 100).map((p, _, arr) => {
  const matches = arr.filter(p2 => p2[1] === p[1]);
  const span = matches.length;
  const isFirst = matches[0] === p;
  return `${isFirst ? `|rowspan=${span}| {{ord|${arr.indexOf(matches[0]) + 1}}} |` : ''}| [[${p[0].replaceAll('_', ' ')}${p[0].includes('(') ? '|' : ''}]]${isFirst ? ` ||rowspan=${span}| ${p[1]}` : ''}`;
}).join('\n|-\n') + '\n|}');