Last active
March 11, 2022 15:34
-
-
Save helgridly/8c8b39de93bf6b68d9516d53b8d4fb7d to your computer and use it in GitHub Desktop.
Wordle Average Score
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
// ==UserScript== | |
// @name Wordle Average Stats | |
// @namespace helgridly | |
// @version 0.1 | |
// @description Adds an average score to the statistics modal | |
// @author helgridly | |
// @match https://www.nytimes.com/games/wordle/* | |
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
function add_avg_score() { | |
var statsbox = document.querySelector('game-app').shadowRoot.querySelector('game-stats').shadowRoot.querySelector('#statistics'); | |
var avgScore = "?"; | |
if(localStorage['nyt-wordle-statistics']) { | |
var stats = JSON.parse(localStorage['nyt-wordle-statistics']); | |
var guesses = stats['guesses']; | |
var total = Object.keys(guesses).reduce(function (total, key) { return (isNaN(key) ? total : total + parseInt(key) * guesses[key]); }, 0); | |
avgScore = (total / stats['gamesWon']).toFixed(2); | |
} | |
var newNode = statsbox.children[0].cloneNode(true); | |
newNode.children[0].textContent = avgScore; | |
newNode.children[1].textContent = "Avg. Score"; | |
statsbox.appendChild(newNode); | |
} | |
var old_modal = document.querySelector('game-app').showStatsModal.bind(document.querySelector('game-app')); | |
document.querySelector('game-app').showStatsModal = function() { | |
old_modal(); | |
add_avg_score(); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment