Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@bellbind
Last active February 17, 2022 02:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bellbind/8ef506a5f267a7b5656cb8e03e528584 to your computer and use it in GitHub Desktop.
Save bellbind/8ef506a5f267a7b5656cb8e03e528584 to your computer and use it in GitHub Desktop.
[deno] print wordle answer of today
void(fetch(document.querySelector("script[src^=main]").src).then(r=>r.text()).then(c=>JSON.parse(c.match(/(\[("[a-z]{5}",)*"[a-z]{5}"\])/)[1])).then(w=>alert(w[((new Date().setHours(0,0,0,0)-new Date("2021-6-19"))/864e5)%w.length])))
<html>
<head>
<title>wordle answer bookmarklet</title>
</head>
<body>
Drag <a style="border: solid transparent; border-radius: 5px; padding: 5px; background-color: gray; color: white;"
href='javascript:void(fetch(document.querySelector("script[src^=main]").src).then(r=>r.text()).then(c=>JSON.parse(c.match(/(\[("[a-z]{5}",)*"[a-z]{5}"\])/)[1])).then(w=>alert(w[((new Date().setHours(0,0,0,0)-new Date("2021-6-19"))/864e5)%w.length])))'
>Wordle answer</a> into your bookmark bar
</body>
</html>
// deno run --allow-net wordle-answer.js
import {JSDOM} from "https://jspm.dev/npm:jsdom-deno";
const url = "https://www.nytimes.com/games/wordle/index.html";
const {document} = new JSDOM(await fetch(url).then(r => r.text()), {url}).window;
const script = document.querySelector("script[src^=main]").src;
const code = await fetch(script).then(r => r.text());
const [solutions, accepts] = [...code.matchAll(/(\[("[a-z]{5}",)*"[a-z]{5}"\])/g)].map(m => JSON.parse(m[1]));
const index = (new Date().setHours(0, 0, 0, 0) - new Date("2021-6-19")) / (24 * 60 * 60 * 1000);
console.log(solutions[index % solutions.length]);
Deno.exit(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment