<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Yuriy Stasyuk</title>
    <description>The latest articles on DEV Community by Yuriy Stasyuk (@ystasyuk).</description>
    <link>https://dev.to/ystasyuk</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4207478%2F3ccba585-9160-4090-ab68-de3b7488fec4.png</url>
      <title>DEV Community: Yuriy Stasyuk</title>
      <link>https://dev.to/ystasyuk</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ystasyuk"/>
    <language>en</language>
    <item>
      <title>The Little Markdown Builder Behind My Kids' Element Name Guides</title>
      <dc:creator>Yuriy Stasyuk</dc:creator>
      <pubDate>Wed, 11 Nov 2026 18:20:40 +0000</pubDate>
      <link>https://dev.to/ystasyuk/the-little-markdown-builder-behind-my-kids-element-name-guides-2934</link>
      <guid>https://dev.to/ystasyuk/the-little-markdown-builder-behind-my-kids-element-name-guides-2934</guid>
      <description>&lt;p&gt;Elemon is a periodic table card game I made for my sons. Every element is a card and every move is a true fact. Over time the site grew a /learn/ section with guides for kids and parents: all 118 element names, why gold is Au, how to teach element names in elementary school, that kind of thing.&lt;/p&gt;

&lt;p&gt;Those guides are plain Markdown in &lt;code&gt;content/learn/*.md&lt;/code&gt;. One Node script, &lt;code&gt;tools/build-learn.mjs&lt;/code&gt;, turns them into static HTML. No framework, and the pages need no JavaScript to read. This post is about the parts of that script I'd build again.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fnm3prr6elz10ght88iga.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fnm3prr6elz10ght88iga.jpg" alt="A small wooden gadget on a purple-and-gold desk, with blank manuscript pages going in and illustrated booklets coming out" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;A little desktop builder turning blank pages into illustrated guides.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Front matter that errors loudly
&lt;/h2&gt;

&lt;p&gt;Each guide starts with a small front matter block. Here's the one for the gold page:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;slug&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;why-is-gold-au-element-symbols-that-dont-match&lt;/span&gt;
&lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Why Is Gold Au? 11 Odd Element Symbols, for Kids&lt;/span&gt;
&lt;span class="na"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Why is gold Au? The 11 element symbols that don't match their names&lt;/span&gt;
&lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Why is gold Au and iron Fe? A kid-friendly guide to ...&lt;/span&gt;
&lt;span class="na"&gt;short&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;The old Latin and German names hiding behind Na, K, Fe, ...&lt;/span&gt;
&lt;span class="na"&gt;published&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2026-11-09&lt;/span&gt;
&lt;span class="na"&gt;modified&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2026-11-09&lt;/span&gt;
&lt;span class="na"&gt;byline&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;dad&lt;/span&gt;
&lt;span class="na"&gt;toc&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;none&lt;/span&gt;
&lt;span class="na"&gt;faq&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;A few more questions&lt;/span&gt;
&lt;span class="na"&gt;cards&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Na, K, Fe, Au&lt;/span&gt;
&lt;span class="na"&gt;hero_element&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;gold&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The parser is about a dozen lines. It splits on the &lt;code&gt;---&lt;/code&gt; fences and reads &lt;code&gt;key: value&lt;/code&gt; pairs. The checks after it are where the value is. A guide with no slug, title, h1, description, short, published or modified date fails the build. So does a title over 62 characters, a description outside 140 to 162 characters, or the word "free" anywhere in a title. Search engines cut long titles off, and I'd rather find out at build time.&lt;/p&gt;

&lt;h2&gt;
  
  
  The names table can't have a gap
&lt;/h2&gt;

&lt;p&gt;The element names guide has a table of all 118 elements with a say-it spelling and what each name comes from. I didn't want 118 rows of hand-written HTML, so the data lives in &lt;code&gt;content/element-names.json&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"H"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"HY-druh-jun"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Greek words for *water-maker*: burn it and you get water"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"He"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"HEE-lee-um"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"*Helios*, the Greek word for the Sun, where it was spotted first"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A &lt;code&gt;{{element-names}}&lt;/code&gt; placeholder in the Markdown expands into the full table. The builder walks the same element list the game uses, sorted by atomic number, and if any symbol is missing from the JSON it throws. That one check is why I trust the table. A typo in a key stops the build, so the live table never ships with a hole in it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fuoatvu5dyffreu44abh1.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fuoatvu5dyffreu44abh1.jpg" alt="A stack of lined manuscript pages, a small purple-and-gold robot, and illustrated guide pages showing the real element symbols H, He, and Au" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Manuscript pages becoming illustrated guides for H, He, and Au.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Symbol origins get the same treatment. Gold's row says "an old English word; Au is from Latin &lt;em&gt;aurum&lt;/em&gt;." Lead's says Pb is from Latin &lt;em&gt;plumbum&lt;/em&gt;. Tungsten's says W is from German &lt;em&gt;Wolfram&lt;/em&gt;. Each name row links to that element's card, so a kid who reads "Au is from aurum" is one click from the gold card.&lt;/p&gt;

&lt;h2&gt;
  
  
  The header card is the real card
&lt;/h2&gt;

&lt;p&gt;I wanted each guide to open with an actual Elemon card instead of stock art. So &lt;code&gt;hero_element: gold&lt;/code&gt; (a symbol or a name both work) puts gold's card in the page header.&lt;/p&gt;

&lt;p&gt;The trick is that the builder doesn't have its own copy of the card. It loads the browser files the game already ships, &lt;code&gt;data.js&lt;/code&gt;, &lt;code&gt;facts.js&lt;/code&gt;, &lt;code&gt;types.js&lt;/code&gt;, &lt;code&gt;holo.js&lt;/code&gt; and &lt;code&gt;dex-show.js&lt;/code&gt;, into a Node &lt;code&gt;vm&lt;/code&gt; context and calls the same &lt;code&gt;face()&lt;/code&gt; function the Elemondex uses:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;ctx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;vm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;runInNewContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;readFileSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`${root}site/js/data.js`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"utf8"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"facts.js"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"types.js"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"holo.js"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"dex-show.js"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="n"&gt;vm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;runInNewContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;readFileSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`${root}site/js/${f}`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"utf8"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;SHOW&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ElemonShow&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The front of the header card is that face. The back shows the element's number, symbol, family, type and three facts from &lt;code&gt;facts.js&lt;/code&gt;. A small script adds the tilt and lets kids drag or tap to turn it over. When I change a card in the game, every guide that uses it picks up the change on the next build. A hero element that isn't a real element throws, and so does a page that doesn't open with a paragraph, because the card sits next to that opening answer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Old #links keep working
&lt;/h2&gt;

&lt;p&gt;Most of these guides have been rewritten at least once, and headings changed. Old links like &lt;code&gt;#five-activities&lt;/code&gt; could already be sitting in someone's notes or a class handout, and I didn't want them landing at the top of the page.&lt;/p&gt;

&lt;p&gt;Two things handle it. A heading can pin its id with &lt;code&gt;## Heading text {#some-id}&lt;/code&gt;, so I can reword the heading and keep the anchor. For headings that got renamed or removed, &lt;code&gt;content/learn-anchors.json&lt;/code&gt; maps old ids to new ones, or to &lt;code&gt;null&lt;/code&gt; when the section is gone:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"best-periodic-table-games-for-kids"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"how-did-i-pick-these-games"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"how-i-picked-them"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"the-quick-comparison"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The builder drops an empty &lt;code&gt;&amp;lt;span id="old-id"&amp;gt;&lt;/code&gt; right before the heading it moved to, or before the first section when there's nowhere better. Right now that file covers 112 old ids across 16 guides.&lt;/p&gt;

&lt;h2&gt;
  
  
  Fewer template tells
&lt;/h2&gt;

&lt;p&gt;I wanted the guides to read like someone wrote them, so most of the extra blocks are opt-in per page. A table of contents only shows up by default on pages with five or more H2s. FAQ schema only exists if the page has the heading named in &lt;code&gt;faq:&lt;/code&gt;, so there's no identical FAQ box stapled to the bottom of everything. Even the "When you're ready" line at the end of the parent guides rotates its links based on a hash of the slug, so two pages next to each other don't end the same way.&lt;/p&gt;

&lt;p&gt;The hub has one rule of its own. Every guide has to be placed in exactly one section, and the script throws if a guide is missing or listed twice. With a new kids' story planned every other day, that catches the "forgot to add it to the hub" mistake before it ships.&lt;/p&gt;

&lt;p&gt;If you want to see the output, the gold page lives under &lt;a href="https://elemon.win/learn/" rel="noopener noreferrer"&gt;elemon.win/learn/&lt;/a&gt;. Drag the card in the header.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>node</category>
      <category>webdev</category>
      <category>seo</category>
    </item>
    <item>
      <title>A Black Screen Ate a Kid's Screen Time: Billing Play by the Second in a Learning App</title>
      <dc:creator>Yuriy Stasyuk</dc:creator>
      <pubDate>Sun, 01 Nov 2026 18:14:28 +0000</pubDate>
      <link>https://dev.to/ystasyuk/a-black-screen-ate-a-kids-screen-time-billing-play-by-the-second-in-a-learning-app-168k</link>
      <guid>https://dev.to/ystasyuk/a-black-screen-ate-a-kids-screen-time-billing-play-by-the-second-in-a-learning-app-168k</guid>
      <description>&lt;p&gt;DadSchool is a home learning site I built for my kids, grades 1 to 5, at &lt;a href="https://dadschool.yuriystasyuk.com" rel="noopener noreferrer"&gt;dadschool.yuriystasyuk.com&lt;/a&gt;. They pass tests, unlock achievements, and each achievement is worth 10 points. One point buys one minute of games or parent-picked videos. The promise on the landing page is that points are spent only once play starts.&lt;/p&gt;

&lt;p&gt;In October a kid reported that the slingshot game went black and their gems drained anyway. They were right, and the fix touched every game in the arcade.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fiu8ytyx7hnk64z6cjlk3.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fiu8ytyx7hnk64z6cjlk3.jpg" alt="A dark blank tablet on a wooden desk beside a small timer, an hourglass, a mug, and a blank lined page" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;A dark tablet sitting beside timers and a blank notes page.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How it was billing
&lt;/h2&gt;

&lt;p&gt;The front end is a Next.js static export on Cloudflare Pages. Points and progress live in a Cloudflare Worker with D1. Spending goes through &lt;code&gt;start&lt;/code&gt;, &lt;code&gt;checkpoint&lt;/code&gt; and &lt;code&gt;end&lt;/code&gt; routes for each session.&lt;/p&gt;

&lt;p&gt;The arcade billed by wall-clock time from when a game mounted. That leaked in four places:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Where&lt;/th&gt;
&lt;th&gt;What happened&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Slingshot game loading&lt;/td&gt;
&lt;td&gt;Billing started on the iframe &lt;code&gt;load&lt;/code&gt; event, before about 3 MB of game had finished loading&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Slingshot game crash&lt;/td&gt;
&lt;td&gt;A lost WebGL context or an error in Phaser's loop leaves a black or frozen canvas, and the clock kept going&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Hidden tab&lt;/td&gt;
&lt;td&gt;Countdowns in Snake, Flappy Birdy and Doodle Jumpy kept ticking in the background&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Snake game over&lt;/td&gt;
&lt;td&gt;Billing continued until the kid pressed Continue&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fgqwv7hfwesfbmeggcrop.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fgqwv7hfwesfbmeggcrop.jpg" alt="A wooden clock beside a short row of five colorful session beads and an open grid notebook" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;A clock and a row of beads standing in for play-by-the-second sessions.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Make each game say when it's playing
&lt;/h2&gt;

&lt;p&gt;The fix started with a contract. All five arcade games now report play and pause through an &lt;code&gt;onPlayingChange&lt;/code&gt; prop and count only visible play time. The reward route runs its billable clock only while the game says it's being played and the page is visible. When a game ends, the route bills the smaller of the game's own count and its clock.&lt;/p&gt;

&lt;p&gt;Brick Breakout was already frame-driven, so it only needed to report. The hard one was the slingshot game, which is a third-party Phaser game running in an iframe that I can't easily rewire.&lt;/p&gt;

&lt;h2&gt;
  
  
  A heartbeat from inside the iframe
&lt;/h2&gt;

&lt;p&gt;So I added a small bridge script inside the frame. It wraps Phaser's update function to note when the last frame actually ran, and posts a heartbeat to the parent once a second:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;originalUpdate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;game&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;update&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;game&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;update&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;lastFrameAt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;originalUpdate&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;this&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;setInterval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'heartbeat'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;ready&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="s1"&gt;'Preloader'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;frameAgeMs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;lastFrameAt&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;lastFrameAt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;paused&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;!!&lt;/span&gt;&lt;span class="n"&gt;game&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;paused&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;contextLost&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;contextLost&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;hidden&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;visibilityState&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s1"&gt;'hidden'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;frameAgeMs&lt;/code&gt; is the useful field. A Phaser crash doesn't fire anything nice. The loop just stops, so the age of the last frame keeps growing. A &lt;code&gt;webglcontextlost&lt;/code&gt; listener on the canvas covers the other kind of black screen.&lt;/p&gt;

&lt;p&gt;The wrapper on the parent side turns heartbeats into a state:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a frame older than 3 seconds is a bad heartbeat&lt;/li&gt;
&lt;li&gt;three bad heartbeats in a row means stuck&lt;/li&gt;
&lt;li&gt;no heartbeat for 6 seconds means the iframe itself is gone&lt;/li&gt;
&lt;li&gt;loading gets 60 seconds before the kid is offered a retry&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The clock starts when the game's menu is up, not when the iframe loads. When it gets stuck, the overlay says "Uh-oh, the game got stuck," tells the kid the gems stopped counting when it froze, and offers a reload that retries with the canvas renderer instead of WebGL.&lt;/p&gt;

&lt;p&gt;The local test ran against a local Worker with a test student. We froze Phaser's loop on purpose and the stuck screen showed up in about 5 seconds with the countdown frozen. That run billed 31 seconds against 32 on screen, out of 52 seconds of wall time. A Snake run with a simulated hidden page billed 45 seconds out of about 73.&lt;/p&gt;

&lt;h2&gt;
  
  
  The server was already half right
&lt;/h2&gt;

&lt;p&gt;The Worker doesn't trust the browser's elapsed time either. At every checkpoint it bills the smallest of three numbers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;deltaSeconds&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="n"&gt;clientDeltaSeconds&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;                  &lt;span class="c1"&gt;// what the browser reports&lt;/span&gt;
  &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ceil&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;serverDeltaSeconds&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;1.2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// wall time since last checkpoint, plus 20% slack&lt;/span&gt;
  &lt;span class="n"&gt;maxBillableSeconds&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;                  &lt;span class="c1"&gt;// what the balance can cover&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(Trimmed from the real function.) That cap meant no Worker change was needed for this bug. The server could stop a client from billing more than real time, but it had no way to know the real time was spent staring at a black rectangle. Only the game could know that, which is why the fix lives in the browser and the cap lives on the server.&lt;/p&gt;

&lt;h2&gt;
  
  
  Videos have their own edge cases
&lt;/h2&gt;

&lt;p&gt;Videos check in every 30 seconds and whenever the player goes from playing to not playing. On &lt;code&gt;visibilitychange&lt;/code&gt; to hidden and on &lt;code&gt;pagehide&lt;/code&gt;, the page sends a checkpoint with &lt;code&gt;keepalive: true&lt;/code&gt; so the request survives the tab closing. The library re-reads the real balance on &lt;code&gt;pageshow&lt;/code&gt;, so coming back with the browser back button shows what was actually billed.&lt;/p&gt;

&lt;p&gt;Each video session also stores a &lt;code&gt;client_instance_id&lt;/code&gt;. If a second tab tries to play the same video, the Worker returns a 409 telling the kid it's playing somewhere else and to try again in about 90 seconds, which is when an abandoned session counts as stale.&lt;/p&gt;

&lt;p&gt;My old "playing" signal measured whether a component had mounted. The new one measures whether frames are being drawn on a visible page, and that's the one the kids get billed by now.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>cloudflare</category>
      <category>webdev</category>
      <category>gamedev</category>
    </item>
    <item>
      <title>One "Send to AI" Button, Four Chatbots, Four Different Workarounds</title>
      <dc:creator>Yuriy Stasyuk</dc:creator>
      <pubDate>Sat, 31 Oct 2026 17:12:51 +0000</pubDate>
      <link>https://dev.to/ystasyuk/one-send-to-ai-button-four-chatbots-four-different-workarounds-o2o</link>
      <guid>https://dev.to/ystasyuk/one-send-to-ai-button-four-chatbots-four-different-workarounds-o2o</guid>
      <description>&lt;p&gt;On paper this is a tiny feature. Put the prompt in a URL, open a new tab, done.&lt;/p&gt;

&lt;p&gt;In practice each chatbot needed its own handling.&lt;/p&gt;

&lt;p&gt;The app is Cover Styles (&lt;a href="https://covers.yuriystasyuk.com" rel="noopener noreferrer"&gt;https://covers.yuriystasyuk.com&lt;/a&gt;), a free library of book cover styles where each reference cover comes with a prompt. You pick a cover, hit ChatGPT or Gemini or Grok or Meta AI, and the idea is that you land in that chatbot with the prompt ready and the cover image available as a style reference. Getting text across was easy. Getting the image across is where it got weird.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F0rn5tsh7fqahietxi0hu.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F0rn5tsh7fqahietxi0hu.jpg" alt="Four different cards arranged around a single wooden button, each with a distinct workaround: a paper clip, a postmark, a folded corner, and a wax seal" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Four workaround cards around one central button.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The easy half: prompts in the URL
&lt;/h2&gt;

&lt;p&gt;Three of the four take a query parameter, and one of them names it differently:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="no"&gt;AIS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"chatgpt"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"ChatGPT"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;u&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;q&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"https://chatgpt.com/?q="&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;q&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s2"&gt;"&amp;amp;hints=image"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"gemini"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Gemini"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="n"&gt;u&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;q&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"https://gemini.google.com/app?q="&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;q&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"grok"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;    &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Grok"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;    &lt;span class="n"&gt;u&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;q&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"https://grok.com/?q="&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;q&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"meta"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;    &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Meta AI"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;u&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;q&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"https://www.meta.ai/?prompt="&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;q&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(Trimmed from the real code, which also has colors and icons.)&lt;/p&gt;

&lt;p&gt;Two gotchas showed up fast.&lt;/p&gt;

&lt;p&gt;URLs get long. A style prompt plus a list of reference covers can blow past what you want in a query string, so the text is capped at 1,800 characters. The reference list goes at the end and gets trimmed one cover at a time until it fits in about 1,000 characters or only three are left. If the prompt itself is still too long, it gets cut at a word boundary and ends with an ellipsis.&lt;/p&gt;

&lt;p&gt;Desktop Gemini is its own story. More on that below.&lt;/p&gt;

&lt;h2&gt;
  
  
  Don't send a prompt with holes in it
&lt;/h2&gt;

&lt;p&gt;The prompts are templates with &lt;code&gt;{TITLE}&lt;/code&gt; and &lt;code&gt;{AUTHOR}&lt;/code&gt; in them. Before I added a check, nothing stopped you from sending "Title {TITLE} in yellow-gold display serif" straight to a chatbot, and a model can take that literally.&lt;/p&gt;

&lt;p&gt;So there's a gate. Every send goes through a function that checks both fields first. If one is empty, it opens a little sheet asking for title and author, remembers the send you tried, and runs it once both are filled in. The comment in the code says it plainly: never send a prompt with placeholders left in it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The hard half: images and the clipboard
&lt;/h2&gt;

&lt;p&gt;None of these chatbots take an image through the URL. What you can do is put the image on the clipboard so the user just pastes it. That's where I spent most of the time.&lt;/p&gt;

&lt;p&gt;Lesson one: &lt;strong&gt;&lt;code&gt;navigator.clipboard.write()&lt;/code&gt; has to happen inside the click.&lt;/strong&gt; Browsers only let you write to the clipboard during a user gesture. If you &lt;code&gt;await&lt;/code&gt; a fetch first and then write, the gesture is gone and the write fails.&lt;/p&gt;

&lt;p&gt;The way around it is that &lt;code&gt;ClipboardItem&lt;/code&gt; accepts a Promise of a Blob, not only a Blob. So you call &lt;code&gt;write()&lt;/code&gt; right away, synchronously, and hand it a promise that resolves later:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;writeImage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;src&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// must be called synchronously inside the click handler&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nf"&gt;canClipImg&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"no clipboard images"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;BLOBS&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;src&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nf"&gt;encodeImg&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;src&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"image/png"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// a ready Blob if pre-encoded, else Promise&amp;lt;Blob&amp;gt;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"text/plain"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Blob&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"text/plain"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;navigator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;clipboard&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ClipboardItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Lesson two: &lt;strong&gt;Chrome only accepts PNG here.&lt;/strong&gt; The covers are stored as WebP to keep the site light. Chrome only accepts &lt;code&gt;image/png&lt;/code&gt; in a ClipboardItem, so each image is fetched from the same origin (so the canvas isn't tainted by CORS), drawn onto a canvas, and exported with &lt;code&gt;toBlob(..., "image/png")&lt;/code&gt;. If that fetch fails, there's a fallback that loads it as a CORS-enabled &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt;, which works because the site sends &lt;code&gt;Access-Control-Allow-Origin: *&lt;/code&gt; on its assets. Encoded PNGs are cached per image so the second click is instant.&lt;/p&gt;

&lt;p&gt;Lesson three: &lt;strong&gt;feature-detect, then fall back to text.&lt;/strong&gt; If &lt;code&gt;navigator.clipboard.write&lt;/code&gt;, &lt;code&gt;ClipboardItem&lt;/code&gt; or a secure context is missing, the app skips the image and copies the prompt plus a link to the cover instead. A link to a reference image is worse than the image, but it beats a broken button.&lt;/p&gt;

&lt;h2&gt;
  
  
  So each chatbot got its own mode
&lt;/h2&gt;

&lt;p&gt;Once I accepted that, the code got a small lookup table:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="no"&gt;AI_MODE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;chatgpt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"image"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;gemini&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"text"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;grok&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"image-first"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;meta&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"text"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="no"&gt;IS_MOBILE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="no"&gt;AI_MODE&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;gemini&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"image-steps"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;ChatGPT:&lt;/strong&gt; copy the image, open the tab with the prompt in the URL. You paste the image and go.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Grok:&lt;/strong&gt; copy the image first while the current tab still has focus, then open Grok. There's a 2.5 second timer so the tab still opens even if the copy is slow.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Meta AI:&lt;/strong&gt; text mode. The prompt goes in the URL and onto the clipboard, and the text includes the cover link.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Gemini on desktop:&lt;/strong&gt; this one became a two-step sheet. The code comment says it ignores &lt;code&gt;?q=&lt;/code&gt; and won't open image links, so the app copies the cover image, opens Gemini, and then shows a "Step 2 of 2" with a Copy prompt button for when you come back. Not pretty. It works.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fk9pnes9zxma0zwmqxbru.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fk9pnes9zxma0zwmqxbru.jpg" alt="Four illustrated lighthouse cards in different styles, showing four different results from the same subject" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Four different lighthouse results from the same idea.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Android had one more surprise
&lt;/h2&gt;

&lt;p&gt;On Android, a link to Gemini or Meta AI may open their app instead of the browser, and the app may drop the query parameter. For those two, the app builds an &lt;code&gt;intent://&lt;/code&gt; URL that asks for Chrome specifically, with the normal URL as the fallback:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;intent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"intent://"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;/^&lt;/span&gt;&lt;span class="n"&gt;https&lt;/span&gt;&lt;span class="o"&gt;?:&lt;/span&gt;\&lt;span class="o"&gt;/&lt;/span&gt;\&lt;span class="c1"&gt;//, "") +&lt;/span&gt;
  &lt;span class="s2"&gt;"#Intent;scheme=https;package=com.android.chrome;S.browser_fallback_url="&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
  &lt;span class="nf"&gt;encodeURIComponent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s2"&gt;";end"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  If you're building something similar
&lt;/h2&gt;

&lt;p&gt;Plan for the clipboard from the first commit, and test the real click path, because the gesture rule bites the moment you add an &lt;code&gt;await&lt;/code&gt;. Expect each chatbot's URL handling to change under you, and keep the per-service behavior in one small table so it's a one-line fix when it does. And always keep a plain-text fallback.&lt;/p&gt;

&lt;p&gt;The whole thing is live and free at &lt;a href="https://covers.yuriystasyuk.com" rel="noopener noreferrer"&gt;https://covers.yuriystasyuk.com&lt;/a&gt; if you want to see the button in action. Fair warning, it might send you down a romantasy foil rabbit hole.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>frontend</category>
      <category>ai</category>
    </item>
    <item>
      <title>One Data File, a Pile of Build Scripts and a Domain Move: Notes From Building Elemon</title>
      <dc:creator>Yuriy Stasyuk</dc:creator>
      <pubDate>Thu, 29 Oct 2026 17:28:15 +0000</pubDate>
      <link>https://dev.to/ystasyuk/one-data-file-a-pile-of-build-scripts-and-a-domain-move-notes-from-building-elemon-al7</link>
      <guid>https://dev.to/ystasyuk/one-data-file-a-pile-of-build-scripts-and-a-domain-move-notes-from-building-elemon-al7</guid>
      <description>&lt;p&gt;Elemon is a free browser card game I built with my sons. Every one of the 118 elements is a monster card, and every move on a card is a true fact about that element. Kids play the computer or a friend, and there's no account, download or ads.&lt;/p&gt;

&lt;p&gt;The game part is fun to talk about. This post is about the boring parts that ended up mattering more: where the element data lives, how the static pages stay in sync with it, how I test facts, and what I did when the game moved to its own domain in late October.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fjsylfufk1891fz6s3f0q.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fjsylfufk1891fz6s3f0q.jpg" alt="A purple-and-gold box labeled data on a desk, surrounded by rolled script scrolls and a few cute element cards" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;One data box beside a pile of build-script scrolls and element cards.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fwe4t8391ndlgtmpjyam3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fwe4t8391ndlgtmpjyam3.png" alt="The home page on a phone" width="780" height="1688"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;The home page on a phone. Everything on it comes out of one data file.&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  All 118 elements live in one file
&lt;/h2&gt;

&lt;p&gt;There's a single file, &lt;code&gt;data.js&lt;/code&gt;, with one object per element. It sets &lt;code&gt;window.ELEMON&lt;/code&gt; to an array of 118 records and runs about 5,000 lines. Here's sodium, trimmed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="s2"&gt;"z"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;11&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="s2"&gt;"sym"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Na"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="s2"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Sodium"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="s2"&gt;"epithet"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"the Salt Lamp"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="s2"&gt;"family"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Alkali"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="s2"&gt;"combat"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Blast"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="s2"&gt;"attacks"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="s2"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Salt Bond"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="s2"&gt;"effect"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"team move: hits harder when Chlorine, its bond buddy, is on your team."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="s2"&gt;"why"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Sodium grabs onto chlorine and the two atoms lock together as the same table salt you eat."&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="s2"&gt;"bonds"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;"with"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Cl"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"as"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Salt"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="s2"&gt;"period"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="s2"&gt;"file"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"011-Na-Sodium.jpg"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;why&lt;/code&gt; field is the one I care about. That's the sentence a kid reads when the move fires, so it's the sentence that has to be true.&lt;/p&gt;

&lt;p&gt;Because it's a plain script that assigns to &lt;code&gt;window&lt;/code&gt;, the browser loads it directly with no bundler. Node scripts load it too, with &lt;code&gt;new Function("window", src)&lt;/code&gt; or &lt;code&gt;vm.runInNewContext&lt;/code&gt;, so the same file feeds the game, the build tools and the tests without a second copy.&lt;/p&gt;

&lt;p&gt;The catalog builder that feeds the game server starts like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;cards&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"window"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;src&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s2"&gt;"\nreturn window.ELEMON;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isArray&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cards&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="n"&gt;cards&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="mi"&gt;118&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"expected 118 cards, got "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cards&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;cards&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first 20 elements also get a separate &lt;code&gt;elements-1-20.json&lt;/code&gt; with quick facts for their own pages (state at room temperature, who discovered it, four facts). Its &lt;code&gt;_about&lt;/code&gt; field notes that the discovery dates were cross-checked against Wikipedia's "Discovery of chemical elements" page in October 2026.&lt;/p&gt;

&lt;h2&gt;
  
  
  Every generator has a --check mode
&lt;/h2&gt;

&lt;p&gt;The site is static. There's no framework and no build step on deploy. Instead there's a folder of small Node scripts that read the data and write HTML that gets committed:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the Worker's card catalog&lt;/li&gt;
&lt;li&gt;the &lt;code&gt;/learn/&lt;/code&gt; guides, from markdown files&lt;/li&gt;
&lt;li&gt;one page per element for the first 20, plus the sitemap&lt;/li&gt;
&lt;li&gt;the prerendered Elemondex and home page&lt;/li&gt;
&lt;li&gt;the teacher page and the printables pages&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each one takes &lt;code&gt;--check&lt;/code&gt;, which rebuilds in memory, diffs the result against what's committed, and exits 1 if anything differs. CI runs all of them on every pull request. So if I fix a fact in &lt;code&gt;data.js&lt;/code&gt; and forget to rerun the builders, the PR goes red before the wrong version of the fact can sit on some page nobody remembered.&lt;/p&gt;

&lt;p&gt;This is the cheapest fact-checking tool I have. A fact gets fixed in one place, and the build refuses to ship until every page agrees.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tests that know some chemistry
&lt;/h2&gt;

&lt;p&gt;The rules engine has 22 tests that run with plain &lt;code&gt;node --test&lt;/code&gt;, no test framework. Most are game logic, like switches happening before attacks or a match ending at three knockouts. A few pin real chemistry:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"real chemistry drives the stats"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;equal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;STATS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tiers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;hp&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"osmium is the densest element"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;equal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;STATS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;H&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tiers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;spd&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"hydrogen is the lightest"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;equal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;STATS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Cs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tiers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pow&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"caesium explodes in water"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;equal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;STATS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Og&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tiers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;hp&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"superheavies fall apart in a blink"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Stats come from a formula over density, reactivity and atomic weight, and formulas drift when you tune them. These asserts are tripwires. If osmium ever stops being tough, a test tells me before a kid does.&lt;/p&gt;

&lt;p&gt;The tests also lock the type counts (12 Blast, 7 Life, 5 Acid and so on, adding up to 118), and they check that every card's three moves do three different things.&lt;/p&gt;

&lt;p&gt;Not every fact can be a test. In October I had to fix a nitrogen fact (it's about 78% of the air) and pull some claims about mixing elements that the game couldn't back up. Those were plain edits to the data file, and the &lt;code&gt;--check&lt;/code&gt; builders made sure every page picked them up.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting a JavaScript game indexed
&lt;/h2&gt;

&lt;p&gt;The interactive parts of the home page and the Elemondex are drawn by JavaScript. Crawlers and no-JS readers would see an empty shell, so two of the generators prerender those sections into the raw HTML from the same data. When the page loads, the script swaps in identical markup, so nothing on screen changes.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;/learn/&lt;/code&gt; guides are markdown with a tiny supported subset: headings, paragraphs, lists, pipe tables, bold and links. If a guide has a "Frequently asked questions" section, the builder turns those questions into FAQPage JSON-LD too, and they're visible on the page.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fv9twamlj00ijcpqyhk7c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fv9twamlj00ijcpqyhk7c.png" alt="A learn guide on a phone" width="780" height="1688"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;A learn guide on a phone. It started as a markdown file in the repo.&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Moving to elemon.win without breaking links
&lt;/h2&gt;

&lt;p&gt;Elemon used to live on a subdomain of my personal site. In late October it moved to its own domain, elemon.win. One PR changed the canonicals, the sitemap and robots.txt, and added a Pages Function that sends the old host to the new one:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9nyujw25dilp045g0oeu.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9nyujw25dilp045g0oeu.jpg" alt="An old wooden sign set aside on the left, and a new gold-and-violet hanging sign on the right, with a box of element cards on the desk" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;An old sign set aside beside a new gold-and-violet sign.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// 301 old hosts to the canonical domain, keeping path + query.&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;OLD&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="no"&gt;OLD_SUBDOMAIN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"www.elemon.win"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// the old host is a plain string in the real file&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;onRequest&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;next&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="no"&gt;URL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;OLD&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;has&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;hostname&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;redirect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"https://elemon.win"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pathname&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;search&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;301&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Keeping the path matters. A teacher who bookmarked the printables page on the old subdomain lands on the same printables page on the new domain, and every old URL in search results points at its exact new page.&lt;/p&gt;

&lt;p&gt;Two small gotchas. The redirect only works while the old hostname still points at the Pages project, so the old DNS record and custom domain have to stay in place even though nothing is served from them. And the &lt;code&gt;*.pages.dev&lt;/code&gt; address still serves the site directly, so a host-scoped rule in &lt;code&gt;_headers&lt;/code&gt; sends &lt;code&gt;X-Robots-Tag: noindex&lt;/code&gt; there to keep the duplicate out of search.&lt;/p&gt;

&lt;h2&gt;
  
  
  Multiplayer with no game server to babysit
&lt;/h2&gt;

&lt;p&gt;Two kids on two phones need one shared referee, and the table should vanish when they leave. I didn't want another server to keep running. The setup I landed on is a Worker with Durable Objects: one object per table name, plus a lobby object that lists open tables. Sockets use the WebSocket hibernation API, which keeps idle tables cheap, and when a table closes, its object wipes its own storage.&lt;/p&gt;

&lt;p&gt;Pages can't define Durable Object classes, so the rooms live in a sibling Worker and the static site talks to it over HTTPS and WebSockets. Solo matches against the computer run in the same Worker.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reviewing generated art
&lt;/h2&gt;

&lt;p&gt;The card art is AI-generated, and generated art gets details wrong. So the repo has a small review page that shows every card with a "Mistake, regenerate" checkbox. It exports the flagged cards as a text file, and that list is what gets redone.&lt;/p&gt;

&lt;p&gt;If you want to see how the data turns into a game, it's at &lt;a href="https://elemon.win" rel="noopener noreferrer"&gt;elemon.win&lt;/a&gt;. The Elemondex is all 118 records, laid out the way the periodic table lays them out.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>cloudflare</category>
      <category>gamedev</category>
    </item>
    <item>
      <title>Three CSVs In, 1,272 Food Pages Out: PregNut's Boring Static Build</title>
      <dc:creator>Yuriy Stasyuk</dc:creator>
      <pubDate>Tue, 27 Oct 2026 17:29:45 +0000</pubDate>
      <link>https://dev.to/ystasyuk/three-csvs-in-1272-food-pages-out-pregnuts-boring-static-build-2il4</link>
      <guid>https://dev.to/ystasyuk/three-csvs-in-1272-food-pages-out-pregnuts-boring-static-build-2il4</guid>
      <description>&lt;p&gt;PregNut is a free pregnancy food lookup I've been building since 2018. You search a food and see how 100 grams of it stacks up against the daily amounts pregnancy asks for. It has 1,272 foods and 13 nutrients, and each food gets its own page.&lt;/p&gt;

&lt;p&gt;There's no database server behind it. It's an Eleventy site that builds from three CSV files and deploys to Cloudflare Pages. I like boring stacks for side projects, and this one has stayed easy to work on through three pregnancies, so here's how it fits together.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhf9e0mjo2b54x9lvur8w.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhf9e0mjo2b54x9lvur8w.jpg" alt="Three standing boards on a kitchen desk labeled foods, nutrients, and portions, each with a small watercolor food still life, beside a laptop and tea" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Three input boards labeled foods, nutrients, and portions.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F89j9xxmlx22p141wb8uh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F89j9xxmlx22p141wb8uh.png" alt="The home page. Everything on it is plain HTML from the build." width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The inputs
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;database/&lt;/code&gt; folder has three files: &lt;code&gt;FoodList.csv&lt;/code&gt;, &lt;code&gt;NutrientList.csv&lt;/code&gt; and &lt;code&gt;daily requirements.csv&lt;/code&gt;. The food list has the USDA NDB number, name, food group and a warning field. The nutrient list is long and skinny, one row per food per nutrient with a value and a unit. The requirements file has the daily reference amount for each nutrient as a label like "1000 mg" or "0.3 g."&lt;/p&gt;

&lt;p&gt;All of it comes from a fixed snapshot of the USDA's SR Legacy data. USDA's final Standard Reference release was in 2018, so the numbers are frozen. For a reference site I count that as a feature. A value doesn't change under you between builds. The cost is that newer data and current product labels can differ, and the About page says that.&lt;/p&gt;

&lt;h2&gt;
  
  
  A tiny build script instead of a dependency
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;scripts/build-fooddata.js&lt;/code&gt; reads the CSVs and writes one JSON file the site uses everywhere. I wrote a minimal CSV parser for it, small enough to read in one sitting. It handles quoted fields and doubled quotes, and it strips a byte order mark if there is one. That BOM will quietly rename your first column header if you don't strip it.&lt;/p&gt;

&lt;p&gt;The requirements file has a reference list under the main table, so the parser stops when it hits the &lt;code&gt;SourceId&lt;/code&gt; row. Reference amounts get parsed with a small regex into a number and a unit.&lt;/p&gt;

&lt;p&gt;One choice I'd make again. If the CSVs aren't present but the JSON already exists, the script prints a warning and keeps the existing JSON instead of failing. That lets a deploy work from the committed JSON alone.&lt;/p&gt;

&lt;h2&gt;
  
  
  One page per food with pagination
&lt;/h2&gt;

&lt;p&gt;Eleventy's pagination does the heavy lifting. The food page template paginates over a data file with &lt;code&gt;size: 1&lt;/code&gt;, so every item becomes its own page. The permalink is &lt;code&gt;/food/{{ food.slug }}/&lt;/code&gt;, and the slug starts with the USDA number: &lt;code&gt;/food/15151-shrimp-cooked/&lt;/code&gt;, &lt;code&gt;/food/15152-shrimp-canned/&lt;/code&gt;. Food names repeat a lot in USDA data. The number keeps every URL unique without me thinking about it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fyr7bg3bvqiar6fjfz2kw.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fyr7bg3bvqiar6fjfz2kw.jpg" alt="A large grid of small watercolor food-page cards covering a wooden table, like a library of finished pages" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;A table covered in a library of illustrated food pages.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The data file is also where per-page decisions live. Title overrides for pages that get search traffic, related blog posts, and special cases. The human milk record, for example, stays in the dataset but is labeled as a historical data record only and left out of the food listings.&lt;/p&gt;

&lt;p&gt;Units needed a helper. DHA is stored in grams and its benchmark is 0.3 g, while other nutrients are in mg or mcg. There's a small conversion function so comparisons always happen in the same unit.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fb805fuyo7allbnbsvwus.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fb805fuyo7allbnbsvwus.png" alt="A generated food page, phone-sized." width="780" height="1688"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Each page shows two columns: per 100 g, and a serving based on FDA reference amounts. Cooked shrimp shows 3 oz (85 g) next to 100 g. The 100 g column is for comparing foods. The serving column is closer to what's on a plate.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the data can't do
&lt;/h2&gt;

&lt;p&gt;The dataset has no iodine values. Rather than fake it, the site has an iodine guide and says the data is missing. Folate is shown as DFE, which isn't the same thing as the folic acid number on a prenatal label, so that gets its own guide too.&lt;/p&gt;

&lt;p&gt;PregNut is an educational reference and isn't medical advice. Every page says so in the footer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Deploys and one contact form
&lt;/h2&gt;

&lt;p&gt;A GitHub Actions workflow runs &lt;code&gt;npm run build&lt;/code&gt; and deploys with wrangler. Pushes to master go to pregnut.com. Pull requests get a preview deploy, and the link gets posted on the PR. Previews are only built for branches in the repo, and the actions are pinned to commit SHAs. The &lt;code&gt;*.pages.dev&lt;/code&gt; hosts send &lt;code&gt;X-Robots-Tag: noindex&lt;/code&gt; from &lt;code&gt;_headers&lt;/code&gt;, so Google only indexes the real domain.&lt;/p&gt;

&lt;p&gt;The one dynamic piece is &lt;code&gt;/api/contact&lt;/code&gt;, a Cloudflare Pages Function. I wanted a free email relay and picked FormSubmit, which turned out to refuse requests coming from Workers. So the function does validation, a honeypot, a timing check and rate limiting, and only then hands the browser the relay endpoint to send to. Bots that fail the checks never see it.&lt;/p&gt;

&lt;p&gt;If you want to see the output, open any food page on &lt;a href="https://pregnut.com" rel="noopener noreferrer"&gt;pregnut.com&lt;/a&gt; and view source. The numbers and the notes are right there in the HTML.&lt;/p&gt;

</description>
      <category>eleventy</category>
      <category>javascript</category>
      <category>cloudflare</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Things That Bit Me Wrapping the YouTube IFrame API for a Kids' App</title>
      <dc:creator>Yuriy Stasyuk</dc:creator>
      <pubDate>Tue, 27 Oct 2026 17:29:04 +0000</pubDate>
      <link>https://dev.to/ystasyuk/things-that-bit-me-wrapping-the-youtube-iframe-api-for-a-kids-app-2n91</link>
      <guid>https://dev.to/ystasyuk/things-that-bit-me-wrapping-the-youtube-iframe-api-for-a-kids-app-2n91</guid>
      <description>&lt;p&gt;I built WiseTube because the YouTube sidebar kept leading my kids somewhere I didn't want them. It's a free library of hand-picked learning videos that play inside my own player, with YouTube's suggestions, Shorts and autoplay-to-the-next-thing taken out.&lt;/p&gt;

&lt;p&gt;The covering-up part gets most of the attention. This post is about the smaller stuff that cost me evenings. If you're wrapping the IFrame API for anything, some of these will probably find you too.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fl2yb9bcz0zusbwvlz5k8.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fl2yb9bcz0zusbwvlz5k8.jpg" alt="A landscape video playing inside a custom cardboard-style app shell, with a laptop diagram labeled Video and Custom App Shell and the line Protected. Branded. Yours." width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;A video player sitting inside a custom app shell.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5uhlmhnfrxxiw2d6ly1w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5uhlmhnfrxxiw2d6ly1w.png" alt="The phone view, where a kid actually taps all this." width="780" height="1688"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  1. The API script can hang, so give it a deadline
&lt;/h2&gt;

&lt;p&gt;You load &lt;code&gt;https://www.youtube.com/iframe_api&lt;/code&gt; and wait for &lt;code&gt;onYouTubeIframeAPIReady&lt;/code&gt;. Most of the time it's fine. On a flaky connection it can sit there forever, and a kid staring at a spinner will go find another app.&lt;/p&gt;

&lt;p&gt;I wrap the load in a promise, cache it so it only happens once, and clear the cache if the script errors so the next try starts clean. The player also starts a 15 second timer. If &lt;code&gt;onReady&lt;/code&gt; hasn't fired by then, it shows "The film didn't load" with a retry button.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. YouTube resets your playback speed
&lt;/h2&gt;

&lt;p&gt;I save speed and volume to localStorage so a kid who likes 1.25x doesn't have to set it every time. I set the rate in &lt;code&gt;onReady&lt;/code&gt;, and that isn't enough, because YouTube can reset the rate when a film starts playing. The fix is boring. On every PLAYING state change, read &lt;code&gt;getPlaybackRate()&lt;/code&gt; and set it again if it doesn't match the saved value.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Autoplay for the chosen film still gets blocked sometimes
&lt;/h2&gt;

&lt;p&gt;I want the film a kid picked to start right away, so the player is created with &lt;code&gt;autoplay: 1&lt;/code&gt;. Browsers don't always allow it. There's no clean event for "autoplay was blocked," so after &lt;code&gt;onReady&lt;/code&gt; I wait about 1.2 seconds and check the state. If it's still UNSTARTED or CUED, I show my own big play button.&lt;/p&gt;

&lt;p&gt;That's the only autoplay in the app. When a film ends, nothing else starts on its own.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8sovi5967uvixpdb0tix.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8sovi5967uvixpdb0tix.jpg" alt="A laptop with a paused, nearly finished video, and a small token on the desk labeled ended" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;A paused player beside a token labeled ended.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Don't let callbacks restart the player
&lt;/h2&gt;

&lt;p&gt;The Player component takes &lt;code&gt;onTick&lt;/code&gt;, &lt;code&gt;onEnded&lt;/code&gt; and &lt;code&gt;onError&lt;/code&gt; from the page. If those are effect dependencies, any parent re-render can tear down the iframe and build a new one mid-film. I use React's &lt;code&gt;useEffectEvent&lt;/code&gt; for them, so the effect that mounts the player only depends on the video id, the retry count and the title.&lt;/p&gt;

&lt;p&gt;Progress gets read every 250ms for the scrub bar but only reported up every 5 seconds. Saving progress four times a second felt silly.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Validate pasted links before you trust them
&lt;/h2&gt;

&lt;p&gt;Parents can add a film by pasting a YouTube link. People paste everything: &lt;code&gt;youtu.be&lt;/code&gt; links, &lt;code&gt;/embed/&lt;/code&gt; links, &lt;code&gt;watch?v=&lt;/code&gt; links, Shorts. I parse the URL, accept the normal shapes, and reject anything under &lt;code&gt;/shorts/&lt;/code&gt; or &lt;code&gt;/live/&lt;/code&gt; with "Paste a normal YouTube link. Shorts stay out of WiseTube."&lt;/p&gt;

&lt;p&gt;Then I call YouTube's oEmbed endpoint for the link. If it doesn't come back with a title and channel name, the film doesn't get added. That catches typos, private videos and videos that can't be embedded, before a kid ever taps them.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. A PIN on a device with no server
&lt;/h2&gt;

&lt;p&gt;There are no accounts. Profiles, progress and settings sit in localStorage. The four-digit parent PIN is stored as a SHA-256 hash with a random 16-byte salt, using &lt;code&gt;crypto.subtle&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I'll be straight about what that buys. A four-digit PIN on a device the kid holds is a speed bump. It keeps a six-year-old out of the settings. A teenager with dev tools could get past it. For a free app with no backend, I'm fine with that, and I'd rather say it than pretend it's a vault.&lt;/p&gt;

&lt;p&gt;Because everything is on one device, the parent settings have an export button that downloads a &lt;code&gt;wisetube-library.json&lt;/code&gt; with profiles, PIN, added and hidden films, and progress. Import shows how many learners are in the file and asks before replacing anything.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Febc6qncawrkvx6xb9516.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Febc6qncawrkvx6xb9516.png" alt="The little-kids look. The PIN keeps them in this lane." width="780" height="1688"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Vite preview lies about routing
&lt;/h2&gt;

&lt;p&gt;The site is a static build on Cloudflare Pages. Public pages are prerendered for search. Private app routes like &lt;code&gt;/watch/:youtubeId&lt;/code&gt; and &lt;code&gt;/parent&lt;/code&gt; are rewritten to a noindex &lt;code&gt;app.html&lt;/code&gt; through &lt;code&gt;public/_redirects&lt;/code&gt;, so a refresh doesn't 404.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;vite preview&lt;/code&gt; ignores &lt;code&gt;_redirects&lt;/code&gt; and Pages' 404 behavior, so a route can look fine locally and behave differently once deployed. I test routing with &lt;code&gt;npx wrangler pages dev dist&lt;/code&gt;, which behaves like the real thing.&lt;/p&gt;

&lt;h2&gt;
  
  
  8. Tests for the catalog, too
&lt;/h2&gt;

&lt;p&gt;The video list is data, and data drifts. &lt;code&gt;npm run check&lt;/code&gt; runs TypeScript, oxlint and vitest, and the catalog tests fail if an import sneaks in a Short, a duplicate, an unknown topic, or a channel I already ruled out. That has caught more mistakes than any of my UI tests.&lt;/p&gt;

&lt;p&gt;You can try the result at &lt;a href="https://wisetube.yuriystasyuk.com" rel="noopener noreferrer"&gt;wisetube.yuriystasyuk.com&lt;/a&gt;. If you've wrapped the IFrame API and found a cleaner way around any of these, I'd love to hear it.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>youtube</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
