Project Log
AuthorViktor Hansson
SubjectElectronics · 3D printing · misc. hacks
Rev
Commit
c7e34df · 2026-08-09 00:12 UTC
Author
Claude
Message
Priority 5 on the ntfy push so it wakes the device
View on GitHub →

A +1 button that remembers your name

Every post page now has a red-pencil "+1" button at the bottom. It's the first bit of interactivity on the site that isn't just "click the link, load the page", so this note explains what it does, where the data goes, and where it doesn't.

What happens when you tap it

The first time you press +1 on any post, a browser prompt asks for your name. Whatever you type gets saved in localStorage under p1-name, on that browser only. From then on, every +1 you leave (this post, another post, next week, six months from now) gets attributed to that name automatically, with no second prompt. The button itself flips to "+1 from <name>" and stays that way on repeat visits so you can see which entries you've already flagged.

Which posts you've +1'd is a separate localStorage key (p1-posts), keyed by post slug, with the name and a timestamp on each entry. Clearing your site data resets both. A different browser, device, or profile is a fresh slate: your name lives on the machine, not in the cloud.

Where the +1 goes

Straight to my phone. The button doesn't talk to a server I own, because I don't have one. Instead it POSTs a small JSON blob to ntfy.sh, a free pub/sub push service. The payload carries your name, the post title and a link back to it; on my end the ntfy app is subscribed to a private topic and pops a notification when the message arrives. No account, no cookie, one fetch() call in the browser.

So there are two independent things happening when you tap +1: your name and which posts you've +1'd stay in this browser's localStorage so the button remembers you next time, and a one-shot push goes out over the public internet to tell me about it. Neither carries anything beyond the name you typed, the post's title and slug, and the current page URL.

The topic name sits in the page source (that's how the fetch knows where to send). Anyone reading View Source can also POST to it and pretend to be a reader; if that starts happening I rotate the topic and move on. Fine tradeoff for not standing up a real backend today.

Why a browser prompt

A window.prompt() is the ugliest possible input widget, and I picked it on purpose. It's zero JavaScript weight, it's impossible to mistake for a real login, and it makes the trade obvious: I'm asking for a name, you're typing one in, it goes into your browser. A styled modal with a shiny "Sign in" button would suggest something is happening on a server. Nothing is.

What's next

A real counter on each post. The ntfy push is great for me but it's invisible to everyone else: right now the +1 lands on my phone and then disappears into the ether. Aggregating the count per post, so the button can show something like "you and 7 others +1'd this", needs a real endpoint with storage behind it. Probably a small Cloudflare Worker with a KV store, on the same domain as the site. The ntfy push stays either way: that's the part that told me the button was worth building at all.