Wire the share button up

The button was rendered but nothing listened for it.
This commit is contained in:
gator 2026-09-09 01:08:46 +00:00
parent 9801f1a8d1
commit 6dcbfbd035

View file

@ -109,6 +109,27 @@ async function load() {
return; return;
} }
out.innerHTML = '<div class="list">' + r.projects.map(card).join("") + '</div>'; out.innerHTML = '<div class="list">' + r.projects.map(card).join("") + '</div>';
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. // 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); if (r.projects.some(function (p) { return p.status === "scripting"; })) setTimeout(load, 6000);
} }