User:Habst/getNCAAWinners.js

isFemale = new URLSearchParams(location.search).get('gender') === '2'; evt = document.querySelector(`option[value="${document.querySelector('select').value}"]`).innerText; isRelay = evt.includes('Relay'); teams = { Alabama: 'Alabama Crimson Tide', LSU: isFemale ? 'LSU Lady Tigers' : 'LSU Tigers', Texas: 'Texas Longhorns', Houston: 'Houston Cougars', 'Indiana State': 'Indiana State Sycamores', Georgia: 'Georgia Bulldogs', 'South Carolina': 'South Carolina Gamecocks', Clemson: 'Clemson Tigers', Arkansas: 'Arkansas Razorbacks', 'Texas Southern': 'Texas Southern Tigers', Auburn: 'Auburn Tigers', 'Miami (Fla.)': 'Miami Hurricanes', Kentucky: 'Kentucky Wildcats', Florida: 'Florida Gators', Tennessee: 'Tennessee Volunteers', Oregon: 'Oregon Ducks', Harvard: 'Harvard Crimson', 'North Carolina A&T': 'North Carolina A&T Aggies', 'Ohio State': 'Ohio State Buckeyes', Arizona: 'Arizona Wildcats', 'George Mason': 'George Mason Patriots', Missouri: 'Missouri Tigers', Nebraska: 'Nebraska Cornhuskers', 'Seton Hall': 'Seton Hall Pirates', 'North Carolina': 'North Carolina Tar Heels', Manhattan: 'Manhattan Jaspers', Rice: 'Rice Owls', Iowa: 'Iowa Hawkeyes', Hampton: 'Hampton Pirates', 'Texas A&M': 'Texas A&M Aggies', Kansas: 'Kansas Jayhawks', 'Southern California': 'USC Trojans', 'Arizona State': 'Arizona State Sun Devils', Villanova: 'Villanova Wildcats', Indiana: 'Indiana Hoosiers', 'Iowa State': 'Iowa State Cyclones', 'Eastern Michigan': 'Eastern Michigan Eagles', Wisconsin: 'Wisconsin Badgers', 'Little Rock': 'Little Rock Trojans', Pittsburgh: 'Pittsburgh Panthers', UTEP: 'UTEP Miners', UCLA: 'UCLA Bruins', Minnesota: 'Minnesota Golden Gophers', California: 'California Golden Bears', BYU: 'BYU Cougars', 'Penn State': 'Penn State Nittany Lions', Baylor: 'Baylor Bears', 'Virginia Tech': 'Virginia Tech Hokies', Stanford: 'Stanford Cardinal', 'Grambling State': 'Grambling State Tigers', UNLV: 'UNLV Rebels', 'Boston University': 'Boston University Terriers', Providence: 'Providence Friars', Georgetown: 'Georgetown Hoyas', 'West Virginia': 'West Virginia Mountaineers', Liberty: isFemale ? 'Liberty Lady Flames': 'Liberty Flames', 'Northern Arizona': 'Northern Arizona Lumberjacks', 'Mississippi State': 'Mississippi State Bulldogs', Duke: 'Duke Blue Devils', 'Florida State': 'Florida State Seminoles', 'Stony Brook': 'Stony Brook Seawolves', Colorado: 'Colorado Buffaloes', 'Michigan State': 'Michigan State Spartans', 'Oklahoma State': isFemale ? 'Oklahoma State Cowgirls' : 'Oklahoma State Cowboys', Samford: 'Samford Bulldogs', 'New Hampshire': 'New Hampshire Wildcats', Illinois: 'Illinois Fighting Illini', 'Washington State': 'Washington State Cougars', Oklahoma: 'Oklahoma Sooners', Michigan: 'Michigan Wolverines', 'Boston College': 'Boston College Eagles', 'Texas Tech': 'Texas Tech Red Raiders', Dartmouth: 'Dartmouth Big Green', 'Notre Dame': 'Notre Dame Fighting Irish', 'NC State': 'NC State Wolfpack', 'Bowling Green': 'Bowling Green Falcons', 'Western Kentucky': isFemale ? 'Western Kentucky Lady Toppers' : 'Western Kentucky Hilltoppers', Brown: 'Brown Bears', Montana: isFemale ? 'Montana Lady Griz' : 'Montana Grizzlies', 'South Alabama': 'South Alabama Jaguars', 'Fairleigh Dickinson': 'Fairleigh Dickinson Knights', 'Western Colorado': 'Western Colorado Mountaineers', 'Texas A&M-Corpus Christi': 'Texas A&M–Corpus Christi Islanders', Iona: 'Iona Gaels', Syracuse: 'Syracuse Orange', 'Georgia Tech': 'Georgia Tech Yellow Jackets', 'Arkansas State': 'Arkansas State Red Wolves', 'Ole Miss': 'Ole Miss Rebels', 'Bethune-Cookman': 'Bethune–Cookman Wildcats', 'Morgan State': isFemale ? 'Morgan State Lady Bears' : 'Morgan State Bears', Adelphi: 'Adelphi Panthers', SMU: 'SMU Mustangs', TCU: 'TCU Horned Frogs', 'Kansas State': 'Kansas State Wildcats', Fordham: 'Fordham Rams', Princeton: 'Princeton Tigers', 'New Mexico': 'New Mexico Lobos', Rutgers: 'Rutgers Scarlet Knights', Richmond: 'Richmond Spiders', Washington: 'Washington Huskies', 'Boise State': 'Boise State Broncos', 'Southern Miss': 'Southern Miss Golden Eagles', 'Northwestern State': isFemale ? 'Northwestern State Lady Demons' : 'Northwestern State Demons', Maryland: 'Maryland Terrapins', 'Cal State LA': 'Cal State Los Angeles Golden Eagles', Toledo: 'Toledo Rockets', Ohio: 'Ohio Bobcats', 'Mississippi College': 'Mississippi College Choctaws', 'UT Arlington': 'UT Arlington Mavericks', 'Jackson State': 'Jackson State Tigers', ULM: 'Louisiana–Monroe Warhawks', Southern: isFemale ? 'Southern Lady Jaguars' : 'Southern Jaguars', Louisville: 'Louisville Cardinals', CSUN: 'Cal State Northridge Matadors', 'Weber State': 'Weber State Wildcats', Nevada: 'Nevada Wolf Pack', 'Miami (Ohio)': 'Miami RedHawks', 'Oregon State': 'Oregon State Beavers', 'Colgate': 'Colgate Raiders', 'Long Beach State': 'Long Beach State Beach', Navy: 'Navy Midshipmen', Louisiana: 'Louisiana Ragin\' Cajuns', 'McNeese State': isFemale ? 'McNeese State Cowgirls' : 'McNeese State Cowboys', 'South Florida': 'South Florida Bulls', 'Fresno State': 'Fresno State Bulldogs', 'Montana State': 'Montana State Bobcats', 'Purdue': 'Purdue Boilermakers', 'San Jose State': 'San Jose State Spartans', 'Northern Iowa': 'Northern Iowa Panthers', 'Binghamton': 'Binghamton Bearcats', 'Akron': 'Akron Zips', 'South Dakota': 'South Dakota Coyotes', 'Southern Illinois': 'Southern Illinois Salukis', 'Hawai\'i': isFemale ? 'Hawaii Rainbow Wahine' : 'Hawaii Rainbow Warriors', 'Central Michigan': 'Central Michigan Chippewas', 'Colorado State': 'Colorado State Rams', 'North Dakota State': 'North Dakota State Bison', ETSU: 'East Tennessee State Buccaneers', UMBC: 'UMBC Retrievers', 'UC Riverside': 'UC Riverside Highlanders', Cincinnati: 'Cincinnati Bearcats', Connecticut: 'UConn Huskies', 'Rhode Island': 'Rhode Island Rams', 'Kent State': 'Kent State Golden Flashes', Wyoming: isFemale ? 'Wyoming Cowgirls' : 'Wyoming Cowboys', 'Southeastern Louisiana': isFemale ? 'Southeastern Louisiana Lady Lions' : 'Southeastern Louisiana Lions', 'Kennesaw State': 'Kennesaw State Owls', } out = ''; fmtName = (nameText, splitCol = false) => { let split = ''; const result = (nameText?.split(' ') ?? []).flatMap(n => {   if (n.startsWith('(')) return []; if (n.match(/^[0-9.]+$/)) { split = n; return []; } if (n === n.toUpperCase) return n.split('-').map(word => word[0] + word.slice(1).toLowerCase).join('-'); return n; }).join(' ');  return `${result}${splitCol ? ` || ${split}` : ''}`; }; [...document.querySelectorAll('table.ui')].toReversed.forEach(t => { const yr = t.querySelector('tbody td').innerText?.split(' ')[0]; if (!yr) return; const athletes = t.querySelectorAll('td[colspan="6"] tbody tr'); const winners = [...athletes].filter(a => a.querySelector('td').innerText.startsWith('(1)')); out += winners.length > 1 ? `|rowspan=${winners.length}| ` : isRelay ? `|rowspan=4| ` : `| `; out += `${yr} || `; for (let i = 0; i < winners.length; i++) { const winner = winners[i]; const [nameTd, _, team, markTd] = winner.querySelectorAll('td'); const nameText = nameTd.querySelector('span').innerText.split(') ')[1];   const teamText = isRelay ? nameText : team.innerText;    if (!teams[teamText]) console.log(`Missing ${teamText}`);    let names = isRelay ? winner.nextSibling?.querySelector('td').innerText.trim.split(', ').map(n => fmtName(n, true)) ?? [...Array(4)].fill(' ||') : [fmtName(nameText)];    const mark = markTd.querySelector('a')?.innerText ?? markTd.innerText;    const abbrs = [...markTd.querySelectorAll('.tooltip')].map(tt => tt.firstChild.textContent);    if (i) out += '\n| ';    const span = isRelay ? 'rowspan=4' : ;    out += `${names[0]} ||${span}  ||${span ? span + '|' : } ${mark}${abbrs.map(a => ` `).join()}${names.length ? '\n|-\n' : }${names.slice(1).map(n => `| ${n}`).join('\n|-\n')}`;    out += '\n|-\n';  } }); console.log(out.replaceAll(`|-\n\n|-`, '|-'));