sethmlarson/sethmlarson.dev

Wordle current streak

asasine opened this issue · 4 comments

Your blog mentions you were looking for a way to set the nyt-wordle-state.lastPlayedTs field but I think that's a red herring.

The current streak seems to derive exclusively from the nyt-wordle-statistics.currentStreak field. Overriding this field and refreshing the wordle page causes the streak to update in the website, and this increments as expected if you solve the wordle for the current day or on subsequent days.

I did some more poking around and it seems like nyt-wordle-statistics.currentStreak is overwritten if nyt-wordle-state.lastPlayedTs is unset when a game is completed, resetting the streak to 1 :(

This is workable though, but it's somewhat manual and tedious. By first playing a game on the device one wishes to import data to, the wordle website will set lastPlayedTs for you. If you then load a URL with a query string that includes statistics.currentStreak set to any value, the wordle website will use the currentStreak from the import tool. After that point, the imported streak is remembered on subsequent days.

I verified this with these exact steps:

  1. Open https://www.nytimes.com/games/wordle/index.html in a private browsing window
    1. I tested with private browsing to not muck up my real wordle data. In a real scenario, you would use a normal tab so the local storage is persisted across browser sessions.
  2. Answer the current day's wordle
    1. At this point, your streak should be 1
  3. In the same window, go to https://www.nytimes.com/games/wordle?data={{%22time%22:1648905500,%22statistics%22:{{%22currentStreak%22:42,%22maxStreak%22:42,%22guesses%22:{{%221%22:42,%222%22:0,%223%22:0,%224%22:0,%225%22:0,%226%22:0,%22fail%22:0}},%22gamesPlayed%22:42,%22gamesWon%22:42,%22averageGuesses%22:1,%22winPercentage%22:100}},%22darkTheme%22:false,%22colorBlindTheme%22:null}}
    1. Note: the 1648905500 needs to be updated to a unix timestamp roughly 5 minutes in the past or less. python3 -c 'import time; print(int(time.time() - 5 * 60))' to get one quickly.
    2. At this point, your streak should be 42
  4. Go to your computer's settings and change the date to the next day
  5. Refresh the wordle website
  6. Answer the next day's wordle
    1. At this point, your streak should be 43
  7. Go to your computer's settings and change the date back to the current day
yfhui commented

I just got a new device and want to move the wordle stats as well. After some research and found that Wordle is heavily relying on localStorage. All the stats and player setting is actually saved in localStorage with the key nyt-wordle-* (but I didn't dig deep to check if Wordle stats is solely relying on localStorage)

So the cloning of data can be done by simply copying localStorage item in the old device one by one to the new device console. (by running window.localStorage.setItem("nyt-wordle-*", ...)) in the new device) If you are updating to a phone, you need to use usb debugging tool to help access the console of the tab

I would suggest this wordle import tool can migrate to the localStorage way to cloning wordle stat...

Also I could confirm that @asasine finding is correct. If you check the source code, the tutorial it pops (game-help) when you play for the first time is actually depends on the lastPlayedTs

You can see the following snipper of the main.js:

key: "showHelpModal",
value: function() {
    var e = this.$game.querySelector("game-modal");
    e.appendChild(document.createElement("game-help")),
    e.setAttribute("open", "")
}
...
this.lastPlayedTs || setTimeout((function() {
        return c.showHelpModal()
}

I hope my findings can help improving the tool!

I really love all this analysis and I also believe the only way to fix the "Current Streak" functionality is to use localStorage likely through copy-pasted JavaScript into the console. Unfortunately I think my tool will continue to use the current method instead of this more complete method if only because I don't have time to work on it myself.

I suggest creating a tool which accomplishes this yourselves and I'll gladly link to it in my article, thanks for the interest! Going to close this issue for now.

For users on iOS, I figured out how to import current streak using custom JavaScript and a Shortcut.

Here's the shortcut: https://www.icloud.com/shortcuts/2a6f602af04b4256a52805daade409a3

The JS:

let statistics = JSON.parse(localStorage.getItem('nyt-wordle-statistics'));
statistics.currentStreak = /* provided input */;
localStorage.setItem('nyt-wordle-statistics', JSON.stringify(statistics));

completion(statistics);

I ran this shortcut after solving the Wordle for the day. The shortcut asks for your current streak, which I set to one plus whatever my streak was on my old device.

More info on custom JavaScript via Shortcuts: https://support.apple.com/guide/shortcuts/use-the-run-javascript-on-webpage-action-apdb71a01d93/ios