User:Habst/getNationalRecords.js

window.cache ??= {}; country='NOR'; demonym='Norwegian'; cat='U18'; (async => { let output = ''; for (const gen of ['women', 'men']) for (const env of ['outdoor', 'indoor']) { output += `===${cat} ${gen} ${env}=== {| class="wikitable sortable" style="font-size: 90%; width: 95%;" ! Event !! Record !! Athlete !! Date !! Meet !! Place !! Country !! Age !! Ref `; const rows = []; for (const evt of { outdoor: [ "100", "200",  "400",  "800",  "1500",  "Mile", "3000", "5000",  "10000",  "2000S", "3000S", gen === 'women' ? "100H" : "110H", "400H", "HJ", "PV", "LJ", "TJ", "SP", "DT", "HT", "JT", gen === 'women' ? "Hep" : "Dec" ], indoor: [ "60", "200",  "400",  "800",  "1500",  "Mile", "3000", "5000",  "60H", "HJ", "PV", "LJ", "TJ", "SP", "WT", gen === 'women' ? "Pen" : "Hep", ]}[env]) { const url = `/api/lists/alltime/${country}/${env}/${cat}/${gen}/${evt}?&top=10`; console.log(url); const data = cache[url] ??= await (await fetch(url, { headers: {    Authorization: new Function([...document.querySelectorAll('script:not([src]):not([type])')].at(-1).innerText+'return auth'),  }, })).json const div = data.templates[0].divs[0]; const res = div.tables[0].body[0]; if (!res) continue; if (res.venue === 'Saint-Denis') res.venue = 'Paris'; const wikiVenue = res.venueCountry === 'USA' ? res.venue : `${res.venue}, ${res.venueCountryFull}`; const ayd = res.dateOfBirth ? `` : res.yearOfBirth ? `24 years years` : ''; rows.push(`| ${div.title.replace('One Mile', 'Mile run')} || ${res.result} || ${res.name} || ${res.date} || ${res.competitionLong ?? ''} || ${res.venue} || || ${ayd} || `); } output += rows.join('\n|-\n') + '\n|}\n\n'; } console.log(output); return output; })