diff --git a/script.html b/script.html index bf9c0c8..4fb89d8 100644 --- a/script.html +++ b/script.html @@ -1194,4 +1194,199 @@ function bindShare() { var sl = document.getElementById("sharelink"); if (sl) sl.onclick = async function () { var title = (DATA && DATA.script && DATA.script.title) || "A video"; - \ No newline at end of file + // The native sheet is the shortest path into a text message on a phone. + if (navigator.share) { + try { await navigator.share({ title: title, text: msg, url: link }); return; } + catch (e) { if (e && e.name === "AbortError") return; } + } + try { + await navigator.clipboard.writeText(link); + sl.textContent = "Link copied"; + setTimeout(function () { sl.textContent = "Share the video"; }, 1600); + } catch (e) { showMsg("msg", "Copy this: " + link); } + }; + var c = document.getElementById("sharecopy"); + if (c) c.onclick = function () { + var t = document.getElementById("sharemsg"); + t.select(); + navigator.clipboard.writeText(t.value).then(function () { + c.textContent = "Copied"; + setTimeout(function () { c.textContent = "Copy the message"; }, 1600); + }).catch(function () { c.textContent = "Select it and copy"; }); + }; + } + + b.onclick = async function () { + hideMsg("msg"); + b.disabled = true; b.textContent = "Choosing a frame…"; + var r = await api("share_image", { email: email, project_id: pid, refresh: true }); + if (r.ok && r.pending) { + var waited = 0; + r = await new Promise(function (done) { + var t = setInterval(async function () { + waited += 4; + var g = await api("share_image", { email: email, project_id: pid }); + if (g.ok && !g.pending) { clearInterval(t); done(g); return; } + if (waited > 180) { clearInterval(t); done({ ok: false, error: "That is taking unusually long." }); } + }, 4000); + }); + } + b.disabled = false; b.textContent = "Pick another frame"; + if (!r.ok) { showMsg("msg", r.error || "Could not make that picture."); return; } + if (r.note) { showMsg("msg", r.note); return; } + note.textContent = r.status_text || ""; + paint(r); + }; + + api("share_image", { email: email, project_id: pid }).then(function (r) { + if (r && r.ok && !r.pending && r.image) { + b.textContent = "Pick another frame"; + note.textContent = r.status_text || ""; + paint(r); + } + }); +} + +function bindPost() { + loadTakes(); + bindShare(); + // The editing bay is opt-in. Most people want to watch the thing and leave. + var eo = document.getElementById("edlopen"); + if (eo) eo.onclick = function () { + var w = document.getElementById("edlwrap"); + var open = w.style.display === "none"; + w.style.display = open ? "" : "none"; + this.textContent = open ? "Close the video editor" : "Open the video editor"; + if (open) { + if (!EDL) loadEdl((DATA && DATA.project) || {}); + else tlDraw(); + w.scrollIntoView({ behavior: "smooth", block: "start" }); + } + }; + var sb = document.getElementById("seams"); + function paintSeams(r) { + var el = document.getElementById("seamout"); + if (!el) return; + el.innerHTML = '
' + esc(r.status_text || "") + '
' + + (r.seams || []).map(function (x) { + var col = x.verdict === "smooth" ? "var(--good)" + : (x.verdict === "visible" ? "var(--accent2)" : "var(--bad)"); + return '' + esc(r.status_text || "Measuring…") + '
'; + var waited = 0; + var t = setInterval(async function () { + waited += 4; + var g = await api("seam_report", { email: email, project_id: pid }); + if (g.ok && !g.pending) { + clearInterval(t); + sb.disabled = false; sb.textContent = "Measure the joins"; + paintSeams(g); + return; + } + if (waited > 180) { + clearInterval(t); + sb.disabled = false; sb.textContent = "Measure the joins"; + showMsg("msg", "Measuring is taking unusually long."); + } + }, 4000); + return; + } + sb.disabled = false; sb.textContent = "Measure the joins"; + if (!r.seams || !r.seams.length) { + el.innerHTML = '' + esc(r.status_text || "Nothing to measure.") + '
'; + return; + } + el.innerHTML = '' + esc(r.status_text || "") + '
' + + r.seams.map(function (x) { + var col = x.verdict === "smooth" ? "var(--good)" + : (x.verdict === "visible" ? "var(--accent2)" : "var(--bad)"); + return '