← Commit history

adom-stock: freshness stamp as 12h ago; v1 shows vendor, qty, price only (Ray)

Colby Knox ·088e723533 ·28d ago ·parent d786646
1 file changed +3−2
widgets/stock-widget.js+3−2
@@ -10,7 +10,8 @@ a.pill:hover{border-color:var(--accent)}.pill .v{color:var(--muted);font-size:11 .pill.dim{color:var(--muted)}.pill.dim .q{color:var(--muted)} .when{flex-basis:100%;color:var(--muted);font-size:11px;margin-top:2px}.when a{color:var(--accent);text-decoration:none}.note{color:var(--muted)}`;   const VENDORS = ['mouser', 'digikey', 'lcsc'];-  const ago = iso => { if (!iso) return ''; const m = Math.max(0, (Date.now() - Date.parse(iso)) / 60000); return m < 90 ? `checked ${Math.round(m)} min ago` : m < 2880 ? `checked ${Math.round(m / 60)} h ago` : `checked ${Math.round(m / 1440)} d ago`; };+  // Freshness stamp in Ray's form: 12h ago (from the distributor's fetched_at).+  const ago = iso => { if (!iso) return ''; const m = Math.max(0, (Date.now() - Date.parse(iso)) / 60000); return m < 60 ? `${Math.max(1, Math.round(m))}m ago` : m < 2880 ? `${Math.round(m / 60)}h ago` : `${Math.round(m / 1440)}d ago`; };   const num = n => Number(n).toLocaleString();   class AdomStock extends HTMLElement {     constructor() { super(); this.attachShadow({ mode: 'open' }); }@@ -52,7 +53,7 @@ a.pill:hover{border-color:var(--accent)}.pill .v{color:var(--muted);font-size:11         if (r.error) return `<span class="pill dim" title="${esc(r.error)}"><span class="v">${esc(label)}</span><span class="q">${/budget/.test(r.error) ? 'daily lookups used' : /PARTS_API_KEY/.test(r.error) ? 'not configured' : 'lookup failed'}</span></span>`;         if (!r.found) return `<span class="pill dim"><span class="v">${esc(label)}</span><span class="q">not listed</span></span>`;         const inner = `<span class="v">${esc(label)}</span><span class="q ${r.stock > 0 ? '' : 'out'}">${r.stock > 0 ? num(r.stock) : 'out of stock'}</span>${r.unit_price ? `<span class="p">${esc(r.unit_price)}</span>` : ''}`;-        const title = `${label}: ${r.part || r.mpn || ''}${r.price_100 ? `, ${r.price_100} at 100` : ''}${r.lead_time ? `, lead ${r.lead_time}` : ''}`;+        const title = `${label}: ${r.part || r.mpn || ''}${r.checked_at ? `, ${ago(r.checked_at)}` : ''}`;         return r.product_url ? `<a class="pill" href="${esc(r.product_url)}" target="_blank" rel="noopener" title="${esc(title)}">${inner}</a>` : `<span class="pill" title="${esc(title)}">${inner}</span>`;       });       const refresh = d.checked_at && d.signed_in !== false && !d.login_required ? ' <a class="refresh" href="#" title="Ask the distributors again (counts against the daily lookup budget)">refresh</a>' : d.login_required ? ' (sign in to refresh)' : '';