Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

1.8 KB
Raw Blame
// Wires up the footer newsletter form on any page that includes it.
// POSTs to /api/newsletter/subscribe and shows inline success/error.
// Idempotent — safe to call multiple times. Forms are tagged once they're
// wired so dynamic footer injection (see /footer.js) re-triggers without
// double-binding.
(function () {
	function wireForm(form) {
		if (form.__newsletterWired) return;
		form.__newsletterWired = true;

		const input = form.querySelector('input[name="email"]');
		const btn = form.querySelector('button[type="submit"]');
		const msg = form.parentElement?.querySelector('[data-newsletter-msg]');
		if (!input || !btn) return;

		function setMsg(text, cls) {
			if (!msg) return;
			msg.textContent = text;
			msg.classList.remove('is-error', 'is-success');
			if (cls) msg.classList.add(cls);
		}

		form.addEventListener('submit', async (e) => {
			e.preventDefault();
			const email = input.value.trim();
			if (!email || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
				setMsg('Please enter a valid email.', 'is-error');
				return;
			}
			btn.disabled = true;
			setMsg('Subscribing…');
			try {
				const r = await fetch('/api/newsletter/subscribe', {
					method: 'POST',
					headers: { 'content-type': 'application/json' },
					body: JSON.stringify({ email }),
				});
				if (!r.ok) {
					const data = await r.json().catch(() => ({}));
					throw new Error(data.error_description || 'Subscription failed');
				}
				input.value = '';
				setMsg('Thanks — you’re on the list.', 'is-success');
			} catch (err) {
				setMsg(err.message || 'Something went wrong.', 'is-error');
			} finally {
				btn.disabled = false;
			}
		});
	}

	function scan() {
		document.querySelectorAll('[data-newsletter-form]').forEach(wireForm);
	}

	window.__threewsFooterNewsletterReady = scan;
	scan();
})();