Jump to content

User:Habst/gbrTable.js

From Wikipedia, the free encyclopedia
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 = 1924;
DATE = { M: 'March 5', W: '' };
CITYSTATE = { M: 'New York City, New York', W: '' };
STATE = { M: 'New York (state)', W: '' };
SPORTSCOMPIN = { M: 'New York City', W: '' };
TANDFIN = { M: 'New York City', W: '' };
PRESTADIUM = { M: 'the ', W: '' };
STADIUM = { M: '[[22nd Regiment Armory]]', W: '' };
EVENTSAT = { M: '', W: '' };
IMG = { M: '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', W: '' };
MONTH = { M: DATE.M.split(' ')[0], W: DATE.W.split(' ')[0] };
makeMWI = (obj, replaceStr = '<X>') => ['M', 'W'].filter(g => obj[g]).map(g => `${replaceStr.replace('<X>', obj[g])} ${obj.W ? `(${g === 'M' ? 'men' : 'women'})` : ''}`.trim()).join('<br>');
makeMWU = (obj, replaceStr = '<X>') => [...new Set(['M', 'W'].filter(g => obj[g]).map(g => replaceStr.replace('<X>', obj[g])))].join('\n');
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 = ${makeMWI(CITYSTATE, '[[<X>]], United States')}
| Dates = ${makeMWI(DATE)}
| Stadium = ${makeMWI(STADIUM)}
| Stadium image = ${IMG.M ? `[[${IMG.M}|200px]]` : ''}${IMG.W ? `[[${IMG.W}|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 organized by the [[Amateur Athletic Union]] (AAU) and served as the [[national championships]] in indoor [[track and field]] for the United States.

The men's championships were held at ${PRESTADIUM.M}${STADIUM.M} in [[${CITYSTATE.M}]], and they took place ${DATE.M}. ${CITYSTATE.W ? `The women's meet was held separately at ${PRESTADIUM.W}${STADIUM.W} in [[${CITYSTATE.W}]], taking place ${DATE.W}` : `Women's championships were not officially held until 1927`}.<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><ref>{{cite web |title=UNITED STATES INDOOR CHAMPIONSHIPS (WOMEN) |url=http://www.gbrathletics.com/nc/usawi.htm |website=GBR Athletics |access-date=9 August 2024}}</ref>

At the championships, 

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

${CITYSTATE.W ? `===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__]]
${makeMWU(MONTH, `[[Category:<X> ${YEAR} sports events in the United States]]`)}
[[Category:__YEAR__ in athletics (track and field)|USA Indoor Track and Field Championships]]
${makeMWU(SPORTSCOMPIN, `[[Category:Sports competitions in <X>]]`)}
${makeMWU(TANDFIN, `[[Category:__YEAR__ in sports in <X>|USA Indoor Track and Field Championships]]`)}
${makeMWU(TANDFIN, `[[Category:Track and field in <X>]]`)}
${makeMWU(EVENTSAT)}}}`;
res = {};
medals = { M: '', W: '' };
hashs = {
  M: {
    '1 mile walk': '1500 m walk',
  },
  W: {},
};
yards = {
  M: {
    '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',
  }
}; yards.W = yards.M;
graves = {
  M: {
    '60 yards hurdles': '70 yards hurdles',
    '60 yards': '75 yards',
  },
  W: {
    '60 m': '50 m',
    '60 m hurdles': '50 m hurdles',
    'Shot put': 'Shot put', // 8 lb
  }
};
graveys = {
  M: {},
  W: {
    '60 m': '50 yards',
    '60 m hurdles': '50 yards hurdles',
  },
};
stars = {
  M: {
    '60 m': '55 m',
    '60 m hurdles': '55 m hurdles',
    'Long jump': 'Standing long jump',
  },
  W: {
    '60 m': '55 m',
    '200 m': '200 yards',
    '60 m hurdles': '55 m hurdles',
    'Long jump': 'Standing long jump',
  },
};
hashys = {
  M: {}, W: { '60 m hurdles': '70 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') && graveys[gen][evt]) {
          mark = mark.replace('†y', ''); yearEvt = graveys[gen][evt];
        } else if (mark.endsWith('#y') && hashys[gen][evt]) {
          mark = mark.replace('#y', ''); yearEvt = hashys[gen][evt];
        } else if (mark.endsWith('y') && yards[gen][evt]) {
          mark = mark.replace('y', ''); yearEvt = yards[gen][evt];
        } else if (mark.endsWith('†') && graves[gen][evt]) {
          mark = mark.replace('†', ''); yearEvt = graves[gen][evt];
        } else if (mark.endsWith('*') && stars[gen][evt]) {
          mark = mark.replace('*', ''); yearEvt = stars[gen][evt];
        } else if (mark.endsWith('#') && hashs[gen][evt]) {
          mark = mark.replace('#', ''); yearEvt = hashs[gen][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} ${womenEvts ? `(${menEvts} men's + ${womenEvts} women's)` : ''}`.trim();
art.replaceAll('__YEAR__', YEAR).replaceAll('__PREV__', YEAR - 1).replaceAll('__NEXT__', YEAR + 1).replaceAll('__MTBL__', medals.M).replaceAll('__WTBL__', medals.W).replaceAll('__EVTS__', numEvts);
// </nowiki>