Jump to content

User:Habst/getWikiWinners.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Habst (talk | contribs) at 20:40, 29 August 2024 (Created page with 'window.meets ??= {}; window.redirs ??= {}; getRedir = async pg => { redirs[pg] ??= new DOMParser().parseFromString(await (await fetch(`/wiki/${pg}`)).text(), 'text/html').querySelector('title').innerText.slice(0, -12); return redirs[pg]; } START = 1927; END = new Date().getFullYear(); winners = {}; for (const y of [...Array(END - START)].map((_, i) => i + START)) { const matchEvts = ['200 metres']; meets[y] ??= await (await fetch(`/wiki/${y}_USA_In...'). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
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.
window.meets ??= {};
window.redirs ??= {};
getRedir = async pg => {
  redirs[pg] ??= new DOMParser().parseFromString(await (await fetch(`/wiki/${pg}`)).text(), 'text/html').querySelector('title').innerText.slice(0, -12);
  return redirs[pg];
}

START = 1927;
END = new Date().getFullYear();
winners = {};
for (const y of [...Array(END - START)].map((_, i) => i + START)) {
  const matchEvts = ['200 metres'];
  meets[y] ??= await (await fetch(`/wiki/${y}_USA_Indoor_Track_and_Field_Championships`)).text();
  const doc = new DOMParser().parseFromString(meets[y], 'text/html');
  const trs = [...doc.querySelector('#Women')?.parentElement.nextSibling.nextSibling.querySelectorAll('tr') ?? []];
  const evtRows = [];
  for (const tr of trs) {
    const tds = tr.querySelectorAll('td');
    const rowEvt = tds[0]?.querySelector('a')?.href.split('/').at(-1);
    if (!rowEvt) continue;
    const evt = await getRedir(rowEvt);
    if (matchEvts.includes(evt)) evtRows.push(tds);
  }
  for (const tds of evtRows) {
    const winnerA = tds[1].querySelector('a');
    const winner = winnerA?.href.split('/').at(-1);
    if (!winner) { console.log('no winner', y); continue; }
    const rWinner = winnerA.classList.contains('new') ? new URLSearchParams(winner.split('?').at(-1)).get('title').replaceAll('_', ' ') : await getRedir(winner);
    winners[y] ??= [];
    winners[y].push(rWinner);
  }
}