Jump to content

User:Habst/gbrTable.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Habst (talk | contribs) at 17:48, 11 August 2024 (add variables). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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.
YEAR = 2002;
DATE = 'March 1–2';
CITYSTATE = 'New York City, New York';
STATE = 'New York (state)';
TANDFIN = 'New York City'; // STATE;
STADIUM = '[[Fort Washington Avenue Armory]]';
IMG = 'File:US Navy 120106-N-PA426-003 U.S. Navy SEALs and special warfare combatant-craft crewmen (SWCC) recruiters attended the 18th annual Hispanic Track an.jpg'
art = `{{Infobox Athletics Championships
| Name = __YEAR__ USA Indoor Track and Field Championships
| Colour = #A9F5A9
| Logo =
| Size = <!-- do not add "px" -->
| Host city = [[${CITYSTATE}]], United States
| Dates = __DATE__
| Stadium = ${STADIUM}
| Stadium image = [[${IMG}|200px]]
| Level = Senior
| Type = Indoor
| Athletes participating =
| Events = __EVTS__
| Records set =
| Previous = [[__PREV__ USA Indoor Track and Field Championships|__PREV__]]
| Next = [[__NEXT__ USA Indoor Track and Field Championships|__NEXT__]]
}}
The '''__YEAR__ [[USA Indoor Track and Field Championships]]''' were held at the ${STADIUM} in [[${CITYSTATE}]]. Organized by [[USA Track and Field]] (USATF), the two-day competition took place __DATE__ and served as the [[national championships]] in indoor [[track and field]] for the [[United States]].<ref>{{cite web |title=UNITED STATES INDOOR CHAMPIONSHIPS (MEN) |url=http://www.gbrathletics.com/nc/usai.htm |website=GBR Athletics |access-date=9 August 2024}}</ref> The championships in [[combined track and field events]] were held at a different time.<ref>{{cite web |title=2020 & 35th USA Indoor Men's Heptathlon Media Guide |url=https://docslib.org/doc/3075509/2020-usa-i-mens-heptathlon |website=DocsLib |page=9 |access-date=9 August 2024}}</ref><ref>{{cite web|url=https://decathlonusa.typepad.com/files/2014-usatf-i-w-pentathlon.pdf|title=2014 USATF Indoor Women's Pentathlon|page=5|access-date=9 August 2024}}</ref>

At the meeting, 

==Medal summary==
{{clear}}
===Men===
{| {{MedalistTable|columns=2|type=Event}}
|-
__MTBL__
|}

===Women===
{| {{MedalistTable|columns=2|type=Event}}
|-
__WTBL__
|}

==References==
{{reflist}}
; Results
* {{cite web |title=UNITED STATES INDOOR CHAMPIONSHIPS (MEN) |url=http://www.gbrathletics.com/nc/usai.htm |website=GBR Athletics |access-date=9 August 2024}}
* {{cite web |title=2020 & 35th USA Indoor Men's Heptathlon Media Guide |url=https://docslib.org/doc/3075509/2020-usa-i-mens-heptathlon |website=DocsLib |page=9 |access-date=9 August 2024}}
* {{cite web|url=https://decathlonusa.typepad.com/files/2014-usatf-i-w-pentathlon.pdf|website=Decathlon USA|title=2014 USATF Indoor Women's Pentathlon|page=5|access-date=9 August 2024}}

{{USA Indoor Track and Field Championships}}
{{__YEAR__ in athletics}}

{{draft cats|
[[Category:USA Indoor Track and Field Championships|__YEAR__]]
[[Category:__MONTH__ __YEAR__ sports events in the United States]]
[[Category:__YEAR__ in athletics (track and field)|USA Indoor Track and Field Championships]]
[[Category:Sports competitions in ${STATE.split(',')[0]}]]
[[Category:__YEAR__ in sports in ${STATE}|USA Indoor Track and Field Championships]]
[[Category:Track and field in ${TANDFIN}]]
}}`;
res = {};
medals = { M: '', W: '' };
window.wHtml ??= await (await fetch('http://www.gbrathletics.com/nc/usawi.htm')).text();
wDoc = new DOMParser().parseFromString(wHtml, 'text/html');
for (const gen of ['M', 'W']) {
  tbls = (gen === 'M' ? document : wDoc).querySelectorAll('table:is([width="886"], [width="608"])');
  console.log(gen, tbls.length)
  for (const tbl of tbls) {
    const topTrs = tbl.querySelectorAll('tr');
    const evts = topTrs[0].querySelectorAll('td');
    const tds = topTrs[1].querySelectorAll('td');
    const years = tds[0].innerHTML.split('<br>');
    for (let i = 0; i < 3; i++) {
      const gEvt = evts[i * 2 + 1]?.innerText;
      if (!gEvt) continue;;
      const evt = (gEvt[0] + gEvt.slice(1).toLowerCase().replaceAll('metres', 'm'))
        .replace('35 pounds weight', 'Weight throw').replace('20 pounds weight', 'Weight throw').replace('Shot', 'Shot put')
        .replace('Heptathlon', 'Indoor heptathlon|Heptathlon')
        .replace('Pentathlon', 'Indoor pentathlon|Pentathlon');
      const winners = tds[i * 2 + 1].innerHTML.split('<br>');
      const marks = tds[i * 2 + 2].innerHTML.split('<br>');
      for (let j = 0; j < years.length; j++) {
        const yr = years[j];
        res[yr] ??= {};
        res[yr][gen] ??= {};
        let winner = winners[j];
        if (winner === '-' || !winner?.trim()) continue;
        if (winner.includes('not held')) continue;
        if (winner.endsWith('&')) winner += ' ' + winners[j + 1];
        let mark = marks[j];
        if (evt.includes('put') || evt.includes('throw') || evt.includes('jump') || evt.includes('vault')) mark += ' m';
        if (evt.includes('athlon')) mark += ' pts';
        res[yr][gen][evt] = [winner, mark];
      }
    }
  }
  medals[gen] = Object.entries(res[YEAR][gen]).map(([evt, [ath, mark]]) => {
    return `| [[${evt}]]
| [[${ath}]] || ${mark}
|  || 
|  || `;
  }).join('\n|-\n');
}
menEvts = Object.keys(res[YEAR].M).length;
womenEvts = Object.keys(res[YEAR].W).length;
numEvts = `${menEvts + womenEvts} (${menEvts} men's + ${womenEvts} women's)`;
art.replaceAll('__YEAR__', YEAR).replaceAll('__PREV__', YEAR - 1).replaceAll('__NEXT__', YEAR + 1).replaceAll('__DATE__', DATE).replaceAll('__MTBL__', medals.M).replaceAll('__WTBL__', medals.W).replaceAll('__EVTS__', numEvts).replaceAll('__MONTH__', DATE.split(' ')[0]);