User talk:Habst/DL
Appearance
Created with this code:
nfix = { 'Blanka VlašIć': 'Blanka Vlašić', 'Daniel Taylor': 'Dan Taylor (shot putter)|', 'Virginia Crawford': 'Ginnie Crawford', 'Emma Green': 'Emma Green (athlete)|', 'Ryan Bailey': 'Ryan Bailey (athlete)|', 'David Neville': 'David Neville (athlete)|', 'David Oliver': 'David Oliver (athlete)|', 'Jesse Williams': 'Jesse Williams (athlete)|', 'Jason Young': 'Jason Young (discus thrower)|', 'Michelle Carter': 'Michelle Carter (athlete)|', 'Zoltán KőVágó': 'Zoltán Kővágó', 'Richard Thompson': 'Richard Thompson (athlete)|', 'David Greene': 'David Greene (athlete)|', 'Guillermo Martínez': 'Guillermo Martínez (athlete)|', 'Yelena Sokolova': 'Yelena Sokolova (athlete)|', 'Nadine Müller': 'Nadine Müller (athlete)|', 'Christopher Brown': 'Christopher Brown (athlete)|', 'Ryan Wilson': 'Ryan Wilson (athlete)|', 'Andrew Turner': 'Andrew Turner (athlete)|', 'David Payne': 'David Payne (athlete)|', 'Eglė BalčIūnaitė': 'Eglė Balčiūnaitė', 'Michael Rodgers': 'Michael Rodgers (athlete)|', 'Félix Sánchez': 'Félix Sánchez (hurdler)|', 'Donald Thomas': 'Donald Thomas (athlete)|', 'Randy Lewis': 'Randy Lewis (athlete)|', 'Chris Hill': 'Chris Hill (athlete)|', 'Jinzhe LI': 'Jinzhe Li', 'Barbara Parker': 'Barbara Parker (athlete)|', 'Damiel DosséVI': 'Damiel Dossevi', 'Kellie Wells': 'Kellie Wells (athlete)|', 'Morten Jensen': 'Morten Jensen (athlete)|', 'Richard Yates': 'Richard Yates (athlete)|', 'Rhys Williams': 'Rhys Williams (athlete)|', 'Brad Walker': 'Brad Walker (athlete)|', 'Steve Lewis': 'Steven Lewis', 'Yanxi LI': 'Yanxi Li', 'Yanfeng LI': 'Yanfeng Li', } resp = ''; hasDqNote = false; await (async () => { const isField = s => ['Vault', 'Jump', 'Throw', 'Put'].some(w => s.split(' ').includes(w)); if (typeof nameFixer === 'undefined') { const script = Object.assign(document.createElement('script'), { src: 'https://unpkg.com/name-fixer' }); document.body.appendChild(script); await new Promise(res => script.addEventListener('load', res)); } for (const { id, mtg, color, inv } of [ { id: 33, mtg: 'Doha', color: '#6c193f' }, { id: 34, mtg: 'Shanghai', color: '#3a9b20' }, { id: 18, mtg: 'Oslo', color: '#3f48cc' }, { id: 19, mtg: 'Rome', color: '#e5b122' }, { id: 35, mtg: 'New York', color: '#005da3' }, { id: 25, mtg: 'Eugene', color: '#000000', inv: true }, { id: 36, mtg: 'Lausanne', color: '#dc0b28' }, { id: 37, mtg: 'Gateshead', color: '#2e3160' }, { id: 21, mtg: 'Paris', color: '#d0ab4c' }, { id: 38, mtg: 'Monaco', color: '#dd291e' }, { id: 27, mtg: 'Stockholm', color: '#009fe3' }, { id: 24, mtg: 'London', color: '#c6362d' }, { id: 2, mtg: 'Zurich', color: '#009fe3' }, { id: 22, mtg: 'Brussels', color: '#003781' }, ]) { const html = await (await fetch(`https://dl.all-athletics.com/dlra/en/${id}/2010/all`)).text(); const document = new DOMParser().parseFromString(html, 'text/html'); const parseTable = (tbl) => { return [...tbl.querySelectorAll("tbody tr")].map((tr) => { const achiever = tr.querySelector(".achiever"); const birthYear = +(tr.querySelector(".birthdate")?.textContent ?? NaN); const results = tr.querySelectorAll(".result"); return { place: tr.querySelector(".place")?.textContent ?? "", athlete: achiever?.textContent ?? "", id: achiever ?.querySelector("a") ?.href.match( /^http:\/\/www.diamondleague.com\/athletes\/(\d+).htm/ )?.[1] ?? "", nat: tr.querySelector(".nationality")?.textContent ?? "", birthYear: birthYear < 100 ? 1900 + birthYear : birthYear, mark: results[0]?.textContent ?? "", doping: results[1]?.textContent ?? "", }; }); }; const headers = [...document.querySelectorAll("h2")].filter( (h2) => h2.nextElementSibling?.tagName === "H2" ); const evts = {}; for (const hdr of headers) { const hdrText = hdr.textContent ?? ""; evts[hdrText] = []; let ptr = hdr; let heat = {}; let lastTitle = ""; while ( ptr && (ptr === hdr || !headers.includes(ptr)) ) { ptr = ptr?.nextElementSibling; if (ptr?.tagName === "H2") { heat.title = ptr?.textContent ?? ""; lastTitle = heat.title; } if (ptr?.tagName === "H3") heat.detail = ptr?.textContent ?? ""; if (ptr?.tagName === "TABLE") { heat.data = parseTable(ptr); heat.title ??= lastTitle; heat.category = hdrText; evts[hdrText].push(heat); heat = {}; } } } resp += `{| class="wikitable mw-collapsible mw-collapsed" width=1150 style="font-size: 70%; margin-bottom: -10px" |- !colspan=13 align=center style="font-size: initial; background-color: ${color};${inv ? ' color: white;' : ''}"| ${mtg} |- !width=100| Event !width=150| 1st !!width=50| Mark !width=150| 2nd !!width=50| Mark !width=150| 3rd !!width=50| Mark !width=150| 4th !!width=50| Mark !width=150| 5th !!width=50| Mark !width=150| 6th !!width=50| Mark\n`; for (const evt of evts['Diamond Discipline'].filter(evt => evt.detail.startsWith('Final'))) { const disc = evt.title.split(' - ')[0]; const wind = evt.detail.split(', wind: ')[1]; resp += `|-\n`; resp += `| ${disc}${wind ? `<br><small>(${wind} m/s)</small>` : ''}\n`; for (const dat of evt.data.slice(0, 6)) { const names = dat.athlete.split(' '); const lastNameIdx = names.findIndex((s, i) => i && s.toUpperCase() === s); const firstName = names.slice(0, lastNameIdx).join(' '); const lastName = nameFixer.nameFixer(names.slice(lastNameIdx).join(' ')); const name = firstName + ' ' + lastName; resp += `| [[${nfix[name] ?? name}]]<br>{{flagg|cnce|${dat.nat}|size=12}} || ${dat.doping ? `DQ{{efn|name=dq${hasDqNote ? '|Disqualified after competition due to [[doping in sport|antidoping rule violation]]' : ''}}}` : dat.mark + (isField(disc) ? ' m' : '')}\n`; if (dat.doping) hasDqNote = true; } } resp += '|}\n'; } })();