Files
counter/public/index.html
T
2026-11-14 17:16:57 +00:00

185 lines
9.8 KiB
HTML

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
<meta name="theme-color" content="#0b0f14">
<meta name="description" content="Counter — scan food, track calories, steps and workouts, and get meal plans.">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-title" content="Counter">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<title>Counter</title>
<link rel="manifest" href="/manifest.webmanifest">
<link rel="icon" href="/icon.svg" type="image/svg+xml">
<link rel="apple-touch-icon" href="/icon.svg">
<link rel="stylesheet" href="/styles.css">
</head>
<body>
<header class="topbar">
<div class="brand">
<svg class="brand-mark" viewBox="0 0 24 24" aria-hidden="true">
<circle cx="12" cy="12" r="9" fill="none" stroke="currentColor" stroke-width="2.4"
stroke-dasharray="42 15" stroke-linecap="round" transform="rotate(-90 12 12)"/>
</svg>
<span>Counter</span>
</div>
<div class="date-nav">
<button class="icon-btn" type="button" data-action="date-prev" aria-label="Previous day">&#8249;</button>
<button class="date-label" type="button" id="dateLabel" data-action="date-today" title="Jump to today">Today</button>
<button class="icon-btn" type="button" data-action="date-next" aria-label="Next day">&#8250;</button>
</div>
</header>
<main>
<section class="view" id="view-today"></section>
<section class="view" id="view-scan" hidden>
<div class="view-head">
<h1>Scan food</h1>
<p class="muted">Barcode or name lookup, powered by Open Food Facts.</p>
</div>
<div class="segmented" role="tablist" aria-label="Food entry method">
<button type="button" data-scan-tab="scan" class="is-active" role="tab">Scan</button>
<button type="button" data-scan-tab="search" role="tab">Search</button>
<button type="button" data-scan-tab="manual" role="tab">Manual</button>
</div>
<div class="scan-pane" id="scanPane-scan">
<div class="card">
<div class="camera-box" id="cameraBox" hidden>
<video id="camera" playsinline muted></video>
<button class="btn ghost small" type="button" data-action="stop-camera">Stop camera</button>
</div>
<button class="btn primary block" type="button" id="startCameraBtn">Start camera</button>
<p class="hint" id="cameraHint">Point the camera at a barcode.</p>
<div class="or"><span>or</span></div>
<button class="btn block" type="button" data-action="photo-scan">Take a photo of the barcode</button>
<input type="file" id="photoInput" accept="image/*" capture="environment" hidden>
<form class="row-form" id="barcodeForm" autocomplete="off">
<input name="barcode" inputmode="numeric" pattern="[0-9]*" placeholder="Type the barcode digits" aria-label="Barcode digits">
<button class="btn" type="submit">Look up</button>
</form>
</div>
<div id="scanResult"></div>
</div>
<div class="scan-pane" id="scanPane-search" hidden>
<form class="row-form" id="searchForm" autocomplete="off">
<input name="q" placeholder="e.g. greek yogurt, oat milk" aria-label="Search foods">
<button class="btn" type="submit">Search</button>
</form>
<div id="searchResults"></div>
</div>
<div class="scan-pane" id="scanPane-manual" hidden>
<form class="card form-grid" id="manualForm" autocomplete="off">
<label class="field span-2"><span>Food name</span><input name="name" maxlength="120" placeholder="Homemade chili" required></label>
<label class="field"><span>Calories</span><input name="kcal" type="number" inputmode="numeric" min="0" max="5000" required></label>
<label class="field"><span>Protein (g)</span><input name="protein_g" type="number" inputmode="decimal" min="0" max="500" step="0.1" value="0"></label>
<label class="field"><span>Carbs (g)</span><input name="carbs_g" type="number" inputmode="decimal" min="0" max="500" step="0.1" value="0"></label>
<label class="field"><span>Fat (g)</span><input name="fat_g" type="number" inputmode="decimal" min="0" max="500" step="0.1" value="0"></label>
<label class="field span-2"><span>Meal</span><select name="meal" id="manualMeal"></select></label>
<button class="btn primary span-2" type="submit">Add to day</button>
</form>
</div>
</section>
<section class="view" id="view-plan" hidden>
<div class="view-head">
<h1>Meal plan</h1>
<p class="muted">Suggestions that fit what is left of your day.</p>
</div>
<div class="card">
<label class="field"><span>Style</span><select id="planStyle"></select></label>
<p class="hint" id="planTarget"></p>
<button class="btn primary block" type="button" id="generatePlanBtn">Generate plan</button>
</div>
<div id="planList"></div>
</section>
<section class="view" id="view-you" hidden>
<div class="view-head">
<h1>You</h1>
<p class="muted">Targets are estimates built from this profile.</p>
</div>
<form class="card form-grid" id="profileForm" autocomplete="off">
<label class="field span-2"><span>Name</span><input name="name" maxlength="60" placeholder="Your name"></label>
<label class="field"><span>Sex</span>
<select name="sex"><option value="male">Male</option><option value="female">Female</option></select>
</label>
<label class="field"><span>Age</span><input name="age" type="number" inputmode="numeric" min="13" max="120" required></label>
<label class="field"><span>Height (cm)</span><input name="height_cm" type="number" inputmode="decimal" min="100" max="250" step="0.1" required></label>
<label class="field"><span>Weight (kg)</span><input name="weight_kg" type="number" inputmode="decimal" min="30" max="300" step="0.1" required></label>
<label class="field"><span>Goal</span>
<select name="goal">
<option value="lose">Lose weight</option>
<option value="maintain">Maintain</option>
<option value="gain">Gain weight</option>
</select>
</label>
<label class="field"><span>Rate (kg/week)</span><input name="rate_kg_week" type="number" inputmode="decimal" min="0" max="1.5" step="0.1"></label>
<label class="field"><span>Meal style</span><select name="diet" id="profileDiet"></select></label>
<label class="field"><span>Protein target (g)</span><input name="protein_target_g" type="number" inputmode="numeric" min="0" max="400" placeholder="Auto"></label>
<button class="btn primary span-2" type="submit">Save profile</button>
</form>
<div class="card" id="targetsCard"></div>
<div class="card small-print">
<h2>Apple Health</h2>
<p class="muted">In the Health app open your profile → <strong>Export All Health Data</strong>, unzip it, then choose <code>export.xml</code> here. The file is read on this device; only daily step totals and workouts are sent to your server.</p>
<label class="field" style="margin-top:10px"><span>Date range</span>
<select id="importRange">
<option value="30">Last 30 days</option>
<option value="90" selected>Last 90 days</option>
<option value="365">Last year</option>
<option value="3650">Everything</option>
</select>
</label>
<label class="field" style="margin-top:10px"><span>Health export</span>
<input type="file" id="healthFile" accept=".xml,text/xml,application/xml">
</label>
<p class="hint" id="importStatus"></p>
</div>
<div class="card small-print">
<h2>Step data</h2>
<p class="muted">A browser cannot read the phone's step sensor. Log steps on the Today tab, or push them from a shortcut (iOS Shortcuts, Tasker) when <code>INGEST_TOKEN</code> is set on the server:</p>
<pre><code>curl -X POST http://HOST:31490/api/ingest/steps \
-H "Authorization: Bearer $INGEST_TOKEN" \
-H "Content-Type: application/json" \
-d '{"steps": 8500}'</code></pre>
<p class="muted small">Add <code>"date": "YYYY-MM-DD"</code> to backfill an earlier day. For scheduled Apple Health sync, point <strong>Health Auto Export</strong> at <code>/api/ingest/health-auto-export</code> with the same token; the README has the two-automation setup. Food data from Open Food Facts (ODbL).</p>
</div>
</section>
</main>
<nav class="tabbar" aria-label="Sections">
<button class="tab is-active" type="button" data-view="today">
<svg viewBox="0 0 24 24" aria-hidden="true"><circle cx="12" cy="12" r="8"/><path d="M8.5 12.2l2.4 2.4 4.6-5"/></svg>
<span>Today</span>
</button>
<button class="tab" type="button" data-view="scan">
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M4 8V5.5A1.5 1.5 0 015.5 4H8M16 4h2.5A1.5 1.5 0 0120 5.5V8M20 16v2.5a1.5 1.5 0 01-1.5 1.5H16M8 20H5.5A1.5 1.5 0 014 18.5V16"/><path d="M7 12h10"/></svg>
<span>Scan</span>
</button>
<button class="tab" type="button" data-view="plan">
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M5 7h14M5 12h14M5 17h9"/></svg>
<span>Plan</span>
</button>
<button class="tab" type="button" data-view="you">
<svg viewBox="0 0 24 24" aria-hidden="true"><circle cx="12" cy="8.5" r="3.5"/><path d="M5.5 20c.8-3.6 3.3-5.5 6.5-5.5s5.7 1.9 6.5 5.5"/></svg>
<span>You</span>
</button>
</nav>
<div id="toast" class="toast" role="status" aria-live="polite"></div>
<script src="/vendor/zxing/index.min.js"></script>
<script src="/health.js"></script>
<script src="/app.js"></script>
</body>
</html>