/* Font Peek by Pablo Murad · https://pablomurad.com Hover any text to see which font the browser is really drawing it with, out of the whole font stack. Click to pin a full report. Esc closes. Run it again to toggle. */ (() => { const ID = "font-peek-root"; const old = document.getElementById(ID); if (old) { old.__close(); return; } const GENERIC = new Set([ "serif", "sans-serif", "monospace", "cursive", "fantasy", "math", "system-ui", "ui-serif", "ui-sans-serif", "ui-monospace", "ui-rounded", "emoji", "fangsong", "-apple-system", "blinkmacsystemfont" ]); const PROBES = ["mmmmmmmmmmlli", "WQ@#0123456789", "abcdefghij ABCDEFGHIJ", "il1|.,;:!"]; const BASES = ["monospace", "serif", "sans-serif"]; /* Canvas text measuring: a font counts as installed if it changes the width of at least one probe string against at least one generic fallback. */ const ctx = document.createElement("canvas").getContext("2d"); const width = (font, text) => { ctx.font = font; return ctx.measureText(text).width; }; const baseline = {}; BASES.forEach(b => { baseline[b] = PROBES.map(p => width(`72px ${b}`, p)); }); const installedCache = new Map(); const isInstalled = family => { const key = family.toLowerCase(); if (!installedCache.has(key)) { const q = `"${family.replace(/"/g, '\\"')}"`; installedCache.set(key, BASES.some(b => PROBES.some((p, i) => width(`72px ${q}, ${b}`, p) !== baseline[b][i]))); } return installedCache.get(key); }; /* Web fonts the page has actually loaded, and where they came from. */ const loaded = new Set(); try { document.fonts.forEach(f => { if (f.status === "loaded") loaded.add(f.family.replace(/^["']|["']$/g, "").toLowerCase()); }); } catch (e) {} const sources = new Map(); const readRules = rules => { for (const r of rules) { if (r.type === CSSRule.FONT_FACE_RULE) { const fam = (r.style.getPropertyValue("font-family") || "").replace(/^["']|["']$/g, "").trim().toLowerCase(); const url = (r.style.getPropertyValue("src").match(/url\(["']?([^"')]+)/) || [])[1]; if (fam && url && !sources.has(fam)) sources.set(fam, url); } else if (r.cssRules) { try { readRules(r.cssRules); } catch (e) {} } } }; for (const sheet of document.styleSheets) { try { readRules(sheet.cssRules); } catch (e) {} /* cross-origin sheets can't be read */ } const splitStack = stack => stack.split(",").map(s => s.trim().replace(/^["']|["']$/g, "")).filter(Boolean); const classify = family => { const key = family.toLowerCase(); if (GENERIC.has(key)) return { family, kind: "generic", ok: true }; if (loaded.has(key)) return { family, kind: "web font", ok: true, src: sources.get(key) }; if (isInstalled(family)) return { family, kind: "installed", ok: true }; return { family, kind: "missing", ok: false }; }; const toHex = rgb => { const m = rgb.match(/\d+(\.\d+)?/g); if (!m || m.length < 3) return rgb; const hex = "#" + m.slice(0, 3).map(n => (+n).toString(16).padStart(2, "0")).join(""); return m[3] !== undefined && +m[3] < 1 ? `${hex} (${Math.round(m[3] * 100)}% opacity)` : hex; }; const inspect = el => { const cs = getComputedStyle(el); const stack = splitStack(cs.fontFamily).map(classify); const used = stack.find(f => f.ok); return { el, stack, used: used ? used.family : "browser default", usedKind: used ? used.kind : "fallback", size: cs.fontSize, lineHeight: cs.lineHeight, weight: cs.fontWeight, style: cs.fontStyle, spacing: cs.letterSpacing, color: toHex(cs.color), features: cs.fontFeatureSettings !== "normal" ? cs.fontFeatureSettings : "", raw: cs.fontFamily }; }; /* Every font family the page renders text in, counted by element. */ const pageFonts = () => { const counts = new Map(); const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT); let n = 0, node; const seen = new Set(); while ((node = walker.nextNode()) && n < 4000) { const el = node.parentElement; if (!el || seen.has(el) || !node.textContent.trim() || host.contains(el)) continue; seen.add(el); n++; const info = inspect(el); counts.set(info.used, (counts.get(info.used) || 0) + 1); } return [...counts.entries()].sort((a, b) => b[1] - a[1]); }; const describe = el => { let s = el.tagName.toLowerCase(); if (el.id) s += "#" + el.id; if (el.classList.length) s += "." + [...el.classList].slice(0, 2).join("."); return s; }; /* The interface lives in a shadow root, so the page's CSS can't touch it. */ const host = document.createElement("div"); host.id = ID; Object.assign(host.style, { position: "fixed", inset: "0", zIndex: "2147483647", pointerEvents: "none" }); const root = host.attachShadow({ mode: "open" }); const css = ` :host { all: initial; } * { box-sizing: border-box; } .box { position: fixed; border: 2px solid #4dabf7; background: rgba(77,171,247,.08); border-radius: 3px; pointer-events: none; display: none; } .tip { position: fixed; display: none; pointer-events: none; padding: 4px 8px; border-radius: 6px; font: 12px/1.4 ui-monospace, Menlo, Consolas, monospace; background: #1b1e22; color: #f1f3f5; white-space: nowrap; } .panel { position: fixed; right: 16px; bottom: 16px; width: min(380px, calc(100vw - 32px)); max-height: 70vh; overflow: auto; pointer-events: auto; padding: 14px 16px; border-radius: 12px; border: 1px solid #dee2e6; font: 13px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; color: #212529; background: #fff; box-shadow: 0 10px 30px rgba(0,0,0,.18); } @media (prefers-color-scheme: dark) { .panel { background: #1b1e22; color: #e9ecef; border-color: #343a40; } } .head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; } .title { font-weight: 700; font-size: 14px; } .hint { opacity: .65; font-size: 12px; } .big { font-size: 20px; font-weight: 700; margin: 6px 0 2px; word-break: break-word; } .kind { font-size: 12px; opacity: .7; margin-bottom: 10px; } table { width: 100%; border-collapse: collapse; margin: 6px 0 10px; } td { padding: 3px 0; vertical-align: top; } td:first-child { opacity: .65; width: 38%; } ul { list-style: none; margin: 4px 0 10px; padding: 0; } li { padding: 2px 0; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; word-break: break-all; } .ok { color: #2b8a3e; } .no { color: #c92a2a; } .gen { color: #5f3dc4; } @media (prefers-color-scheme: dark) { .ok { color: #69db7c; } .no { color: #ff8787; } .gen { color: #b197fc; } } h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; opacity: .6; margin: 10px 0 2px; } button { font: inherit; font-size: 12px; padding: 4px 10px; border-radius: 6px; border: 1px solid #ced4da; background: transparent; color: inherit; cursor: pointer; } button:hover { border-color: #4dabf7; } .row { display: flex; gap: 6px; } a { color: #1c7ed6; word-break: break-all; } .by { margin-top: 10px; font-size: 11px; opacity: .55; } .by a { color: inherit; } `; try { const sheet = new CSSStyleSheet(); sheet.replaceSync(css); /* works even on pages that block inline