Last active
December 7, 2021 00:44
-
-
Save pjflanagan/2e26950aa7a532171752116563ec705b to your computer and use it in GitHub Desktop.
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
var script = document.createElement('script'); script.src = "https://code.jquery.com/jquery-3.4.1.min.js"; document.getElementsByTagName('head')[0].appendChild(script); | |
// wait for script to load, then add and run the rest in console | |
function setWinnerAndMakeGame(gameElem) { | |
// get the teams | |
const teams = []; | |
$(gameElem).find('.DenseOutcome-content').each((_i, teamElem) => { | |
teams.push({ | |
name: $(teamElem).find('.DenseOutcome-title').text(), | |
percent: parseFloat($(teamElem).find('.DenseOutcome-metadata').last().text()), | |
teamElem | |
}); | |
}); | |
// pick the winning team | |
let winningTeam; | |
if (teams[0].percent > teams[1].percent) { | |
winningTeam = teams[0]; | |
} else { | |
winningTeam = teams[1]; | |
} | |
// click the team and return the data | |
$(winningTeam.teamElem).click(); | |
return { | |
winner: winningTeam.name, | |
percent: winningTeam.percent, | |
gameElem | |
} | |
} | |
function setWinnersAndMakeGamesArray() { | |
const games = []; | |
// for each game | |
$('.ConfidenceProposition').each((_i, gameElem) => { | |
// select the winner and | |
// add the data to the array | |
const game = setWinnerAndMakeGame(gameElem); | |
games.push(game); | |
}); | |
return games; | |
} | |
function setRanks(games) { | |
// sort in order of percent and add rank | |
const gameRanks = games | |
.sort((a, b) => { | |
return b.percent - a.percent; | |
}).map((v, i) => { | |
v.rank = games.length - i; | |
return v; | |
}); | |
gameRanks.forEach((game) => { | |
$(game.gameElem) | |
.find('.ConfidenceValue-button') | |
.click(() => { | |
// in the popup, find the row with game.rank, click "Move here" button | |
$(`.ChuiModal-content .ConfidenceItem-points:contains(${game.rank})`) | |
.parent() | |
.find('.ConfidenceItem-button') | |
.click(); | |
}); | |
}); | |
// output | |
console.table(gameRanks); | |
} | |
// select the winners and add to an array | |
const games = setWinnersAndMakeGamesArray(); | |
setRanks(games); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment