User:Habst/getWikiWinners.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | Documentation for this user script can be added at User:Habst/getWikiWinners. |
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);
}
}