Make saner score when you lose
dkl9

dkl9 commited on 2026-40 23:43:26
Showing 1 changed files, with 10 additions and 6 deletions.

... ...
@@ -25,7 +25,7 @@ switch (host) {
25 25
                 note.classList.add("side");
26 26
                 const b = elemText("Copy again", "button");
27 27
                 b.type = "button";
28
-                b.addEventListener("click", () => navigator.clipboard.writeText(boast));
28
+                b.addEventListener("click", () => navigator.clipboard.writeText(localStorage.getItem("score")));
29 29
                 note.append(b);
30 30
                 grid.before(note);
31 31
                 navigator.clipboard.writeText(score.join("\n"));
... ...
@@ -103,7 +103,7 @@ function submitGuess() {
103 103
         return;
104 104
     }
105 105
     currentRow++;
106
-    if (currentRow >= maxGuesses && !playedToday()) loseMessage();
106
+    if (currentRow >= maxGuesses && !playedToday()) setTimeout(loseMessage, 300 * tl);
107 107
     currentInput = [];
108 108
 }
109 109
 
... ...
@@ -249,9 +249,9 @@ function humane(f = target) {
249 249
     return `${infix(f)} (input as ${f.join(" ")})`;
250 250
 }
251 251
 
252
-function winMessage() {
253
-    let boast = `Functle ${puzzleNum} ${currentRow + 1}/${maxGuesses}\n`;
254
-    for (i = 0; i <= currentRow; i++) {
252
+function copyBoast(failed) {
253
+    let boast = `Functle ${puzzleNum} ${failed ? "F" : currentRow + 1}/${maxGuesses}\n`;
254
+    for (i = 0; i <= Math.min(currentRow, maxGuesses - 1); i++) {
255 255
         const r = grid.rows[i];
256 256
         for (const c of r.cells) {
257 257
             const l = c.classList;
... ...
@@ -264,6 +264,10 @@ function winMessage() {
264 264
     boast += "https://DKL9.net/functle/";
265 265
     localStorage.setItem("score", boast);
266 266
     navigator.clipboard.writeText(boast);
267
+}
268
+
269
+function winMessage() {
270
+    copyBoast(false);
267 271
     const w = elemText(`${congrats[currentRow]}! The function was ${humane()}. Share your score. It's on your clipboard. `, "section");
268 272
     const b = elemText("Copy again", "button");
269 273
     b.type = "button";
... ...
@@ -276,6 +280,6 @@ function winMessage() {
276 280
 }
277 281
 
278 282
 function loseMessage() {
279
-    localStorage.setItem("score", `Functle ${puzzleNum} ${maxGuesses + 1}/${maxGuesses}`);
283
+    copyBoast(true);
280 284
     container.prepend(elemText(`Better luck next time. The function was ${humane()}`));
281 285
 }
282 286