Change formatting

This commit is contained in:
Lavender 2021-03-27 20:42:29 -07:00
parent 8cba1e3a3c
commit 3932f996dc
Signed by untrusted user: endie
GPG key ID: CC5162D7C2146F01

45
main.js
View file

@ -1,38 +1,39 @@
var request = new XMLHttpRequest() var request = new XMLHttpRequest()
request.open("GET", "https://cors-proxy.blaseball-reference.com/database/allTeams", true) request.open(
"GET",
"https://cors-proxy.blaseball-reference.com/database/allTeams",
true)
request.send(); request.send();
request.onload = function() { request.onload = function() {
var teams = JSON.parse(this.response) var teams = JSON.parse(this.response)
var totals = teams.map(team => team.lineup.length + team.rotation.length) var totals = teams.map(team => team.lineup.length + team.rotation.length)
// Get all player counts that there are from greatest to least // Get all player counts that there are from greatest to least
var playercounts = totals.slice().sort( var playercounts = totals.slice().sort(function (x, y) {
function (x, y) { return y - x
return y - x }).filter(function (item, pos, array) {
} return !pos || item != array[pos - 1]
).filter( })
function (item, pos, array) {
return !pos || item != array[pos - 1]
}
)
// Now make headers & lists for all the player counts // Now make headers & lists for all the player counts
playercounts.forEach(function(item) { playercounts.forEach(function(item) {
document.body.insertAdjacentHTML("beforeend", "<h1>" document.body.insertAdjacentHTML("beforeend",
+ item "<h1>"
+ " players</h1><ul id='tlist" + item
+ item + " players</h1><ul id='tlist"
+ "'></ul>") + item
+ "'></ul>")
}) })
// Put the teams in the lists // Put the teams in the lists
teams.forEach(function(item, pos) { teams.forEach(function(item, pos) {
document.getElementById("tlist" + totals[pos]).insertAdjacentHTML("beforeend", "<li>" document.getElementById("tlist" + totals[pos]).insertAdjacentHTML("beforeend",
+ item.fullName "<li>"
+ " (" + item.fullName
+ item.lineup.length + " ("
+ " hitters, " + item.lineup.length
+ item.rotation.length + " hitters, "
+ " pitchers)</li>") + item.rotation.length
+ " pitchers)</li>")
}) })
document.getElementById("progress").remove() document.getElementById("progress").remove()