team-big/main.js

41 lines
1.2 KiB
JavaScript
Raw Normal View History

2021-03-28 03:08:20 +00:00
var 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() {
var teams = JSON.parse(this.response)
var totals = teams.map(team => team.lineup.length + team.rotation.length)
// Get all player counts that there are from greatest to least
2021-03-28 03:42:29 +00:00
var playercounts = totals.slice().sort(function (x, y) {
return y - x
}).filter(function (item, pos, array) {
return !pos || item != array[pos - 1]
})
2021-03-28 03:08:20 +00:00
// Now make headers & lists for all the player counts
playercounts.forEach(function(item) {
2021-03-28 03:42:29 +00:00
document.body.insertAdjacentHTML("beforeend",
"<h1>"
+ item
+ " players</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",
"<li>"
+ item.fullName
+ " ("
+ item.lineup.length
+ " hitters, "
+ item.rotation.length
+ " pitchers)</li>")
2021-03-28 03:08:20 +00:00
})
document.getElementById("progress").remove()
2021-03-28 03:08:20 +00:00
}