Dev.to WebDev 🛠 Dev 👁 0 📖 2 min read

A New Year's Eve wish game with no sign-up: whose midnight is it?

In Spain, people eat twelve grapes at midnight on New Year's Eve, one on each chime of the clock, and each grape stands for a month of the coming year. We turned that into a small web game for group chats: 12 Grapes With

In Spain, people eat twelve grapes at midnight on New Year's Eve, one on each chime of the clock, and each grape stands for a month of the coming year. We turned that into a small web game for group chats: 12 Grapes With Friends. You start a bunch of twelve grapes, share one link, and each friend seals a wish inside a grape. Nobody can open them until midnight.

It is free and has no sign-up. That one decision shaped most of the front end, so here are the parts that took the most thought.

Whose midnight is it?

Friends in a group chat are rarely in the same time zone. If every visitor used their own clock, the grapes would open at twelve different moments.

So midnight belongs to the person who started the bunch. When the bunch is created, the browser works out the next January 1 at 00:00 in local time and stores it as a timestamp with the bunch:

function nextMidnight() {
  var n = new Date();
  return new Date(n.getFullYear() + 1, 0, 1, 0, 0, 0, 0).getTime();
}

Everyone who opens the link counts down to that same instant. A friend in another city sees the wishes open when it is midnight for the owner, not for them.

Owning something without an account

There is no login, so "this bunch is mine" has to live somewhere else. The browser that created the bunch is remembered as its owner. For people who start on a laptop and want to open the wishes on a phone, the owner can ask for a private link. It is the normal share link with a key after the #, so the key is not sent to the server as part of the page request. The interface tells the owner plainly not to post that link in the chat.

Twelve slots, three per friend

Each grape is a month. A friend picks an empty month, chooses what kind of wish it is (luck, love, money or adventure, each with its own colour) and writes one line. One friend can fill at most three grapes, which leaves room for the rest of the group and keeps one keen person from filling the whole clock.

Sharing that works in a group chat

The share button uses navigator.share when the browser has it and falls back to copying the invite text to the clipboard. The picture cards for stories are drawn on a 1080 × 1920 canvas, turned into a PNG with toBlob, and shared as a file when navigator.canShare says files are allowed.

Small things

  • A practice mode lights one grape per chime so you can rehearse. The real chimes in Madrid come about three seconds apart.
  • The confetti is skipped when prefers-reduced-motion is set.
  • The game's front end is plain JavaScript, with no UI framework.

If your group wants to try it this December 31, the game is here: 12grapesforfriends.com. The site also has a short guide to the 12 grapes tradition.

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.