Last active
May 20, 2024 18:16
-
-
Save devNoiseConsulting/c4779914c77177b974235923f7d2103b to your computer and use it in GitHub Desktop.
Getting live roll stats from Colonist.io
This file contains hidden or 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
// Open up your browser console and enter/paste the following javascript. | |
// It should get the game log, then find all the rolls and give you the stats. | |
// Just enter `displayRolls();` to get the current dice roll stats. | |
let getRolls = function () { | |
return Array.from( | |
Array.from( | |
document.getElementById("game-log-text").childNodes | |
).filter((logText) => logText.textContent.includes("roll")) | |
) | |
.map((logText) => | |
Array.from(logText.getElementsByTagName("img")) | |
.filter((images) => images.alt.includes("dice_")) | |
.map((dieRoll) => dieRoll.alt.substr(5)) | |
.reduce((diceRoll, dieRoll) => { | |
return diceRoll + Number(dieRoll); | |
}, 0) | |
) | |
.reduce( | |
(counts, diceRoll) => { | |
counts[diceRoll]++; | |
return counts; | |
}, | |
{ 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0, 8: 0, 9: 0, 10: 0, 11: 0, 12: 0 } | |
); | |
}; | |
let displayRolls = function () { | |
let counts = getRolls(); | |
Object.keys(counts).forEach((diceRoll) => { | |
console.log( | |
("0" + diceRoll).slice(-2)+`: `+ | |
("0" + counts[diceRoll]).slice(-2)+ | |
Array.apply(null, Array(counts[diceRoll])) | |
.map(() => "+") | |
.join("") | |
); | |
}); | |
}; | |
displayRolls(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment