371 lines
21 KiB
HTML
371 lines
21 KiB
HTML
<!doctype html>
|
||
<html>
|
||
<head>
|
||
<meta charset="utf-8" />
|
||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||
<title>Analytics</title>
|
||
<style>
|
||
[hidden] { display: none !important; }
|
||
html, body { margin: 0; background: hsl(var(--background)); }
|
||
.mono { font-family: var(--aia-mono); font-variant-numeric: tabular-nums; }
|
||
label.cb { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
|
||
label.cb input { margin: 0; accent-color: hsl(var(--primary)); }
|
||
.body { gap: 16px; }
|
||
.grid4 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
|
||
@media (min-width: 720px) { .grid4 { grid-template-columns: repeat(4, 1fr); } }
|
||
.grid2 { display: grid; grid-template-columns: 1fr; gap: 16px; }
|
||
@media (min-width: 768px) { .grid2 { grid-template-columns: repeat(2, 1fr); } }
|
||
.head { padding: 14px 16px; }
|
||
.head .lbl { font-size: 11px; font-weight: 500; text-transform: uppercase; letter-spacing: .04em; }
|
||
.head .val { margin-top: 4px; font: 700 22px/1.2 var(--aia-mono); font-variant-numeric: tabular-nums; }
|
||
.head .sub { font-size: 11px; }
|
||
.panel { padding: 16px; }
|
||
.ph { display: flex; align-items: flex-start; gap: 8px; margin-bottom: 12px; }
|
||
.ph .t { flex: 1; min-width: 0; }
|
||
.finding { margin: 0 0 12px; line-height: 1.6; }
|
||
.finding b { font: 600 12px var(--aia-mono); font-variant-numeric: tabular-nums; }
|
||
.rows { display: flex; flex-direction: column; gap: 6px; }
|
||
.row { display: grid; grid-template-columns: 7.5rem 1fr 3.2rem 4rem; align-items: center; gap: 8px; font-size: 12px; }
|
||
.row .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||
.row .track { height: 8px; border-radius: 999px; background: hsl(var(--muted)); overflow: hidden; }
|
||
.row .fill { height: 100%; border-radius: 999px; }
|
||
.row .v { text-align: right; font-size: 11px; }
|
||
.bars { display: flex; align-items: flex-end; gap: 3px; height: 128px; }
|
||
.bars div { flex: 1; min-width: 0; border-radius: 2px 2px 0 0; background: hsl(var(--primary) / .75); }
|
||
.bars div:hover { background: hsl(var(--primary)); }
|
||
.axis { margin-top: 4px; display: flex; justify-content: space-between; font-size: 9px; }
|
||
.hist { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; align-items: end; height: 140px; }
|
||
.hist .col { display: flex; flex-direction: column; justify-content: flex-end; height: 100%; }
|
||
.hist .b { border-radius: 4px 4px 0 0; background: hsl(var(--primary) / .75); }
|
||
.hist .c { text-align: center; font-size: 11px; margin-bottom: 2px; }
|
||
.hl { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin-top: 4px; font-size: 10px; text-align: center; }
|
||
.tw { overflow-x: auto; }
|
||
.aia-table td.aia-num { font-family: var(--aia-mono); font-size: 12px; color: hsl(var(--muted-foreground)); }
|
||
.aia-table th.aia-num { text-align: right; }
|
||
.more-btn { margin-top: 8px; }
|
||
.stale { margin: 0 0 12px; }
|
||
.fade { opacity: .6; transition: opacity .15s; }
|
||
.note { text-align: center; margin: 16px 0 0; }
|
||
</style>
|
||
</head>
|
||
<body>
|
||
<div class="aia-page">
|
||
<div class="aia-toolbar">
|
||
<div class="aia-seg" id="scopes"></div>
|
||
<select class="aia-select" id="range" title="How far back the figures go">
|
||
<option value="24h">Last 24 hours</option>
|
||
<option value="7d">Last 7 days</option>
|
||
<option value="30d">Last 30 days</option>
|
||
<option value="90d">Last 90 days</option>
|
||
<option value="sub">Since subscription</option>
|
||
<option value="all">All time</option>
|
||
</select>
|
||
<label class="cb aia-small aia-muted" title="Cron jobs, an agent's Run now and throwaway test runs"><input type="checkbox" id="cron" /> Include cron & test runs</label>
|
||
<span class="aia-spacer"></span>
|
||
<div class="aia-seg" id="metric"></div>
|
||
</div>
|
||
<p class="stale aia-small aia-muted" id="stale" hidden></p>
|
||
<div id="msg" hidden></div>
|
||
<div id="body" class="body aia-stack" hidden></div>
|
||
<p class="note aia-small aia-muted">Working time = the 5-minute slots a conversation (or one of its subagents) produced a turn in — the same measure as the Activity dashboard. Conversations started by another conversation are counted inside it. Costs are on the cost dashboards.</p>
|
||
</div>
|
||
<script>
|
||
(function () {
|
||
"use strict";
|
||
var api = window.aiAgentPlugin || null;
|
||
var init = (api && api.init) || {};
|
||
var DAY = 86400000;
|
||
var KEY = "aia-analytics";
|
||
var saved = {};
|
||
try { saved = JSON.parse(localStorage.getItem(KEY) || "{}") || {}; } catch (e) { saved = {}; }
|
||
var state = {
|
||
range: saved.range || "30d",
|
||
metric: saved.metric === "conv" ? "conv" : "work",
|
||
cron: saved.cron === true,
|
||
scope: typeof init.scope === "string" && init.scope ? init.scope : (saved.scope || ""),
|
||
};
|
||
var data = null, seq = 0, tables = {}, more = {}, handle = null;
|
||
|
||
// reads: aiAgentPlugin.query (cached answer at once, then the fresh one); an older host only has action()
|
||
function read(name, payload, cb) {
|
||
if (api && api.query) return api.query(name, payload, cb);
|
||
api.action(name, payload).then(
|
||
function (d) { cb(d, { fromCache: false, fetching: false, at: Date.now() }); },
|
||
function (e) { cb(null, { error: String((e && e.message) || e), fromCache: false, fetching: false, at: Date.now() }); });
|
||
return { stop: function () {}, refresh: function () { return Promise.resolve(); } };
|
||
}
|
||
function setHeader(h) { if (api && api.setHeader) api.setHeader(h); }
|
||
var PALETTE = ["#2a78d6", "#eb6834", "#1baf7a", "#6250d6", "#eda100", "#e87ba4", "#e34948", "#008300", "#0ea5e9", "#94a3b8"];
|
||
var MODEL_COLOR = { opus: "#f97316", sonnet: "#0ea5e9", haiku: "#10b981", fable: "#8b5cf6" };
|
||
var ORIGIN_LABEL = { app: "The app", script: "A script (CLI, mail)", cron: "Cron job", scheduled: "Send later",
|
||
child: "Another conversation", mcp: "An AI app (MCP)", handoff: "Handoff", fork: "Fork", newProject: "New project",
|
||
unknown: "Terminal / before tracking" };
|
||
var RANGE_LABEL = { "24h": "the last 24 hours", "7d": "the last 7 days", "30d": "the last 30 days", "90d": "the last 90 days",
|
||
sub: "since the subscription", all: "all time" };
|
||
var RANGE_SHORT = { "24h": "Last 24 hours", "7d": "Last 7 days", "30d": "Last 30 days", "90d": "Last 90 days",
|
||
sub: "Since the subscription", all: "All time" };
|
||
|
||
function $(id) { return document.getElementById(id); }
|
||
function el(tag, attrs, kids) {
|
||
var n = document.createElement(tag);
|
||
for (var k in attrs || {}) {
|
||
if (attrs[k] == null) continue;
|
||
if (k === "text") n.textContent = attrs[k];
|
||
else if (k === "style") n.setAttribute("style", attrs[k]);
|
||
else if (k === "on") for (var ev in attrs.on) n.addEventListener(ev, attrs.on[ev]);
|
||
else n.setAttribute(k, attrs[k]);
|
||
}
|
||
(kids || []).forEach(function (c) { if (c != null && c !== false) n.appendChild(typeof c === "string" || typeof c === "number" ? document.createTextNode(String(c)) : c); });
|
||
return n;
|
||
}
|
||
function B(x) { return el("b", { text: String(x) }); }
|
||
var count = function (n) { return Number(n || 0).toLocaleString("en-US"); };
|
||
var pct = function (x) { return Math.round(x * 100) + "%"; };
|
||
function dur(min) {
|
||
if (!min) return "0 min";
|
||
if (min < 60) return Math.round(min) + " min";
|
||
var h = min / 60;
|
||
if (h < 10) { var hh = Math.floor(h), mm = Math.round(min - hh * 60); return hh + " h" + (mm ? " " + mm : ""); }
|
||
return Math.round(h).toLocaleString("en-US") + " h";
|
||
}
|
||
function median(xs) {
|
||
if (!xs.length) return 0;
|
||
var s = xs.slice().sort(function (a, b) { return a - b; }), m = s.length >> 1;
|
||
return s.length % 2 ? s[m] : (s[m - 1] + s[m]) / 2;
|
||
}
|
||
function hue(s) { var h = 0; for (var i = 0; i < s.length; i++) h = (h * 31 + s.charCodeAt(i)) >>> 0; return h; }
|
||
function colorOf(key, label) { return (key === "model" && MODEL_COLOR[label]) || PALETTE[hue(key + ":" + label) % PALETTE.length]; }
|
||
|
||
var queued = false;
|
||
function resize() {
|
||
if (!api || typeof api.resize !== "function" || queued) return;
|
||
queued = true;
|
||
requestAnimationFrame(function () { queued = false; api.resize(Math.ceil(document.documentElement.scrollHeight) + 4); });
|
||
}
|
||
if (window.ResizeObserver) new ResizeObserver(resize).observe(document.body);
|
||
function persist() { try { localStorage.setItem(KEY, JSON.stringify({ range: state.range, metric: state.metric, cron: state.cron, scope: state.scope })); } catch (e) {} }
|
||
|
||
function panel(id, title, question, finding, chart, table) {
|
||
var on = !!tables[id];
|
||
var head = el("div", { class: "ph" }, [el("div", { class: "t" }, [el("h2", { class: "aia-title", text: title }), el("p", { class: "aia-subtitle", text: question })])]);
|
||
if (table) head.appendChild(el("button", { class: "aia-btn aia-btn-ghost aia-btn-sm", type: "button", text: on ? "Chart" : "Table",
|
||
title: on ? "Show the chart" : "Show the numbers as a table", on: { click: function () { tables[id] = !on; render(); } } }));
|
||
return el("section", { class: "aia-card panel" }, [head, finding ? el("p", { class: "aia-note finding" }, finding) : null, on && table ? table : chart]);
|
||
}
|
||
function dataTable(head, rows) {
|
||
var t = el("table", { class: "aia-table" }, [el("thead", null, [el("tr", null, head.map(function (h, i) { return el("th", { class: i ? "aia-num" : null, text: h }); }))])]);
|
||
var tb = el("tbody"); rows.forEach(function (r) { tb.appendChild(el("tr", null, r.map(function (c, i) { return el("td", { class: i ? "aia-num" : null }, [c]); }))); });
|
||
t.appendChild(tb); return el("div", { class: "tw" }, [t]);
|
||
}
|
||
|
||
// group rows by a key (a row can sit in several groups: projects)
|
||
function group(rows, keysOf) {
|
||
var m = {};
|
||
rows.forEach(function (r) {
|
||
keysOf(r).forEach(function (k) {
|
||
var e = m[k] || (m[k] = { label: k, n: 0, work: 0, works: [] });
|
||
e.n += 1; e.work += r.workMin; e.works.push(r.workMin);
|
||
});
|
||
});
|
||
var val = function (e) { return state.metric === "work" ? e.work : e.n; };
|
||
return Object.keys(m).map(function (k) { return m[k]; }).sort(function (a, b) { return val(b) - val(a) || b.n - a.n; });
|
||
}
|
||
function breakdown(id, title, question, rows, keysOf, noun) {
|
||
var g = group(rows, keysOf);
|
||
var val = function (e) { return state.metric === "work" ? e.work : e.n; };
|
||
var tot = g.reduce(function (a, e) { return a + val(e); }, 0) || 1;
|
||
var max = g.length ? val(g[0]) : 1;
|
||
var shown = more[id] ? g : g.slice(0, 8);
|
||
var top = g[0];
|
||
var f = null;
|
||
if (top) {
|
||
f = [top.label + " leads: ", B(count(top.n)), " conversation" + (top.n === 1 ? "" : "s") + ", ", B(dur(top.work)), " of working time (" +
|
||
pct(val(top) / tot) + " of the " + (state.metric === "work" ? "time" : "conversations") + ")"];
|
||
if (g[1]) f.push("; then " + g[1].label + " (" + pct(val(g[1]) / tot) + ")");
|
||
f.push(". Median " + dur(median(top.works)) + " each.");
|
||
}
|
||
var chart = el("div", { class: "rows" }, shown.map(function (e) {
|
||
var w = Math.max(val(e) / max * 100, val(e) > 0 ? 2 : 0);
|
||
return el("div", { class: "row" }, [el("span", { class: "n", title: e.label, text: e.label }),
|
||
el("div", { class: "track" }, [el("div", { class: "fill", style: "width:" + w + "%;background:" + colorOf(id, e.label) })]),
|
||
el("span", { class: "v mono aia-muted", title: "conversations", text: count(e.n) }),
|
||
el("span", { class: "v mono", title: "working time", text: dur(e.work) })]);
|
||
}));
|
||
var box = el("div", null, [chart]);
|
||
if (g.length > 8) box.appendChild(el("button", { class: "aia-btn aia-btn-sm more-btn", type: "button", text: more[id] ? "Show the top 8" : "Show all " + g.length,
|
||
on: { click: function () { more[id] = !more[id]; render(); } } }));
|
||
return panel(id, title, question, f, box, dataTable([noun, "Conversations", "Working time", "Median", "Share"],
|
||
g.map(function (e) { return [e.label, count(e.n), dur(e.work), dur(median(e.works)), pct(val(e) / tot)]; })));
|
||
}
|
||
|
||
function byDay(rows) {
|
||
var now = Date.now();
|
||
var times = rows.map(function (r) { return r.t; }).filter(function (t) { return typeof t === "number"; });
|
||
var start = data.since != null ? data.since : Math.min.apply(null, times);
|
||
var weekly = (now - start) / DAY > 45;
|
||
var step = weekly ? 7 * DAY : DAY;
|
||
var nb = Math.min(120, Math.max(1, Math.ceil((now - start) / step) + 1));
|
||
var base = now - (nb - 1) * step;
|
||
var bins = [];
|
||
for (var i = 0; i < nb; i++) bins.push({ n: 0, work: 0 });
|
||
var off = -new Date().getTimezoneOffset() * 60000;
|
||
function idxOf(ms) { return Math.floor((ms - base) / step); }
|
||
rows.forEach(function (r) {
|
||
if (typeof r.t === "number") { var i = idxOf(r.t); if (i >= 0 && i < nb) bins[i].n += 1; }
|
||
Object.keys(r.byDay || {}).forEach(function (d) {
|
||
var ms = Date.parse(d + "T12:00:00Z") - off;
|
||
var j = idxOf(ms); if (j >= 0 && j < nb) bins[j].work += r.byDay[d];
|
||
});
|
||
});
|
||
var val = function (b) { return state.metric === "work" ? b.work : b.n; };
|
||
var max = Math.max.apply(null, [1e-9].concat(bins.map(val)));
|
||
function lab(i) { var d = new Date(base + i * step); return weekly ? (d.getMonth() + 1) + "/" + d.getDate() : String(d.getDate()); }
|
||
function full(i) { var d = new Date(base + i * step); return (weekly ? "Week of " : "") + d.toLocaleDateString("en-US", { month: "short", day: "numeric" }); }
|
||
var busiest = 0; bins.forEach(function (b, i) { if (val(b) > val(bins[busiest])) busiest = i; });
|
||
var unit = weekly ? "week" : "day";
|
||
var tot = bins.reduce(function (a, b) { return a + b.n; }, 0);
|
||
var f = [B(count(tot)), " conversations, ", B(count(Math.round(tot / nb * 10) / 10)), " a " + unit + " on average; the busiest " + unit + " was " +
|
||
full(busiest) + " (" + count(bins[busiest].n) + " conversations, " + dur(bins[busiest].work) + " of work)."];
|
||
var bars = el("div", { class: "bars" }, bins.map(function (b, i) {
|
||
return el("div", { title: full(i) + ": " + count(b.n) + " conversations · " + dur(b.work), style: "height:" + Math.max(val(b) / max * 100, val(b) > 0 ? 2 : 0) + "%" });
|
||
}));
|
||
var chart = el("div", null, [bars, el("div", { class: "axis aia-muted" }, [el("span", { text: lab(0) }), el("span", { text: lab(nb - 1) })])]);
|
||
return panel("day", "By " + unit, (state.metric === "work" ? "Working time" : "Conversations") + " per " + unit, f, chart,
|
||
dataTable([weekly ? "Week of" : "Day", "Conversations", "Working time"], bins.map(function (b, i) { return [full(i), count(b.n), dur(b.work)]; }).reverse()));
|
||
}
|
||
|
||
var BUCKETS = [["≤ 5 min", 0, 5], ["10–30 min", 6, 30], ["35 min – 2 h", 31, 120], ["2–5 h", 121, 300], ["> 5 h", 301, Infinity]];
|
||
function histogram(rows) {
|
||
var cnt = BUCKETS.map(function () { return 0; });
|
||
rows.forEach(function (r) { for (var i = 0; i < BUCKETS.length; i++) if (r.workMin >= BUCKETS[i][1] && r.workMin <= BUCKETS[i][2]) { cnt[i]++; break; } });
|
||
var max = Math.max.apply(null, [1].concat(cnt));
|
||
var tot = rows.length || 1;
|
||
var short = cnt[0] / tot, long = (cnt[3] + cnt[4]) / tot;
|
||
var f = [B(pct(short)), " of conversations worked 5 minutes or less; ", B(pct(long)), " ran over 2 hours. Median ", B(dur(median(rows.map(function (r) { return r.workMin; })))), "."];
|
||
var chart = el("div", null, [
|
||
el("div", { class: "hist" }, cnt.map(function (c) {
|
||
return el("div", { class: "col" }, [el("div", { class: "c mono aia-muted", text: count(c) }), el("div", { class: "b", style: "height:" + Math.max(c / max * 100, c ? 2 : 0) + "%" })]);
|
||
})),
|
||
el("div", { class: "hl aia-muted" }, BUCKETS.map(function (b) { return el("span", { text: b[0] }); }))]);
|
||
return panel("hist", "How long they work", "Conversations by working time", f, chart,
|
||
dataTable(["Working time", "Conversations", "Share"], BUCKETS.map(function (b, i) { return [b[0], count(cnt[i]), pct(cnt[i] / tot)]; })));
|
||
}
|
||
|
||
function headline(rows) {
|
||
var work = rows.reduce(function (a, r) { return a + r.workMin; }, 0);
|
||
var med = median(rows.map(function (r) { return r.workMin; }));
|
||
var turns = median(rows.map(function (r) { return r.turns; }));
|
||
var wall = median(rows.map(function (r) { return r.wallSec / 60; }));
|
||
return el("div", { class: "grid4" }, [
|
||
["Conversations", count(rows.length), "top-level, " + RANGE_LABEL[data.range]],
|
||
["Working time", dur(work), dur(rows.length ? work / rows.length : 0) + " on average"],
|
||
["Median working time", dur(med), "start → end " + dur(wall) + " (median)"],
|
||
["Turns per conversation", String(turns % 1 ? turns.toFixed(1) : turns), "your messages (median)"]
|
||
].map(function (c) {
|
||
return el("div", { class: "aia-card head" }, [el("div", { class: "lbl aia-muted", text: c[0] }), el("div", { class: "val", text: c[1] }), el("div", { class: "sub aia-muted", text: c[2] })]);
|
||
}));
|
||
}
|
||
|
||
function scopeLabel() {
|
||
var cur = (data && data.scope) || state.scope;
|
||
if (!cur || cur === "all") return cur ? "All profiles" : "";
|
||
var p = ((data && data.profiles) || []).find(function (x) { return "profile:" + x.id === cur; });
|
||
return p ? p.label : cur.replace(/^profile:/, "");
|
||
}
|
||
function header() {
|
||
var bits = [];
|
||
var sc = scopeLabel(); if (sc) bits.push(sc);
|
||
bits.push(RANGE_SHORT[(data && data.range) || state.range] || "");
|
||
if (data) bits.push(count((data.conversations || []).length) + " conversations");
|
||
if (state.cron) bits.push("cron & test runs included");
|
||
setHeader({ subtitle: bits.join(" · ") });
|
||
}
|
||
function message(kind, text, strong) {
|
||
var m = $("msg"); m.textContent = ""; m.className = kind === "error" ? "aia-error" : "aia-empty";
|
||
if (strong) m.appendChild(el("strong", { text: strong }));
|
||
if (text) m.appendChild(document.createTextNode(text));
|
||
m.hidden = false;
|
||
}
|
||
|
||
function renderChrome() {
|
||
var box = $("scopes"); box.textContent = "";
|
||
var segs = ((data && data.profiles) || []).map(function (p) { return ["profile:" + p.id, p.label]; });
|
||
segs.push(["all", "All"]);
|
||
var cur = (data && data.scope) || state.scope;
|
||
segs.forEach(function (s) {
|
||
box.appendChild(el("button", { type: "button", class: s[0] === cur ? "aia-active" : null, "aria-pressed": s[0] === cur ? "true" : "false", text: s[1],
|
||
on: { click: function () { if (s[0] === cur) return; state.scope = s[0]; persist(); load(); } } }));
|
||
});
|
||
var mb = $("metric"); mb.textContent = "";
|
||
[["work", "Working time"], ["conv", "Conversations"]].forEach(function (s) {
|
||
mb.appendChild(el("button", { type: "button", class: s[0] === state.metric ? "aia-active" : null, "aria-pressed": s[0] === state.metric ? "true" : "false",
|
||
text: s[1], title: "Rank and draw by " + s[1].toLowerCase(),
|
||
on: { click: function () { state.metric = s[0]; persist(); render(); } } }));
|
||
});
|
||
$("range").value = state.range;
|
||
$("cron").checked = state.cron;
|
||
header();
|
||
}
|
||
|
||
function render() {
|
||
renderChrome();
|
||
if (!data) { resize(); return; }
|
||
var rows = data.conversations || [];
|
||
if (!rows.length) {
|
||
$("body").hidden = true;
|
||
message("empty", "Try a longer range" + (state.cron ? "." : ", or include cron & test runs."), "No conversation " + RANGE_LABEL[data.range] + ".");
|
||
resize(); return;
|
||
}
|
||
$("msg").hidden = true;
|
||
var b = $("body"); b.textContent = ""; b.hidden = false;
|
||
b.appendChild(headline(rows));
|
||
b.appendChild(byDay(rows));
|
||
b.appendChild(histogram(rows));
|
||
b.appendChild(el("div", { class: "grid2" }, [
|
||
breakdown("model", "By model", "The model that ran most of each conversation", rows, function (r) { return [r.model]; }, "Model"),
|
||
breakdown("harness", "By harness", "Claude Code, pi, opencode, agy", rows, function (r) { return [r.harness]; }, "Harness"),
|
||
breakdown("project", "By project", "Every project a conversation touched", rows, function (r) { return r.projects.length ? r.projects : ["(none)"]; }, "Project"),
|
||
breakdown("machine", "By machine", "Where it ran", rows, function (r) { return [r.machine]; }, "Machine"),
|
||
breakdown("person", "By person", "Who started it — you or a guest", rows, function (r) { return [r.person]; }, "Person"),
|
||
breakdown("origin", "By origin", "Where it was started from", rows, function (r) { return [ORIGIN_LABEL[r.origin] || r.origin]; }, "Started from")
|
||
]));
|
||
resize();
|
||
}
|
||
|
||
// a scope / range / cron change: drop the old read, start the new one (the old answer stays, faded, until the new one paints)
|
||
function load() {
|
||
var my = ++seq;
|
||
if (handle) { handle.stop(); handle = null; }
|
||
render();
|
||
$("body").classList.add("fade");
|
||
if (!api) { message("empty", "Open this page from the ai-agent."); resize(); return; }
|
||
handle = read("conversations", { scope: state.scope, range: state.range, cron: state.cron,
|
||
tzOffset: -new Date().getTimezoneOffset() }, function (d, meta) {
|
||
if (my !== seq) return;
|
||
meta = meta || {};
|
||
$("body").classList.toggle("fade", !!meta.fetching);
|
||
if (d) {
|
||
data = d;
|
||
if (d.scope && !state.scope) state.scope = d.scope;
|
||
var st = $("stale");
|
||
st.hidden = !meta.error;
|
||
st.textContent = meta.error ? "Couldn’t refresh: " + meta.error + " — showing the last answer." : "";
|
||
render();
|
||
} else if (meta.error) {
|
||
data = null;
|
||
$("body").hidden = true; $("stale").hidden = true;
|
||
render();
|
||
message("error", meta.error);
|
||
resize();
|
||
}
|
||
});
|
||
}
|
||
$("range").addEventListener("change", function () { state.range = this.value; persist(); load(); });
|
||
$("cron").addEventListener("change", function () { state.cron = this.checked; persist(); load(); });
|
||
setInterval(function () { if (!document.hidden && data && handle) handle.refresh(); }, 120000);
|
||
load();
|
||
})();
|
||
</script>
|
||
</body>
|
||
</html>
|