team-big/main.js

32 lines
1.2 KiB
JavaScript
Raw Normal View History

2021-03-29 01:39:47 +00:00
let request = new XMLHttpRequest()
2021-03-28 03:42:29 +00:00
request.open(
"GET",
"https://cors-proxy.blaseball-reference.com/database/allTeams",
true)
2021-03-28 03:08:20 +00:00
request.send();
request.onload = function() {
2021-04-01 01:21:15 +00:00
let ending = x => (Math.abs(x) === 1 ? "" : "s")
2021-03-29 01:39:47 +00:00
let teams = JSON.parse(this.response)
let totals = teams.map(team => team.lineup.length + team.rotation.length)
2021-03-28 03:08:20 +00:00
// Get all player counts that there are from greatest to least
2021-03-29 01:39:47 +00:00
// & make headers & lists for them
2021-04-05 18:36:04 +00:00
totals.slice().sort((x, y) => x - y)
2021-04-01 01:21:15 +00:00
.filter((item, pos, array) => !pos || item !== array[pos - 1])
2021-03-29 01:39:47 +00:00
.forEach(function(item) {
2021-04-05 18:36:04 +00:00
document.body.insertAdjacentHTML("afterbegin",
2021-04-01 01:21:15 +00:00
`<h1>${item} player${ending(item)}</h1>
<ul id="tlist${item}"></ul>`)
2021-03-28 03:08:20 +00:00
})
// Put the teams in the lists
teams.forEach(function(item, pos) {
2021-03-28 03:42:29 +00:00
document.getElementById("tlist" + totals[pos]).insertAdjacentHTML("beforeend",
2021-03-29 01:39:47 +00:00
`<li>${item.fullName}
2021-04-01 01:21:15 +00:00
(${item.lineup.length} hitter${ending(item.lineup.length)},
${item.rotation.length} pitcher${ending(item.rotation.length)})</li>`)
2021-03-28 03:08:20 +00:00
})
document.getElementById("progress").remove()
2021-03-28 03:08:20 +00:00
}