-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
482 lines (441 loc) · 14 KB
/
index.html
File metadata and controls
482 lines (441 loc) · 14 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>Operadle</title>
<style>
:root{
--bg:#0b0f14;
--panel:#101826;
--text:#e8eef7;
--muted:#a8b3c7;
--tile:#162235;
--tile-border:#2a3952;
--absent:#3a475f;
--present:#b38f2a;
--correct:#1f8a60;
--key:#1a263a;
--key-border:#2a3952;
--focus:#7aa7ff;
}
*{box-sizing:border-box}
body{
margin:0;
font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial, "Apple Color Emoji","Segoe UI Emoji";
background: radial-gradient(1200px 800px at 20% 10%, #14304a 0%, var(--bg) 55%);
color:var(--text);
min-height:100vh;
display:flex;
align-items:center;
justify-content:center;
padding:18px;
}
.app{
width:min(520px, 100%);
background: rgba(16,24,38,0.78);
border:1px solid rgba(42,57,82,0.65);
border-radius:18px;
box-shadow: 0 18px 60px rgba(0,0,0,0.35);
padding:18px 18px 14px;
backdrop-filter: blur(10px);
}
header{
display:flex;
gap:12px;
align-items:flex-start;
justify-content:space-between;
margin-bottom:12px;
}
h1{
margin:0;
font-size:22px;
letter-spacing:0.4px;
}
.sub{
margin-top:4px;
font-size:13px;
color:var(--muted);
line-height:1.35;
}
.actions{
display:flex;
gap:8px;
align-items:center;
}
button{
border:1px solid rgba(42,57,82,0.9);
background: rgba(26,38,58,0.8);
color:var(--text);
border-radius:12px;
padding:9px 12px;
font-weight:600;
cursor:pointer;
}
button:hover{ filter:brightness(1.06); }
button:active{ transform: translateY(1px); }
.board{
display:grid;
grid-template-rows: repeat(6, 1fr);
gap:10px;
padding:10px 6px 14px;
}
.row{
display:grid;
grid-template-columns: repeat(5, 1fr);
gap:10px;
}
.tile{
height:56px;
border-radius:14px;
background:rgba(22,34,53,0.75);
border:1px solid rgba(42,57,82,0.85);
display:flex;
align-items:center;
justify-content:center;
font-size:22px;
font-weight:800;
letter-spacing:1.5px;
text-transform:uppercase;
user-select:none;
}
.tile.filled{
border-color: rgba(122,167,255,0.55);
box-shadow: 0 0 0 2px rgba(122,167,255,0.08) inset;
}
.tile.absent{ background: rgba(58,71,95,0.75); border-color: rgba(58,71,95,0.95); }
.tile.present{ background: rgba(179,143,42,0.75); border-color: rgba(179,143,42,0.95); }
.tile.correct{ background: rgba(31,138,96,0.75); border-color: rgba(31,138,96,0.95); }
.keyboard{
display:grid;
gap:8px;
padding:6px;
}
.keyrow{
display:flex;
gap:8px;
justify-content:center;
flex-wrap:nowrap;
}
.key{
min-width:34px;
height:46px;
padding:0 10px;
border-radius:12px;
border:1px solid rgba(42,57,82,0.95);
background: rgba(26,38,58,0.75);
color:var(--text);
font-weight:800;
letter-spacing:0.8px;
text-transform:uppercase;
cursor:pointer;
user-select:none;
}
.key.wide{ min-width:74px; font-size:12px; }
.key.absent{ background: rgba(58,71,95,0.85); border-color: rgba(58,71,95,1); }
.key.present{ background: rgba(179,143,42,0.85); border-color: rgba(179,143,42,1); }
.key.correct{ background: rgba(31,138,96,0.85); border-color: rgba(31,138,96,1); }
.status{
margin:10px 6px 4px;
min-height:22px;
color:var(--muted);
font-size:13px;
}
.status strong{ color: var(--text); }
footer{
margin-top:10px;
padding:10px 6px 0;
border-top:1px solid rgba(42,57,82,0.55);
color:rgba(168,179,199,0.85);
font-size:12px;
line-height:1.35;
}
.mono{ font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono","Courier New", monospace; }
@media (max-width:420px){
.tile{ height:50px; border-radius:12px; }
.key{ height:42px; border-radius:11px; }
}
</style>
</head>
<body>
<div class="app" role="application" aria-label="Operadle">
<header>
<div>
<h1>Operadle</h1>
<div class="sub">
A daily 5-letter opera puzzle (Wagner-leaning).<br/>
Hint: words include characters, objects, staging terms, and themes.
</div>
</div>
<div class="actions">
<button id="newBtn" title="Start over (same daily word)">Reset</button>
<button id="shareBtn" title="Copy your result">Share</button>
</div>
</header>
<div class="status" id="status" aria-live="polite"></div>
<div class="board" id="board" aria-label="Game board"></div>
<div class="keyboard" id="keyboard" aria-label="On-screen keyboard"></div>
<footer>
Not affiliated with The New York Times or Wordle. This is a fan-made puzzle for personal use.
<div style="margin-top:6px">
Word set is custom and Wagner-leaning (e.g., <span class="mono">wotan</span>, <span class="mono">senta</span>, <span class="mono">grail</span>).
</div>
</footer>
</div>
<script>
// -----------------------------
// Custom 5-letter word list
// Rules: exactly 5 letters, no plurals, no abbreviations/shortenings.
// -----------------------------
const WORDS = [
"anvil","curse","diary","diana","dream","essay","freia",
"gluck", "giant","grail","hagen","heart","honor","karma","lacan","liszt",
"magic","march","metre","moral","music","myths","night","noble","opera","piano",
"poems","psyche","quest","rhein","score","seidl","senta","sleep",
"smoke","spear","stage","storm","sword","wotan"
].filter(w => /^[a-z]{5}$/.test(w));
// -----------------------------
// Daily word selection (local date)
// -----------------------------
function dayNumberLocal() {
const now = new Date();
// Use local midnight boundary
const start = new Date(now.getFullYear(), 0, 1);
const diff = (new Date(now.getFullYear(), now.getMonth(), now.getDate()) - start);
const oneDay = 24 * 60 * 60 * 1000;
return Math.floor(diff / oneDay) + (now.getFullYear() * 1000);
}
function mulberry32(seed) {
return function() {
let t = seed += 0x6D2B79F5;
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
}
}
function getDailyWord() {
const seed = dayNumberLocal();
const rand = mulberry32(seed);
const idx = Math.floor(rand() * WORDS.length);
return WORDS[idx];
}
// -----------------------------
// Game state
// -----------------------------
const ROWS = 6;
const COLS = 5;
let answer = getDailyWord();
let guesses = Array.from({length: ROWS}, () => "");
let evaluations = Array.from({length: ROWS}, () => Array(COLS).fill(""));
let row = 0;
let done = false;
// -----------------------------
// UI build
// -----------------------------
const boardEl = document.getElementById("board");
const statusEl = document.getElementById("status");
const keyboardEl = document.getElementById("keyboard");
const newBtn = document.getElementById("newBtn");
const shareBtn = document.getElementById("shareBtn");
function buildBoard() {
boardEl.innerHTML = "";
for (let r = 0; r < ROWS; r++) {
const rowEl = document.createElement("div");
rowEl.className = "row";
rowEl.setAttribute("role", "row");
for (let c = 0; c < COLS; c++) {
const tile = document.createElement("div");
tile.className = "tile";
tile.setAttribute("role", "gridcell");
tile.dataset.r = r;
tile.dataset.c = c;
rowEl.appendChild(tile);
}
boardEl.appendChild(rowEl);
}
}
const KEY_ROWS = [
["q","w","e","r","t","y","u","i","o","p"],
["a","s","d","f","g","h","j","k","l"],
["enter","z","x","c","v","b","n","m","back"]
];
function buildKeyboard() {
keyboardEl.innerHTML = "";
KEY_ROWS.forEach(keys => {
const rowEl = document.createElement("div");
rowEl.className = "keyrow";
keys.forEach(k => {
const btn = document.createElement("button");
btn.className = "key" + ((k === "enter" || k === "back") ? " wide" : "");
btn.textContent = (k === "back") ? "⌫" : k;
btn.dataset.key = k;
btn.addEventListener("click", () => handleKey(k));
rowEl.appendChild(btn);
});
keyboardEl.appendChild(rowEl);
});
}
function setStatus(msg, strong=false) {
statusEl.innerHTML = strong ? `<strong>${msg}</strong>` : msg;
}
// -----------------------------
// Rendering
// -----------------------------
function render() {
// tiles
for (let r = 0; r < ROWS; r++) {
for (let c = 0; c < COLS; c++) {
const tile = boardEl.querySelector(`.tile[data-r="${r}"][data-c="${c}"]`);
const ch = guesses[r][c] ? guesses[r][c].toUpperCase() : "";
tile.textContent = ch;
tile.classList.remove("filled","absent","present","correct");
if (ch) tile.classList.add("filled");
const ev = evaluations[r][c];
if (ev) tile.classList.add(ev);
}
}
// keyboard coloring (best state wins: correct > present > absent)
const best = {};
for (let r = 0; r < ROWS; r++) {
for (let c = 0; c < COLS; c++) {
const ch = guesses[r][c];
const ev = evaluations[r][c];
if (!ch || !ev) continue;
const rank = (ev === "correct") ? 3 : (ev === "present") ? 2 : 1;
best[ch] = Math.max(best[ch] || 0, rank);
}
}
keyboardEl.querySelectorAll(".key").forEach(k => {
const key = k.dataset.key;
k.classList.remove("absent","present","correct");
if (key.length === 1 && best[key]) {
k.classList.add(best[key] === 3 ? "correct" : best[key] === 2 ? "present" : "absent");
}
});
}
// -----------------------------
// Evaluation logic
// -----------------------------
function evaluateGuess(guess, ans) {
const res = Array(COLS).fill("absent");
const ansArr = ans.split("");
const guessArr = guess.split("");
// first pass: correct
for (let i = 0; i < COLS; i++) {
if (guessArr[i] === ansArr[i]) {
res[i] = "correct";
ansArr[i] = null;
guessArr[i] = null;
}
}
// second pass: present
for (let i = 0; i < COLS; i++) {
if (!guessArr[i]) continue;
const j = ansArr.indexOf(guessArr[i]);
if (j !== -1) {
res[i] = "present";
ansArr[j] = null;
}
}
return res;
}
function isValidWord(w) {
return WORDS.includes(w);
}
// -----------------------------
// Input handling
// -----------------------------
function handleKey(k) {
if (done) return;
if (k === "enter") {
const g = guesses[row];
if (g.length < COLS) {
setStatus("Need 5 letters.");
return;
}
if (!isValidWord(g)) {
setStatus("Not in Operadle list (try another).");
return;
}
const ev = evaluateGuess(g, answer);
evaluations[row] = ev;
render();
if (g === answer) {
done = true;
setStatus("Bravo! You got it.", true);
return;
}
row++;
if (row >= ROWS) {
done = true;
setStatus(`Curtain. Answer: ${answer.toUpperCase()}`, true);
return;
}
setStatus("");
return;
}
if (k === "back") {
guesses[row] = guesses[row].slice(0, -1);
setStatus("");
render();
return;
}
if (/^[a-z]$/.test(k)) {
if (guesses[row].length >= COLS) return;
guesses[row] += k;
setStatus("");
render();
}
}
document.addEventListener("keydown", (e) => {
const key = e.key.toLowerCase();
if (key === "enter") handleKey("enter");
else if (key === "backspace") handleKey("back");
else if (/^[a-z]$/.test(key)) handleKey(key);
});
// -----------------------------
// Buttons
// -----------------------------
newBtn.addEventListener("click", () => {
// reset but keep same daily answer
guesses = Array.from({length: ROWS}, () => "");
evaluations = Array.from({length: ROWS}, () => Array(COLS).fill(""));
row = 0;
done = false;
setStatus("");
render();
});
function emojiGrid() {
// build share grid from evaluations up to current row (or last row if done)
const usedRows = done ? Math.min(row + 1, ROWS) : row;
const lines = [];
for (let r = 0; r < usedRows; r++) {
const line = evaluations[r].map(ev => ev === "correct" ? "🟩" : ev === "present" ? "🟨" : "⬛").join("");
lines.push(line);
}
return lines.join("\n");
}
shareBtn.addEventListener("click", async () => {
const date = new Date();
const stamp = date.toLocaleDateString(undefined, { year:"numeric", month:"short", day:"numeric" });
const header = `Operadle — ${stamp}`;
const body = done ? emojiGrid() : "In progress!";
const text = `${header}\n${body}`;
try{
await navigator.clipboard.writeText(text);
setStatus("Copied share text to clipboard.");
} catch {
setStatus("Couldn’t access clipboard. (Try manually selecting text.)");
alert(text);
}
});
// -----------------------------
// Init
// -----------------------------
buildBoard();
buildKeyboard();
setStatus("Type a 5-letter word. Press Enter.");
render();
</script>
</body>
</html>