Skip to content

Instantly share code, notes, and snippets.

@DenverCoder1
Created April 28, 2022 20:39
Show Gist options
  • Save DenverCoder1/1ed28947e283566eaecb6518f77aba2c to your computer and use it in GitHub Desktop.
Save DenverCoder1/1ed28947e283566eaecb6518f77aba2c to your computer and use it in GitHub Desktop.
Script to manually update Wordle stats
/**
* Script to manually update Wordle stats
*
* This can be useful for overriding stats if you want to transfer stats from
* another device, or you simply want to set your stats manually.
*
* @author Jonah Lawrence
* @version 1.0
* @license MIT
*
* Copyright 2022 Jonah Lawrence
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
* is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
function updateStats(currentStreak, maxStreak, guesses) {
const stats = JSON.parse(localStorage.getItem("nyt-wordle-statistics"));
stats.currentStreak = currentStreak;
stats.maxStreak = maxStreak;
stats.guesses = guesses;
stats.gamesPlayed = Object.values(stats.guesses).reduce((a, b) => a + b, 0);
stats.gamesWon = stats.gamesPlayed - stats.guesses.fail;
stats.winPercentage = stats.gamesPlayed > 0 ? Math.round((stats.gamesWon / stats.gamesPlayed) * 100) : 0;
const weightedSum = Object.entries(stats.guesses).reduce((a, b) => a + (parseInt(b[0]) || 0) * b[1], 0);
stats.averageGuesses = Math.round(weightedSum / stats.gamesWon);
localStorage.setItem("nyt-wordle-statistics", JSON.stringify(stats));
console.info("Updated stats: ", stats);
}
// Fill in the values for currentStreak, maxStreak, and guesses
updateStats(1, 10, { 1: 0, 2: 5, 3: 17, 4: 16, 5: 7, 6: 2, fail: 1 });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment