diff --git a/videos.html b/videos.html index 17b8079..74ac316 100644 --- a/videos.html +++ b/videos.html @@ -109,6 +109,27 @@ async function load() { return; } out.innerHTML = '
' + r.projects.map(card).join("") + '
'; + var byId = {}; + r.projects.forEach(function (p) { byId[p.id] = p; }); + [].forEach.call(out.querySelectorAll("[data-share]"), function (b) { + b.onclick = async function () { + var p = byId[decodeURIComponent(b.getAttribute("data-share"))]; + if (!p) return; + var link = window.__shareUrl(p); + if (!link) { showMsg("msg", "That one has no video yet."); return; } + var title = p.title || ((p.pet_name || "Your pet") + " has something to say"); + // The native sheet is the shortest path into a text message on a phone. + if (navigator.share) { + try { await navigator.share({ title: title, text: title, url: link }); return; } + catch (e) { if (e && e.name === "AbortError") return; } + } + try { + await navigator.clipboard.writeText(link); + b.textContent = "Copied"; + setTimeout(function () { b.textContent = "Share"; }, 1600); + } catch (e) { showMsg("msg", "Copy this: " + link); } + }; + }); // Anything still being written will change shortly; refresh so the button appears. if (r.projects.some(function (p) { return p.status === "scripting"; })) setTimeout(load, 6000); }