Jump to content

User:Habst/makeTeam.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Habst (talk | contribs) at 17:08, 27 December 2024 (make team table). 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.
{
  const dom = async url => new DOMParser().parseFromString(await (await fetch(url)).text(), 'text/html');
  const teamKey = 'Charlotte';
  const teamName = 'Charlotte 49ers';
  window.trpc ??= await dom('/team-rankings-polls-central/polls-and-rankings-week-by-week?pritype=468&tm=0');
  const teams = Object.fromEntries([...trpc.querySelectorAll('div.menu')[3].querySelectorAll('a.item')].map(a => [a.innerText, a.href.split('=').at(-1)]));
  const id = teams[teamKey];
  window.mhbe ??= await dom('/records-lists/meet-history-by-event?series=3369');
  window.res ??= {};
  const evts = Object.fromEntries([...mhbe.querySelectorAll('select[name=events] option')].slice(1).map(o => [o.innerText, o.value]));
  let allAm = `{| class="wikitable"
! colspan="5" style="{{CollegePrimaryStyle|${teamName}|border=0|color=white}}" | First Team [[All-America]]ns
|-
! scope="col" style="{{CollegeSecondaryStyle|${teamName}|border=0}}" | Team
! scope="col" style="{{CollegeSecondaryStyle|${teamName}|border=0}}" | Championships
! scope="col" style="{{CollegeSecondaryStyle|${teamName}|border=0}}" | Name
! scope="col" style="{{CollegeSecondaryStyle|${teamNAme}|border=0}}" | Event
! scope="col" style="{{CollegeSecondaryStyle|${teamNAme}|border=0}}" | Place
|-\n`;
  for (const gen of [1, 2]) {
    res[gen] ??= {};
    for (const meet of [3368, 3369]) {
      const env = meet === 3368 ? 'Indoor' : 'Outdoor';
      res[gen][meet] ??= {};
      for (const evt in evts) {
        const eid = evts[evt];
        const url = `/records-lists/meet-history-by-event?gender=${gen}&series=${meet}&event=${eid}`;
        console.log(gen, meet, evt, eid, url);
        res[gen][meet][evt] ??= await dom(url);
        const aths = [...res[gen][meet][evt].querySelectorAll(`a[href$="=${id}"]`)].map(a => {
          const row = a.parentElement.parentElement;
          const [pl, name] = row.querySelector('td span').innerText.slice(1).split(') ');
          const athLink = row.querySelector('td a')?.href;
          const tbl = row.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement;
          const year = tbl.querySelector('td').innerText.split(' ')[0];
          return { pl, athLink, name, year };
        });
        allAm += aths.filter(a => +a.pl <= 8).map(a => `| ${gen === 1 ? "Men's" : "Women's"} || [[${a.year} NCAA Division I ${env} Track and Field Championships|${a.year} ${env}]] || [[${a.name}]] || [[${evt} at the NCAA Division I ${env} Track and Field Championships|${evt}]] || {{ord|${a.pl}}}`).join('\n|-\n') + '\n';
      }
    }
  }
  allAm += '|}';
}