// SPDX-License-Identifier: MIT // drAIML WebGPU helper · the popup (also a plain page). Inside the extension, flag links open in a new tab and the // result sets the toolbar badge; as a web page, browser-internal links (chrome://…) cannot be opened, so they are copied. import { checkWebGPU, advice } from "./check.js"; const ext = typeof chrome !== "undefined" && chrome.runtime && chrome.runtime.id ? chrome : null; const $ = (s) => document.querySelector(s); let last = null; function copy(text, btn) { navigator.clipboard.writeText(text).then(() => { const t = btn.textContent; btn.textContent = "Copied"; setTimeout(() => (btn.textContent = t), 1200); }, () => { btn.textContent = "Copy failed"; }); } function stepItem(s) { const li = document.createElement("li"); li.append(document.createTextNode(s.text)); const value = s.link || s.copy; if (value) { const row = document.createElement("div"); row.className = "step-actions"; const code = document.createElement("code"); code.textContent = value; row.append(code); if (s.link && ext) { const b = document.createElement("button"); b.textContent = "Open"; b.addEventListener("click", () => ext.tabs.create({ url: s.link })); row.append(b); } const c = document.createElement("button"); c.textContent = "Copy"; c.addEventListener("click", () => copy(value, c)); row.append(c); li.append(row); } return li; } async function run() { $("#verdict").dataset.v = "checking"; $("#title").textContent = "Checking WebGPU…"; $("#steps").replaceChildren(); let r; try { r = await checkWebGPU(); } catch (e) { r = { verdict: "broken", error: String(e && e.message || e) }; } last = r; const a = advice(r); $("#verdict").dataset.v = r.verdict; $("#title").textContent = a.title; $("#summary").textContent = a.summary; $("#steps").replaceChildren(...a.steps.map(stepItem)); $("#report").textContent = JSON.stringify(r, null, 2); document.body.dataset.verdict = r.verdict; // for tests and for anyone scripting the page if (ext) ext.runtime.sendMessage({ type: "verdict", verdict: r.verdict, report: r }).catch(() => {}); } $("#again").addEventListener("click", run); $("#copy").addEventListener("click", (e) => copy(JSON.stringify(last, null, 2), e.target)); run();