Last active
November 17, 2024 00:59
-
-
Save ahuggins/cd7d0dd4e59abc815e96e0bb8d0de640 to your computer and use it in GitHub Desktop.
ESPN.com Game Focus Console command
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This console script allows you to set the `gamesInterestedIn` to be games you want to keep tabs on. | |
// Just need one team in the game you are interested in (like you don't need both teams listed). | |
// Then run the whole script, and the games you are not interested in will be filtered away. | |
// It sets divs to be style "display: none" because if the elements are removed, when ESPN updates | |
// something and the node is removed, it throws an error. Styling them to display none, means the node | |
// is still there, and it can do its thing. | |
// Some definitions for easier reading | |
const gameIds = new Set; | |
const q = (selector) => document.querySelectorAll(selector); | |
const getParent = (el) => el.closest('section').closest('div').closest('section'); | |
const getParentId = (el) => getParent(el).getAttribute('id'); | |
const setDisplayNone = (els) => els.forEach(el => el.style.display = 'none'); | |
// The main part, take the names of teams we want to see... get the gameId from the .Scoreboard node. | |
// adds ids to gameIds Set | |
const gamesInterestedIn = [ | |
"Kentucky", | |
"Alabama", | |
"Georgia", | |
"Rutgers", | |
"West Virginia", | |
"Tulane", | |
"Illinois", | |
"Arkansas State", | |
"Oregon State", | |
"James Madison", | |
"LSU", | |
"BYU", | |
].forEach(name => { | |
const el = [...q(".Card .ScoreCell__TeamName")] | |
.find(el => el.textContent == name); | |
gameIds.add(getParentId(el)); | |
}) | |
// Hide other sections of site | |
const classesToHide = [ | |
{ | |
class: '.Scoreboard', | |
forEach: (els) => els.forEach(game => { | |
if(!gameIds.has(game.getAttribute('id'))) { | |
setDisplayNone([game]); | |
} | |
}) | |
}, | |
'.gameModules:not(:first-child)', | |
'.pageContent > div:first-child', | |
'.PageLayout__RightAside', | |
'.Scoreboard__Header', | |
'.Ad--banner', | |
'.sponsored-content', | |
'.HeaderScoreboardWrapper', | |
'.page-footer-container', | |
'.Site__Header__Wrapper', | |
'.Scoreboard__Callouts', | |
'.Scoreboard__Column--3' | |
].forEach(cls => { | |
if(typeof cls === 'string') { | |
setDisplayNone(q(cls)) | |
} else { | |
cls.forEach(q(cls.class)); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment