Readme

wordGame

A wordgame inspired by TextTwist. Custom games can be created by appending the available letters to the url.

https://jdan-esmtown.web.val.run/nsetyr

image.png

The dictionary is populated from the following script:

import { blob } from "https://esm.town/v/std/blob?v=12"; const dictionaryUrls = [ "https://www.freescrabbledictionary.com/word-lists/3-letter-words/3-letter-words.json", "https://www.freescrabbledictionary.com/word-lists/4-letter-words/4-letter-words.json", "https://www.freescrabbledictionary.com/word-lists/5-letter-words/5-letter-words.json", "https://www.freescrabbledictionary.com/word-lists/6-letter-words/6-letter-words.json", "https://www.freescrabbledictionary.com/word-lists/7-letter-words/7-letter-words.json", ]; const allWords = await Promise.all( dictionaryUrls.map(async (url) => { const res = await fetch(url); const words = await res.json(); return words.map((entry) => entry.word); }), ); blob.setJSON("words", allWords.flat());
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/** @jsxImportSource npm:hono@3/jsx */
import { wordsMatching } from "https://esm.town/v/jdan/wordsMatching";
import { Hono } from "npm:hono@3";
function esmTown(url) {
return fetch(url, {
headers: {
"User-Agent":
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.142.86 Safari/537.36",
},
}).then(r => r.text());
}
const app = new Hono();
export default app.fetch;
app.get("/", async (c) => {
// redirect to /example
return c.redirect("/example");
});
app.get("/:letters", async (c) => {
const letters = c.req.param("letters");
const matchingWords = await wordsMatching(letters);
return c.html(
<html>
<head>
<title>{letters.toUpperCase()}</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<style
dangerouslySetInnerHTML={{
__html: `
ul {
display: flex;
flex-flow: wrap column;
max-height: 150px; /* Limit height to whatever you need */
}`,
}}
/>
</head>
<body>
<div>
Find all the words using the letters: {letters.toUpperCase()}
</div>
<div id="state"></div>
<form id="form">
<input type="text" id="input" style={{ textTransform: "uppercase" }} /> <button type="submit">Submit</button>
</form>
<div id="progress"></div>
<button id="copy-button">Share</button>
<br />
<br />
<a href="https://www.val.town/v/jdan/esmTown">Fork on val.town</a>
<script
dangerouslySetInnerHTML={{
__html: `
// You are an elite hacker!
// Protip: https://www.nytimes.com/puzzles/spelling-bee has a window.gameData as well
window.letters = ${JSON.stringify(letters)};
window.words = ${JSON.stringify(matchingWords)};
`,
}}
type="module"
/>
<script
dangerouslySetInnerHTML={{
__html: await esmTown("https://esm.town/v/jdan/gameScript"),
}}
type="module"
/>
</body>
</html>,
);
});
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
jdan-esmtown.web.val.run
v32
May 19, 2024