diff --git a/script.html b/script.html index 9e9bf17..648a605 100644 --- a/script.html +++ b/script.html @@ -341,6 +341,15 @@ function render(r) { + (p.cut_url ? 'Cut it again' : 'Cut the B-roll in') + '' + '
' + '
' + + '' + + '

Send it to someone

' + + '
' + + '

Texting the video itself puts it through ' + + 'carrier transcoding and it arrives looking worse than it left. Send the picture as ' + + 'the hook and let the link carry the video at full quality.

' + + '' + + '' + + '
' + '
'; } @@ -1119,8 +1128,79 @@ function bindPreviz() { }); } +// The picture is the hook; the link carries the video. Never the video itself +// over MMS - carriers transcode it into mush. +function bindShare() { + var b = document.getElementById("sharebtn"); + if (!b) return; + var note = document.getElementById("sharenote"), + out = document.getElementById("shareout"); + + function paint(r) { + var kb = Math.round((r.bytes || 0) / 1024); + var link = r.video || ""; + var msg = ((DATA && DATA.script && DATA.script.title) + ? DATA.script.title + " — " : "") + + ((DATA && DATA.project && DATA.project.pet_name) || "your pet") + + " has something to say. " + link; + out.innerHTML = '
' + + 'share picture' + + '
' + + '

' + esc(r.size || "") + ' · ' + kb + ' KB' + + ' · well inside the 600KB most carriers allow, so it will not be ' + + 'downsampled.

' + + '' + + '' + + '' + + 'Download the picture' + + '
'; + 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 () {