Visualize Your League
This is Part 3 of my series on Fantasy Basketball.
In order to pick up roster updates, you must follow the original import instructions (just go to main fantasy basketball page and click on the link to this page to see them again).
Important: Github broke my original implementation, you will likely need to rerun the import script for this page to work again
This page allows you to see some stats about your league and compare teams. Follow the instructions below to import your data. The bottom of the page right now has a preview of what you can expect to see.
Instructions to Generate For Your League (ESPN only)
To import your league data, you need to run a script on the league roster page. It is a quick process (although it might be a bit intimidating the first time).
That script will generate a link to this page containing the rosters of your league, allowing the page to render the data.
Instructions for running the script in Chrome are below. It should work in other browsers as well, but you're on your own instruction wise!
To do so you need to navigate to the league rosters page on ESPN (the URL should look like https://fantasy.espn.com/basketball/league/rosters?leagueId=1234
)
Once you're there, open up the Chrome web console by right clicking somewhere on the page and selecting "Inspect". Then in the top right (you may need to expand the pane that opens) click "Console".
Copy and paste the script below into the console, and then hit enter.
let teamTables = document.getElementsByClassName('ResponsiveTable')
let playerTeams = {}
for (let teamTable of teamTables) {
let teamName = teamTable.firstElementChild.firstElementChild.firstElementChild.children[1].textContent
let playerTable = teamTable.children[1].firstElementChild.children[1].firstElementChild.children[4]
for (let player of playerTable.children) {
if (player.children[1].firstElementChild.firstElementChild.children.length < 2) continue;
if (player.firstElementChild.firstElementChild.textContent == "IR") continue;
let playerName = player.children[1].firstElementChild.firstElementChild.children[1].firstElementChild.firstElementChild.firstElementChild.textContent
if (!(teamName in playerTeams)) {
playerTeams[teamName] = []
}
playerTeams[teamName].push(playerName)
}
}
let zachSite = 'https://www.zachsab.in/fantasy_basketball/your_league'
let linkUrl = `${zachSite}?${new URLSearchParams(playerTeams)}`
let body = document.getElementsByTagName('body')[0]
body.removeChild(body.firstChild)
let link = document.createElement('a')
link.setAttribute('href', linkUrl)
link.textContent = 'CLICK HERE'
body.appendChild(link)
Click the link that appears in the top left!
The charts below allow you to compare stats across your league, or compare two teams head to head.
In the head to head chart, the stats are displayed relative to the best team in your league.
So if your team averages the most steals, then your "STL" bar will be 1.0. Note that all stats use
per game averages, and does not account for how many games players sit out etc...
Sharing
You can simply send the URL of this page to other members of your league if you want to share it with them.
I'd recommend using a URL shortener as the links to this page can be quite long (you can use the TinyURL embed below).