diff --git a/webui/app.js b/webui/app.js index 7c54853..5c52cd1 100644 --- a/webui/app.js +++ b/webui/app.js @@ -447,6 +447,65 @@ function initFooter() { })(); } +function attachCopyButtons() { + // 给指定 statValue 元素绑定一键复制(hover 显示按钮,点击复制文本) + const ids = ["statPid", "statTraceId"]; + for (const id of ids) { + const el = document.getElementById(id); + if (!el || el.dataset.copyBound === "1") continue; + el.dataset.copyBound = "1"; + el.classList.add("hasCopy"); + const btn = document.createElement("button"); + btn.type = "button"; + btn.className = "copyBtn"; + btn.setAttribute("aria-label", "复制"); + btn.innerHTML = ''; + btn.addEventListener("click", async (e) => { + e.stopPropagation(); + const text = (el.textContent || "").trim(); + if (!text || text === "-") { + toast("暂无可复制内容", "warn", { duration: 1800 }); + return; + } + try { + await navigator.clipboard.writeText(text); + toast("已复制:" + (text.length > 24 ? text.slice(0, 24) + "…" : text), "success", { duration: 1800 }); + } catch (err) { + // fallback for non-secure context + const ta = document.createElement("textarea"); + ta.value = text; + ta.style.position = "fixed"; + ta.style.opacity = "0"; + document.body.appendChild(ta); + ta.select(); + try { document.execCommand("copy"); toast("已复制", "success", { duration: 1800 }); } + catch (_) { toast("复制失败", "error", { duration: 2400 }); } + document.body.removeChild(ta); + } + }); + el.appendChild(btn); + } +} + +function initShotFullscreen() { + const btn = document.getElementById("btnShotFullscreen"); + const img = document.getElementById("liveShot"); + if (!btn || !img) return; + btn.addEventListener("click", () => { + const target = img.closest(".preview") || img; + if (document.fullscreenElement) { + document.exitFullscreen?.(); + } else if (target.requestFullscreen) { + target.requestFullscreen().catch(() => { + // fallback:在新标签打开 + window.open(img.src, "_blank", "noopener"); + }); + } else { + window.open(img.src, "_blank", "noopener"); + } + }); +} + function initTabs() { const tabButtons = Array.from(document.querySelectorAll(".tabBtn[data-target]")); const panels = Array.from(document.querySelectorAll(".panel[data-panel]")); @@ -700,7 +759,13 @@ function startShotPolling() { img.addEventListener("load", () => { img.dataset.loading = "false"; if (preview) preview.classList.remove(UI_CLASS.shotEmpty); - if (status) status.textContent = `已更新:${new Date().toLocaleTimeString()}`; + const ts = new Date().toLocaleTimeString(); + if (status) status.textContent = `已更新:${ts}`; + const tsBadge = document.getElementById("liveShotTs"); + if (tsBadge) { + tsBadge.textContent = ts; + tsBadge.hidden = false; + } }); img.addEventListener("error", () => { img.dataset.loading = "false"; @@ -718,15 +783,25 @@ function setTextIfExists(id, text) { const el = $(id); if (!el) return; const next = String(text ?? "-"); + // 仅取文本节点(跳过子元素如 .copyBtn)来比较和读取当前值 + const getTextOnly = (node) => { + let s = ""; + for (const ch of node.childNodes) if (ch.nodeType === Node.TEXT_NODE) s += ch.textContent; + return s; + }; + const prev = getTextOnly(el); // 仅对 statValue 有效:值变化时短暂高亮 - if (el.classList.contains("statValue") && el.textContent !== next && next !== "-") { + if (el.classList.contains("statValue") && prev !== next && next !== "-") { el.classList.remove("isFlash"); - // 强制重排让动画重新触发 void el.offsetWidth; el.classList.add("isFlash"); setTimeout(() => el.classList.remove("isFlash"), 700); } - el.textContent = next; + // 替换:保留所有非文本子节点(如 .copyBtn),仅更新文本 + for (const ch of Array.from(el.childNodes)) { + if (ch.nodeType === Node.TEXT_NODE) ch.remove(); + } + el.insertBefore(document.createTextNode(next), el.firstChild || null); } function setButtonBusy(id, busy) { @@ -1871,6 +1946,8 @@ window.addEventListener("DOMContentLoaded", async () => { initTabs(); initConfigSearch(); initFooter(); + attachCopyButtons(); + initShotFullscreen(); // 首屏统计数字加骨架,待第一次 pollStats 成功后移除 document.querySelectorAll(".stat .statValue").forEach((el) => { if ((el.textContent || "").trim() === "-") el.classList.add("skeleton"); diff --git a/webui/index.html b/webui/index.html index 89a1a65..205822f 100644 --- a/webui/index.html +++ b/webui/index.html @@ -15,7 +15,7 @@ } catch (e) {} })(); - +
+
+