Snippets: Download ETA Calculator
CSS Before Head
<meta name="viewport" content="width=device-width, initial-scale=1.0">
HTML Head
:root { --primary: #6366f1; --primary-hover: #4f46e5; --bg: #f1f5f9; --card: #ffffff; --text: #1e293b; --text-muted: #64748b; --border: #e2e8f0; --radius: 12px; --shadow: 0 4px 24px rgba(0,0,0,0.08); } * { box-sizing: border-box; margin: 0; padding: 0; } body { font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; display: flex; justify-content: center; align-items: flex-start; padding: 24px 16px; } .container { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 32px; width: 100%; max-width: 520px; } h1 { font-size: 1.5rem; font-weight: 700; text-align: center; margin-bottom: 28px; color: var(--primary); } .field { margin-bottom: 20px; } .field label { display: block; font-weight: 600; font-size: 0.875rem; margin-bottom: 6px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; } .input-row { display: flex; gap: 8px; } .input-row input { flex: 1; min-width: 0; } .input-row select { width: 120px; flex-shrink: 0; } input[type="number"], select { padding: 10px 14px; border: 1.5px solid var(--border); border-radius: 8px; font-size: 1rem; color: var(--text); background: var(--card); transition: border-color 0.2s; appearance: auto; } input[type="number"]:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99,102,241,0.15); } input[type="number"]::placeholder { color: #94a3b8; } button { width: 100%; padding: 12px; background: var(--primary); color: #fff; border: none; border-radius: 8px; font-size: 1rem; font-weight: 600; cursor: pointer; transition: background 0.2s, transform 0.1s; margin-top: 4px; } button:hover { background: var(--primary-hover); } button:active { transform: scale(0.98); } .result-box { margin-top: 24px; padding: 20px; background: #f8fafc; border: 1.5px solid var(--border); border-radius: 8px; text-align: center; min-height: 64px; display: flex; flex-direction: column; justify-content: center; gap: 4px; } .result-box .time-value { font-size: 1.75rem; font-weight: 700; color: var(--primary); word-break: break-word; } .result-box .time-label { font-size: 0.8rem; color: var(--text-muted); } .result-box .error { color: #ef4444; font-size: 0.9rem; } .output-unit-row { display: flex; align-items: center; gap: 8px; margin-top: 16px; justify-content: center; } .output-unit-row label { font-size: 0.8rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 0; } .output-unit-row select { padding: 6px 10px; font-size: 0.875rem; }
CSS After Head
JS Before HTML Body
HTML Body Attrs
<div class="container"> <h1>Download ETA Calculator</h1> <div class="field"> <label>File Size</label> <div class="input-row"> <input type="number" id="fileSize" min="0" step="any" placeholder="e.g. 1.5"> <select id="sizeUnit"> <option value="1">B</option> <option value="1024">KB</option> <option value="1048576" selected>MB</option> <option value="1073741824">GB</option> <option value="1099511627776">TB</option> <option value="1125899906842624">PB</option> </select> </div> </div> <div class="field"> <label>Download Speed</label> <div class="input-row"> <input type="number" id="speed" min="0" step="any" placeholder="e.g. 100"> <select id="speedUnit"> <option value="1">B/s</option> <option value="1024">KB/s</option> <option value="1048576" selected>MB/s</option> <option value="1073741824">GB/s</option> <option value="125000">Kbps</option> <option value="125000000">Mbps</option> <option value="125000000000">Gbps</option> </select> </div> </div> <button onclick="calculate()">Calculate</button> <div class="output-unit-row"> <label for="outputUnit">Display unit:</label> <select id="outputUnit" onchange="recalculate()"> <option value="auto" selected>Auto</option> <option value="seconds">Seconds</option> <option value="minutes">Minutes</option> <option value="hours">Hours</option> <option value="days">Days</option> </select> </div> <div class="result-box" id="result"> <span class="time-label">Enter size and speed, then click Calculate</span> </div> </div>
HTML Body
HTML Foot
let lastTotalBytes = null; function calculate() { const sizeVal = parseFloat(document.getElementById('fileSize').value); const speedVal = parseFloat(document.getElementById('speed').value); const sizeUnit = parseFloat(document.getElementById('sizeUnit').value); const speedUnit = parseFloat(document.getElementById('speedUnit').value); const resultEl = document.getElementById('result'); if (isNaN(sizeVal) || isNaN(speedVal)) { resultEl.innerHTML = '<span class="error">Please enter valid numbers for both fields.</span>'; lastTotalBytes = null; return; } if (sizeVal <= 0 || speedVal <= 0) { resultEl.innerHTML = '<span class="error">Both values must be greater than zero.</span>'; lastTotalBytes = null; return; } const totalBytes = sizeVal * sizeUnit; const bytesPerSecond = speedVal * speedUnit; lastTotalBytes = { totalBytes, bytesPerSecond }; recalculate(); } function recalculate() { const resultEl = document.getElementById('result'); if (!lastTotalBytes) return; const { totalBytes, bytesPerSecond } = lastTotalBytes; const totalSeconds = totalBytes / bytesPerSecond; const mode = document.getElementById('outputUnit').value; let html = ''; if (mode === 'auto') { html = formatAuto(totalSeconds); } else if (mode === 'seconds') { html = `<span class="time-value">${formatNum(totalSeconds)}</span><span class="time-label">seconds</span>`; } else if (mode === 'minutes') { const mins = totalSeconds / 60; html = `<span class="time-value">${formatNum(mins)}</span><span class="time-label">minutes</span>`; } else if (mode === 'hours') { const hrs = totalSeconds / 3600; html = `<span class="time-value">${formatNum(hrs)}</span><span class="time-label">hours</span>`; } else if (mode === 'days') { const days = totalSeconds / 86400; html = `<span class="time-value">${formatNum(days)}</span><span class="time-label">days</span>`; } resultEl.innerHTML = html; } function formatAuto(totalSeconds) { if (totalSeconds < 1) { const ms = totalSeconds * 1000; return `<span class="time-value">${formatNum(ms)}</span><span class="time-label">milliseconds</span>`; } const days = Math.floor(totalSeconds / 86400); const hours = Math.floor((totalSeconds % 86400) / 3600); const minutes = Math.floor((totalSeconds % 3600) / 60); const seconds = Math.floor(totalSeconds % 60); const parts = []; if (days > 0) parts.push(`${days} day${days !== 1 ? 's' : ''}`); if (hours > 0) parts.push(`${hours} hour${hours !== 1 ? 's' : ''}`); if (minutes > 0) parts.push(`${minutes} minute${minutes !== 1 ? 's' : ''}`); if (seconds > 0 || parts.length === 0) parts.push(`${seconds} second${seconds !== 1 ? 's' : ''}`); return `<span class="time-value">${parts.join(' ')}</span><span class="time-label">estimated download time</span>`; } function formatNum(n) { if (!isFinite(n)) return '∞'; if (Number.isInteger(n)) return n.toLocaleString(); return n.toLocaleString(undefined, { maximumFractionDigits: 2 }); } document.addEventListener('keydown', function(e) { if (e.key === 'Enter') calculate(); });
JS After HTML Body
Full HTML Code