(function () { if (!window.matchMedia("(hover: hover) and (pointer: fine)").matches) return; var NORMAL = "https://i.postimg.cc/44qx5SDh/Arrow-Far-Cursor.png"; var HOVER = "https://i.postimg.cc/Jh5sY5NV/Arrow-Cursor.png"; function init() { var c = document.createElement("img"); c.id = "gif-cursor"; c.alt = ""; c.src = NORMAL; document.body.appendChild(c); new Image().src = HOVER; var hovering = false; document.addEventListener("mousemove", function (e) { c.style.display = "block"; c.style.transform = "translate(" + e.clientX + "px," + e.clientY + "px)"; var on = !!(e.target.closest && e.target.closest("a, button, input, textarea, [role='button']")); if (on !== hovering) { hovering = on; c.src = on ? HOVER : NORMAL; } }); document.addEventListener("mouseleave", function () { c.style.display = "none"; }); } if (document.body) init(); else document.addEventListener("DOMContentLoaded", init); })();
TedTurtle21
window.addEventListener('load', function () { var s = document.createElement('script'); s.src = 'https://storage.ko-fi.com/cdn/widget/Widget_2.js'; s.onload = function () { kofiwidget2.init('Support me on Ko-fi', '#FF6B00', 'Q5Q8LVXPT'); document.getElementById('kofi-button').innerHTML = kofiwidget2.getHTML(); }; document.head.appendChild(s); });
I play a variety of games to unwind and have fun! My gaming preferences towards horror, cozy games but I also like platformers, action, fighting games but sometimes expect the unexpected! Let's make a splash!
(function () { /* ===== Customize these ===== */ var CHANNEL = "tedturtle21"; /* your Twitch username, lowercase */ /* Every domain this page is shown on, with no https:// and no path. Twitch will refuse to play on any domain not listed here. */ var PARENTS = ["tedturtle21.carrd.co", "www.tedturtle21.carrd.co"]; /* every domain this page is shown on, no https:// */ var GIVE_UP_MS = 15000; /* stop checking after this long if Twitch never answers */ /* =========================== */ var MIN_W = 400, MIN_H = 300; /* Twitch's required minimum embed size */ var root = document.getElementById("lv-root"); var box = document.getElementById("lv-box"); function remove() { box.className = "lv-box lv-gone"; } function reveal() { box.className = "lv-box"; } if (CHANNEL === "YOUR_TWITCH_NAME") { remove(); return; } /* Size the player from the space available, never below Twitch's minimum. Called on load and again whenever the window is resized. */ function applySize() { var boxW = Math.min(800, root.clientWidth || 800); var w = Math.max(MIN_W, boxW - 4); /* minus the 2px outline on each side */ var h = Math.max(MIN_H, Math.round(w * 9 / 16)); box.style.width = boxW + "px"; var f = document.querySelector("#lv-embed iframe"); if (f) { f.setAttribute("width", w); f.setAttribute("height", h); f.style.width = w + "px"; f.style.height = h + "px"; } return { w: w, h: h }; } var size = applySize(); var done = false; var timer = setTimeout(function () { if (!done) { done = true; remove(); } }, GIVE_UP_MS); var s = document.createElement("script"); s.src = "https://player.twitch.tv/js/embed/v1.js"; s.onerror = remove; s.onload = function () { /* Video-only player. Listeners are attached right away so we can't miss the live/offline signal. */ var player = new Twitch.Player("lv-embed", { width: size.w, height: size.h, channel: CHANNEL, autoplay: false, /* we start it once it's visible, since Twitch needs it visible to autoplay */ muted: true, /* muted autoplay is what browsers allow; viewers can unmute */ parent: PARENTS }); /* Keep the player sized to the screen (never below the minimum). Debounced so it isn't recalculated on every pixel. */ var resizeTimer; function onResize() { clearTimeout(resizeTimer); resizeTimer = setTimeout(applySize, 100); } window.addEventListener("resize", onResize); window.addEventListener("orientationchange", onResize); /* If the layout around the embed changes without the window resizing, follow that too */ if (window.ResizeObserver) { try { new ResizeObserver(onResize).observe(root); } catch (e) {} } var readyTimer, playing = false; function live() { if (done) return; done = true; clearTimeout(timer); clearTimeout(readyTimer); reveal(); applySize(); /* re-measure now that it's visible */ /* Start playback muted once the player is on screen (Twitch requires it to be visible to autoplay) */ function start() { try { player.setMuted(true); player.play(); } catch (e) {} } start(); setTimeout(start, 300); setTimeout(start, 1500); /* Some browsers (like Edge) refuse autoplay until the visitor interacts with the page. If it never started, play on their first click, tap, key press or scroll. */ setTimeout(function () { if (playing) return; var evs = ["pointerdown", "keydown", "touchstart", "wheel"], once = function () { evs.forEach(function (e) { window.removeEventListener(e, once, true); }); if (!playing) start(); }; evs.forEach(function (e) { window.addEventListener(e, once, true); }); }, 2500); } function offline() { if (done) return; done = true; clearTimeout(timer); clearTimeout(readyTimer); remove(); } player.addEventListener(Twitch.Player.ONLINE, live); player.addEventListener(Twitch.Player.PLAYING, function () { playing = true; live(); }); player.addEventListener(Twitch.Player.OFFLINE, offline); /* If the browser blocks playback, retry muted (muted autoplay is always allowed) */ player.addEventListener(Twitch.Player.PLAYBACK_BLOCKED, function () { try { player.setMuted(true); player.play(); } catch (e) {} }); /* Already-live channels don't always fire ONLINE on load. If the player is ready and no OFFLINE shows up shortly, treat it as live. */ player.addEventListener(Twitch.Player.READY, function () { readyTimer = setTimeout(live, 4000); }); }; /* Wait until the rest of the page has loaded so the player doesn't compete with it */ function go() { document.head.appendChild(s); } if (document.readyState === "complete") setTimeout(go, 1500); else window.addEventListener("load", function () { setTimeout(go, 1500); }); })();
(function () { /* Your Cloudflare Worker URL (same one as Moon Mail) */ var WORKER_URL = "https://moon-mail.lunargabriel7.workers.dev"; /* Which site this is on the Worker (added with /mailsite add key:ted ...) */ var SITE_KEY = "ted"; var TEXT_COLOR = "#5E0000", DARK_BLUE = "#5E0000"; var W0 = 400, IMG_H = 280; /* sent image area, in pixels (same as the doodle image) */ var BOX_MIN_PX = 50; /* minimum height of the text box on the page, in pixels */ var FONT_PX = 24, PAD = 12; /* text size and margin, in image pixels */ var S = 2; /* image sharpness: sent image is S times the layout size */ var BAR = 6, HEAD = 44, FOOT = 44, RADIUS = 14; var LINK = "tedturtle21.carrd.co#mail"; var TIMEZONE = "America/New_York"; /* Eastern time, always. Shows EST in winter and EDT in summer. */ var $ = function (id) { return document.getElementById(id); }; var box = $("aq-text"), measure = document.createElement("canvas").getContext("2d"); /* Word-wrap using the same font the sent image uses */ function wrap(text, maxW) { measure.font = FONT_PX + "px Itim, sans-serif"; var lines = []; text.split("\n").forEach(function (para) { var line = ""; para.split(" ").forEach(function (word) { var test = line ? line + " " + word : word; if (measure.measureText(test).width <= maxW) { line = test; return; } if (line) lines.push(line); line = ""; while (measure.measureText(word).width > maxW) { /* break very long words */ var i = word.length; while (i > 1 && measure.measureText(word.slice(0, i)).width > maxW) i--; lines.push(word.slice(0, i)); word = word.slice(i); } line = word; }); lines.push(line); }); return lines; } function bodyH(n) { return Math.ceil(n * FONT_PX * 1.25 + PAD * 2); } /* Keep the text centred (across and down) and scaled like the sent image as the page resizes */ function fitText() { var k = box.clientWidth / W0; box.style.fontSize = (FONT_PX * k) + "px"; box.style.lineHeight = (FONT_PX * 1.25 * k) + "px"; box.style.padding = (PAD * k) + "px"; centerText(); } function centerText() { var k = box.clientWidth / W0; var n = Math.max(1, wrap(box.value, W0 - PAD * 2).length); var hPx = Math.max(BOX_MIN_PX, bodyH(n) * k); box.style.height = hPx + "px"; box.style.paddingTop = ((hPx - n * FONT_PX * 1.25 * k) / 2) + "px"; } box.addEventListener("input", centerText); fitText(); window.addEventListener("resize", fitText); /* Image you receive: same frame as Moon Mail, with the message in dark red */ function exportImage() { var lh = FONT_PX * 1.25, lines = wrap(box.value.replace(/\s+$/, ""), W0 - PAD * 2); var w = W0, h = Math.max(IMG_H, bodyH(lines.length)); /* same size as the doodle image */ var body = document.createElement("canvas"); body.width = w * S; body.height = h * S; var b = body.getContext("2d"); b.scale(S, S); b.fillStyle = "#fff"; b.fillRect(0, 0, w, h); b.font = FONT_PX + "px Itim, sans-serif"; b.textBaseline = "top"; b.textAlign = "center"; b.fillStyle = TEXT_COLOR; var y0 = (h - lines.length * lh) / 2 + (lh - FONT_PX) / 2; /* Light, semi-transparent orange box behind the text */ var maxLw = 0; lines.forEach(function (l) { maxLw = Math.max(maxLw, b.measureText(l).width); }); var bp = 14, bw = Math.min(maxLw + bp * 2, w - 16), bh = lines.length * lh + bp * 2; var bx = (w - bw) / 2, by = (h - lines.length * lh) / 2 - bp, br = 12; b.fillStyle = "rgba(255,107,0,.16)"; b.beginPath(); b.moveTo(bx + br, by); b.arcTo(bx + bw, by, bx + bw, by + bh, br); b.arcTo(bx + bw, by + bh, bx, by + bh, br); b.arcTo(bx, by + bh, bx, by, br); b.arcTo(bx, by, bx + bw, by, br); b.closePath(); b.fill(); b.fillStyle = TEXT_COLOR; lines.forEach(function (l, i) { b.fillText(l, w / 2, y0 + i * lh); }); var W = w + BAR * 2, H = BAR + HEAD + BAR + h + BAR + FOOT + BAR; var out = document.createElement("canvas"); out.width = W * S; out.height = H * S; var o = out.getContext("2d"); o.scale(S, S); o.imageSmoothingQuality = "high"; function rr(x, y, a, c, r) { o.beginPath(); o.moveTo(x + r, y); o.arcTo(x + a, y, x + a, y + c, r); o.arcTo(x + a, y + c, x, y + c, r); o.arcTo(x, y + c, x, y, r); o.arcTo(x, y, x + a, y, r); o.closePath(); } o.save(); rr(0, 0, W, H, RADIUS); o.clip(); o.fillStyle = "#fff"; o.fillRect(0, 0, W, H); o.drawImage(body, BAR, BAR + HEAD + BAR, w, h); o.fillStyle = DARK_BLUE; o.fillRect(0, BAR + HEAD, W, BAR); o.fillRect(0, BAR + HEAD + BAR + h, W, BAR); o.restore(); o.strokeStyle = DARK_BLUE; o.lineWidth = BAR; rr(BAR / 2, BAR / 2, W - BAR, H - BAR, RADIUS - BAR / 2); o.stroke(); o.fillStyle = DARK_BLUE; o.font = "18px Itim, sans-serif"; o.textAlign = "center"; o.textBaseline = "middle"; o.fillText(LINK, W / 2, BAR + HEAD / 2); var now = new Date(); var d = now.toLocaleDateString("en-US", { year: "numeric", month: "long", day: "numeric", timeZone: TIMEZONE }); var t = now.toLocaleTimeString("en-US", { hour: "numeric", minute: "2-digit", timeZoneName: "short", timeZone: TIMEZONE }); o.fillText("Sent " + d + " at " + t, W / 2, BAR + HEAD + BAR + h + BAR + FOOT / 2); return out.toDataURL("image/png"); } /* Send */ var statusEl = $("aq-status"), sendBtn = $("aq-send"); function say(text, cls) { statusEl.textContent = text; statusEl.className = "aq-status " + (cls || ""); } sendBtn.addEventListener("click", function () { if (!box.value.trim()) { say("Type something first!", "err"); return; } sendBtn.disabled = true; say("Sending…"); /* Make sure the Itim font is ready so the sent image matches */ var ready = (document.fonts && document.fonts.load) ? document.fonts.load("24px Itim").catch(function () {}) : Promise.resolve(); ready.then(function () { return fetch(WORKER_URL, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ site: SITE_KEY, doodle: exportImage(), website: $("aq-website").value }) }); }) .then(function (r) { return r.json().catch(function () { return {}; }).then(function (d) { return { ok: r.ok, d: d }; }); }) .then(function (res) { if (!res.ok) throw new Error(res.d.error || "Something went wrong."); say("Sent! Thank you 💜", "ok"); box.value = ""; centerText(); setTimeout(function () { sendBtn.disabled = false; }, 4000); }) .catch(function (e) { say(e.message || "Couldn't send, please try again.", "err"); sendBtn.disabled = false; }); }); })();
Doodle Box
Send me an anonymous doodle!
(function () { /* Your Cloudflare Worker URL (see setup steps) */ var WORKER_URL = "https://moon-mail.lunargabriel7.workers.dev"; /* Which site this is on the Worker (added with /mailsite add key:ted ...) */ var SITE_KEY = "ted"; /* Link shown at the top of the image. Leave empty to use this page's own address automatically. */ var SITE_LINK = "tedturtle21.carrd.co#mail"; var S = 2; /* image sharpness: canvas and sent image are S times the 400x280 layout size */ var $ = function (id) { return document.getElementById(id); }; var canvas = $("ms-canvas"), vctx = canvas.getContext("2d"); /* Ink (lines and shapes) sits on top of a separate fill layer, so fills show cleanly under soft edges */ var inkL = document.createElement("canvas"), fillL = document.createElement("canvas"); inkL.width = fillL.width = canvas.width; inkL.height = fillL.height = canvas.height; var ctx = inkL.getContext("2d"), fctx = fillL.getContext("2d"); var color = "#111111", size = 3, drawing = false, last = null, dirty = false, undoStack = []; function render() { vctx.fillStyle = "#fff"; vctx.fillRect(0, 0, canvas.width, canvas.height); vctx.drawImage(fillL, 0, 0); vctx.drawImage(inkL, 0, 0); } function blank() { ctx.clearRect(0, 0, canvas.width, canvas.height); fctx.clearRect(0, 0, canvas.width, canvas.height); render(); } blank(); ctx.lineCap = "round"; ctx.lineJoin = "round"; /* Drawing */ function pos(e) { var r = canvas.getBoundingClientRect(); return { x: (e.clientX - r.left - canvas.clientLeft) * canvas.width / canvas.clientWidth, y: (e.clientY - r.top - canvas.clientTop) * canvas.height / canvas.clientHeight }; } function snapshot() { undoStack.push({ i: ctx.getImageData(0, 0, canvas.width, canvas.height), f: fctx.getImageData(0, 0, canvas.width, canvas.height) }); if (undoStack.length > 12) undoStack.shift(); } var tool = "draw", start = null, base = null, EDGE = 64; /* Pencil and eraser. The eraser removes both lines and fills (back to white) and is twice the brush size. */ function paint(a, b, to) { var erase = tool === "erase", w = size * S * (erase ? 2 : 1); (erase ? [ctx, fctx] : [ctx]).forEach(function (c) { c.save(); c.globalCompositeOperation = erase ? "destination-out" : "source-over"; c.strokeStyle = color; c.fillStyle = color; c.lineWidth = w; c.lineCap = "round"; c.lineJoin = "round"; c.beginPath(); if (to) { c.moveTo(a.x, a.y); c.quadraticCurveTo(b.x, b.y, to.x, to.y); c.stroke(); } else if (a.x === b.x && a.y === b.y) { c.arc(a.x, a.y, w / 2, 0, Math.PI * 2); c.fill(); } else { c.moveTo(a.x, a.y); c.lineTo(b.x, b.y); c.stroke(); } c.restore(); }); render(); } /* Bucket fill: finds the enclosed area using the ink layer as walls, then paints UNDER the ink. The paint also tucks 2px beneath the walls, so soft line edges blend into the fill with no light fringe. */ function floodFill(pt) { var w = canvas.width, h = canvas.height, x0 = Math.floor(pt.x), y0 = Math.floor(pt.y); if (x0 < 0 || y0 < 0 || x0 >= w || y0 >= h) return false; var ink = ctx.getImageData(0, 0, w, h).data, fi = fctx.getImageData(0, 0, w, h), f = fi.data, i0 = (y0 * w + x0) * 4; if (ink[i0 + 3] >= EDGE) return false; /* tapped on a line itself */ var r = parseInt(color.slice(1, 3), 16), g = parseInt(color.slice(3, 5), 16), b = parseInt(color.slice(5, 7), 16); var sr = f[i0], sg = f[i0 + 1], sb = f[i0 + 2], sa = f[i0 + 3]; if (sa === 255 && sr === r && sg === g && sb === b) return false; var mark = new Uint8Array(w * h), list = [], stack = [x0, y0]; while (stack.length) { var y = stack.pop(), x = stack.pop(), idx = y * w + x, o = idx * 4; if (mark[idx]) continue; if (ink[o + 3] >= EDGE || f[o] !== sr || f[o + 1] !== sg || f[o + 2] !== sb || f[o + 3] !== sa) continue; mark[idx] = 1; list.push(idx); if (x > 0) stack.push(x - 1, y); if (x < w - 1) stack.push(x + 1, y); if (y > 0) stack.push(x, y - 1); if (y < h - 1) stack.push(x, y + 1); } var front = list.slice(), all = list.slice(); for (var pass = 0; pass < 2; pass++) { var next = []; front.forEach(function (idx) { var x = idx % w, y = (idx - x) / w; [[x - 1, y], [x + 1, y], [x, y - 1], [x, y + 1]].forEach(function (n) { if (n[0] < 0 || n[1] < 0 || n[0] >= w || n[1] >= h) return; var j = n[1] * w + n[0]; if (!mark[j] && ink[j * 4 + 3] >= EDGE) { mark[j] = 1; next.push(j); all.push(j); } }); }); front = next; } all.forEach(function (idx) { var o = idx * 4; f[o] = r; f[o + 1] = g; f[o + 2] = b; f[o + 3] = 255; }); fctx.putImageData(fi, 0, 0); render(); return true; } /* Outline shapes: line and square go corner to corner, circle goes from its centre outwards */ function shape(a, b) { ctx.strokeStyle = color; ctx.lineWidth = size * S; ctx.beginPath(); if (tool === "line") { ctx.moveTo(a.x, a.y); ctx.lineTo(b.x, b.y); } else if (tool === "rect") ctx.rect(a.x, a.y, b.x - a.x, b.y - a.y); else ctx.arc(a.x, a.y, Math.hypot(b.x - a.x, b.y - a.y), 0, Math.PI * 2); ctx.stroke(); } var mid = null; canvas.addEventListener("pointerdown", function (e) { e.preventDefault(); if (tool === "fill") { snapshot(); if (floodFill(pos(e))) dirty = true; else undoStack.pop(); return; } canvas.setPointerCapture(e.pointerId); snapshot(); drawing = true; last = pos(e); if (tool === "draw" || tool === "erase") { dirty = true; mid = last; paint(last, last); } else { start = last; base = undoStack[undoStack.length - 1]; } }); canvas.addEventListener("pointermove", function (e) { if (!drawing) return; if (tool === "draw" || tool === "erase") { var evs = e.getCoalescedEvents ? e.getCoalescedEvents() : []; if (!evs.length) evs = [e]; evs.forEach(function (ev) { var p = pos(ev), m = { x: (last.x + p.x) / 2, y: (last.y + p.y) / 2 }; paint(mid, last, m); /* curve through the midpoints */ mid = m; last = p; }); } else { var p = pos(e); ctx.putImageData(base.i, 0, 0); shape(start, p); render(); dirty = true; } }); ["pointerup", "pointercancel"].forEach(function (t) { canvas.addEventListener(t, function () { if (drawing && (tool === "draw" || tool === "erase") && mid) paint(mid, last); /* finish the last bit */ drawing = false; mid = null; }); }); var toolBtns = document.querySelectorAll(".ms-tool[data-tool]"); function setTool(name) { tool = name; Array.prototype.forEach.call(toolBtns, function (b) { b.classList.toggle("on", b.dataset.tool === name); }); } Array.prototype.forEach.call(toolBtns, function (b) { b.addEventListener("click", function () { setTool(b.dataset.tool); }); }); /* Zoom: makes the whole box (and the canvas in it) bigger or smaller. When zoomed in, the box is allowed to grow wider than its Carrd column, staying centred on it. */ var ZOOMS = [21, 26, 31, 36], zi = 0, boxEl = document.querySelector(".ms-box"); function layoutBox() { if (zi === 0) { boxEl.style.maxWidth = ZOOMS[0] + "em"; boxEl.style.width = boxEl.style.marginLeft = boxEl.style.marginRight = ""; return; } var fs = parseFloat(getComputedStyle(boxEl).fontSize) || 16; var w = Math.min(ZOOMS[zi] * fs, document.documentElement.clientWidth - 24); /* never wider than the screen */ boxEl.style.maxWidth = "none"; boxEl.style.width = w + "px"; boxEl.style.marginLeft = "calc(50% - " + (w / 2) + "px)"; boxEl.style.marginRight = "0"; } function setZoom(n) { zi = Math.max(0, Math.min(ZOOMS.length - 1, n)); layoutBox(); $("ms-zout").disabled = zi === 0; $("ms-zin").disabled = zi === ZOOMS.length - 1; } window.addEventListener("resize", layoutBox); $("ms-zout").addEventListener("click", function () { setZoom(zi - 1); }); $("ms-zin").addEventListener("click", function () { setZoom(zi + 1); }); setZoom(0); /* Tools */ $("ms-size").addEventListener("input", function () { size = +this.value; }); $("ms-picker").addEventListener("input", function () { color = this.value; $("ms-wheel").style.setProperty("--c", color); }); $("ms-undo").addEventListener("click", function () { var s = undoStack.pop(); if (s) { ctx.putImageData(s.i, 0, 0); fctx.putImageData(s.f, 0, 0); render(); } if (!undoStack.length) dirty = false; }); $("ms-clear").addEventListener("click", function () { blank(); undoStack = []; dirty = false; }); /* Image you receive: header link, dark red bars top and bottom, and a sent timestamp */ var DARK_BLUE = "#5E0000", BAR = 6, HEAD = 44, FOOT = 44, RADIUS = 14; var TIMEZONE = "America/New_York"; /* Eastern time, always. Shows EST in winter and EDT in summer. */ function linkText() { if (SITE_LINK) return SITE_LINK; return (location.host + location.pathname).replace(/\/$/, ""); } function exportImage() { var w = canvas.width / S, h = canvas.height / S, W = w + BAR * 2, H = BAR + HEAD + BAR + h + BAR + FOOT + BAR; var out = document.createElement("canvas"); out.width = W * S; out.height = H * S; var o = out.getContext("2d"); o.scale(S, S); o.imageSmoothingQuality = "high"; function rr(x, y, a, b, r) { o.beginPath(); o.moveTo(x + r, y); o.arcTo(x + a, y, x + a, y + b, r); o.arcTo(x + a, y + b, x, y + b, r); o.arcTo(x, y + b, x, y, r); o.arcTo(x, y, x + a, y, r); o.closePath(); } o.save(); rr(0, 0, W, H, RADIUS); o.clip(); o.fillStyle = "#fff"; o.fillRect(0, 0, W, H); o.drawImage(canvas, BAR, BAR + HEAD + BAR, w, h); o.fillStyle = DARK_BLUE; o.fillRect(0, BAR + HEAD, W, BAR); o.fillRect(0, BAR + HEAD + BAR + h, W, BAR); o.restore(); o.strokeStyle = DARK_BLUE; o.lineWidth = BAR; rr(BAR / 2, BAR / 2, W - BAR, H - BAR, RADIUS - BAR / 2); o.stroke(); o.fillStyle = DARK_BLUE; o.font = "18px Itim, sans-serif"; o.textAlign = "center"; o.textBaseline = "middle"; var link = linkText(), fs = 18; o.font = fs + "px Itim, sans-serif"; while (fs > 10 && o.measureText(link).width > W - 24) { fs--; o.font = fs + "px Itim, sans-serif"; } o.fillText(link, W / 2, BAR + HEAD / 2); o.font = "18px Itim, sans-serif"; var now = new Date(); var d = now.toLocaleDateString("en-US", { year: "numeric", month: "long", day: "numeric", timeZone: TIMEZONE }); var t = now.toLocaleTimeString("en-US", { hour: "numeric", minute: "2-digit", timeZoneName: "short", timeZone: TIMEZONE }); o.fillText("Sent " + d + " at " + t, W / 2, BAR + HEAD + BAR + h + BAR + FOOT / 2); return out.toDataURL("image/png"); } /* Send */ var statusEl = $("ms-status"), sendBtn = $("ms-send"); function say(text, cls) { statusEl.textContent = text; statusEl.className = "ms-status " + (cls || ""); } sendBtn.addEventListener("click", function () { if (!dirty) { say("Draw something first!", "err"); return; } sendBtn.disabled = true; say("Sending…"); fetch(WORKER_URL, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ site: SITE_KEY, doodle: exportImage(), website: $("ms-website").value }) }) .then(function (r) { return r.json().catch(function () { return {}; }).then(function (d) { return { ok: r.ok, d: d }; }); }) .then(function (res) { if (!res.ok) throw new Error(res.d.error || "Something went wrong."); say("Sent! Thank you 🧡", "ok"); blank(); undoStack = []; dirty = false; setTimeout(function () { sendBtn.disabled = false; }, 4000); }) .catch(function (e) { say(e.message || "Couldn't send, please try again.", "err"); sendBtn.disabled = false; }); }); })();