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 14:36, 21 August 2024 (update location). 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.
// <nowiki>
YEAR = 1969;
DATE = 'March 1';
CITYSTATE = 'Philadelphia, Pennsylvania';
STATE = 'Pennsylvania';
SPORTSCOMPIN = 'Philadelphia';
TANDFIN = 'Pennsylvania';
STADIUM = '[[Spectrum (arena)|]]';
EVENTSAT = '';
IMG = 'File:The Spectrum Philadelphia PA.jpg';
art = `{{Short description|National athletics championship event}}
{{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 the [[Amateur Athletic Union]] (AAU), the competition took place on __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>

At the championships, 

==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=UNITED STATES INDOOR CHAMPIONSHIPS (WOMEN) |url=http://www.gbrathletics.com/nc/usawi.htm |website=GBR Athletics |access-date=9 August 2024}}

{{USA Indoor Track and Field Championships}}

{{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 ${SPORTSCOMPIN}]]
[[Category:__YEAR__ in sports in ${TANDFIN}|USA Indoor Track and Field Championships]]
[[Category:Track and field in ${TANDFIN}]]
${EVENTSAT}}}`;
res = {};
medals = { M: '', W: '' };
yards = {
  '1500 m': 'Mile run',
  '60 m': '60 yards',
  '200 m': '220 yards',
  '400 m': '440 yards',
  '800 m': '880 yards',
  '3000 m': '2 miles',
  '60 m hurdles': '60 yards hurdles',
};
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')
        .replace(/^1 mile$/, 'Mile run');
      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++) {
        let yearEvt = evt;
        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 (mark.endsWith('y') && yards[evt]) {
          mark = mark.replace('y', '');
          yearEvt = yards[evt];
        }
        if (winner.includes('\t')) {
          const [name, cnt] = winner.split('\t');
          winner = `{{fla|[[${name}]]|${cnt}}}`;
        } else winner = `[[${winner}]]`;
        if (evt.includes('put') || evt.includes('throw') || evt.includes('jump') || evt.includes('vault')) mark += ' m';
        if (evt.includes('athlon')) mark += ' pts';
        res[yr][gen][yearEvt] = [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]);
// </nowiki>