Feat: Auto-unsubscribe via /unsubscribe?email=

Prefills and submits the form when an email query param is present
(restoring '+' that URLSearchParams decodes to a space), then clears
the query string on success.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-08 02:33:07 +00:00
co-authored by Claude Opus 5.5
parent 88aad3106c
commit a85bcbeb4a
+5 -3
View File
@@ -34,19 +34,21 @@
</footer> </footer>
</main> </main>
<script> <script>
const form=document.getElementById('unsub-form'),msg=document.getElementById('msg'); const form=document.getElementById('unsub-form'),msg=document.getElementById('msg'),input=document.getElementById('email'),
q=new URLSearchParams(location.search).get('email')?.trim().replace(/ /g,'+');
form.onsubmit=async e=>{ form.onsubmit=async e=>{
e.preventDefault(); e.preventDefault();
msg.className='text-center text-sm text-gray-500'; msg.className='text-center text-sm text-gray-500';
msg.textContent='Processing...'; msg.textContent='Processing...';
msg.classList.remove('hidden'); msg.classList.remove('hidden');
try{ try{
const r=await fetch('https://newsletter.planetrenox.com/api/unsub',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({pool:'lynchmark',email:document.getElementById('email').value})}); const r=await fetch('https://newsletter.planetrenox.com/api/unsub',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({pool:'lynchmark',email:input.value.trim()})});
const d=await r.json(); const d=await r.json();
if(d.ok){msg.textContent='✓ Unsubscribed';msg.className='text-center text-sm text-green-600';} if(d.ok){msg.textContent=`✓ ${d.email} unsubscribed`;msg.className='text-center text-sm text-green-600';history.replaceState(null,'',location.pathname);}
else{msg.textContent=d.error||'Error';msg.className='text-center text-sm text-red-600';} else{msg.textContent=d.error||'Error';msg.className='text-center text-sm text-red-600';}
}catch{msg.textContent='Network error';msg.className='text-center text-sm text-red-600';} }catch{msg.textContent='Network error';msg.className='text-center text-sm text-red-600';}
}; };
if(q)input.value=q,form.requestSubmit();
</script> </script>
</body> </body>
</html> </html>