Skip to content

Instantly share code, notes, and snippets.

@devNoiseConsulting
Last active May 20, 2024 18:16
Show Gist options
  • Save devNoiseConsulting/c4779914c77177b974235923f7d2103b to your computer and use it in GitHub Desktop.
Save devNoiseConsulting/c4779914c77177b974235923f7d2103b to your computer and use it in GitHub Desktop.
Getting live roll stats from Colonist.io
// 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