(() => { const btn = document.getElementById("ping16"); if (!btn) return; const out = document.getElementById("ping16-out"); const KEY = "zoo-push-allowed"; const get = () => { try { return localStorage.getItem(KEY); } catch (e) { return null; } }; const put = (v) => { try { v ? localStorage.setItem(KEY, "1") : localStorage.removeItem(KEY); } catch (e) {} }; if (/[?&]pushed=1/.test(location.search)) { put(true); history.replaceState(null, "", "/#e16"); out.textContent = "allowed: press the button again"; } const push = btn.dataset.push; document.getElementById("ping16-manage").addEventListener("click", () => { location.href = push + "/"; }); const go = () => { location.href = push + "/?enable=1&back=" + encodeURIComponent(location.origin + "/?pushed=1#e16"); }; btn.addEventListener("click", async () => { if (!get()) { out.textContent = "taking you to push to allow the zoo…"; go(); return; } btn.disabled = true; out.textContent = "scheduled: ten seconds"; const j = await zoo.call("/api/16/notify", {}); if (j.error) { out.textContent = j.error; btn.disabled = false; return; } for (let i = 0; i < 20; i++) { await new Promise(r => setTimeout(r, 1500)); const s = (await zoo.call("/api/16/status")).state; if (!s || s.state === "waiting") continue; btn.disabled = false; if (s.state === "sent") out.textContent = "sent to " + s.sent + " browser(s): look for it"; else if (s.state === "nobody") { put(false); out.innerHTML = 'Nothing was sent: the zoo is not allowed on any of your browsers yet. '; document.getElementById("ping16-allow").onclick = go; } else out.textContent = s.error || "failed"; return; } btn.disabled = false; out.textContent = "no answer yet"; }); })();