|
javascript:(() => { const e = 3; function t(e, t, n = ".") { if (0 === t.length) return ""; if (1 === t.length) return `Letter ${t[0]} ${e}${n} `; if (5 === t.length) return `All letters ${e}. `; const r = t.pop(); return `Letters ${t.join(", ")} and ${r} ${e}${n} `; } function n(t) { return e * t; } const r = document.querySelector("game-app"); if (r) try { !function (e, t) { !function () { const e = document.querySelector("#wordle-image-generator-modal"), t = document.querySelector("#wordle-image-generator-overlay"); e && e.remove(), t && t.remove(); }(); const n = document.createElement("button"); n.innerText = "Close", n.style = "background: none; border: none; font-size: 0.8em; cursor: pointer; position: absolute; top: 0.25rem; right: 0.25rem; padding: 0.4rem 0.8rem;"; const r = document.createElement("h2"); r.innerText = "Wordle image generator", r.style = "margin-top: 0;"; const o = document.createElement("p"); o.innerText = "A little tool for sharing your Wordle results in a more accessible way. Just copy or save the image and description below."; const a = document.createElement("img"); a.src = e, a.alt = t, a.style = "max-width:100%;"; const l = document.createElement("button"); l.innerText = "Copy alt text", l.style = "float:right;font-size: 1rem; padding: 0.5em 1em;", l.addEventListener("click", () => navigator.clipboard.writeText(t)); const i = document.createElement("p"); i.style = "max-width: 100%; background: #f6f7f8; border-radius: 10px; padding: 1em;", i.innerText = t; const d = document.createElement("div"); d.id = "wordle-image-generator-modal", d.style = "z-index:10000;position:fixed;top:50%;left:50%;transform:translate(-50%,-50%);text-align:center;width: 400px;max-width:80%;max-height:80%;background:white;padding:2rem;border:4px solid #d3d6da;border-radius: 30px;", d.appendChild(n), d.appendChild(r), d.appendChild(o), d.appendChild(a), d.appendChild(i), d.appendChild(l); const c = document.createElement("div"); c.id = "wordle-image-generator-overlay", c.style = "z-index: 9999; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5);"; const s = () => { d.remove(), c.remove(); }; c.addEventListener("click", s), n.addEventListener("click", s), document.body.appendChild(c), document.body.appendChild(d); }(function (e) { const t = e.evaluations.filter(e => null != e), r = document.createElement("canvas"), o = r.getContext("2d"), a = n(10), l = { absent: "#d3d6da", present: "#c9b458", correct: "#6aaa64" }, i = n(20), d = n(2), c = n(6), s = n(15), m = 5 * i + (5 * d - 1), u = s + (a + c + i * t.length + (d * t.length - 1)) + s, g = u / 9 * 16, p = (g - m) / 2, h = s, f = h + a + c; r.width = g, r.height = u, o.fillStyle = "white", o.fillRect(0, 0, r.width, r.height), o.fillStyle = "black", o.font = `${a}px 'Clear Sans', 'Helvetica Neue', Arial, sans-serif`, o.textBaseline = "top", o.fillText(function (e) { var t = e.dayOffset, n = e.rowIndex, r = e.hardMode, o = "WIN" === e.gameStatus, a = "Wordle ".concat(t); return a += " ".concat(o ? n : "X", "/").concat(6), r && (a += "*"), a; }(e), p, h, r.width); for (let e = 0; e < t.length; e++) { const n = t[e], r = f + e * (i + d); for (let e = 0; e < n.length; e++) { const t = n[e], a = p + e * (i + d); o.fillStyle = l[t] || l.absent, o.fillRect(a, r, i, i); } } return r.toDataURL(); }(r), function (e) { const n = e.evaluations, r = e.dayOffset, o = e.rowIndex, a = "WIN" === e.gameStatus; let l = `Wordle ${r} result. `; return l += a ? `Won in ${o} of 6 guesses. ` : "Lost after all 6 guesses. ", n.forEach((e, n) => { if (null === e) return; l += `Guess ${n + 1}: `; const r = { correct: [], present: [], absent: [] }; e.forEach((e, t) => { r[e].push(t + 1); }), l += t("correct", r.correct, r.present.length > 0 ? "," : "."), l += t("present", r.present), 0 === r.correct.length && 0 === r.present.length && (l += t("absent", r.absent)); }), l; }(r)); } catch (e) { alert("Something went wrong when generating the image! Perhaps Wordle has been updated and this bookmarklet is out of date?"); } else console.warn("Wordle image generator could not find a Wordle game on this page."); })(); |