(() => { const root = document.documentElement.cloneNode(true); const head = root.querySelector("head") || root; const inlined = []; const crossOrigin = []; const liveLinks = Array.from(document.querySelectorAll("link")); const cloneLinks = Array.from(root.querySelectorAll("link")); liveLinks.forEach((link, i) => { const sheet = link.sheet; if (!sheet) return; try { const text = Array.from(sheet.cssRules).map((rule) => rule.cssText).join("\n"); inlined.push("/* gstack-dom-dump: " + (sheet.href || "link") + " */\n" + text); if (cloneLinks[i]) cloneLinks[i].remove(); } catch (err) { crossOrigin.push(sheet.href || "(unknown)"); } }); if (inlined.length) { const style = document.createElement("style"); style.setAttribute("data-gstack-dom-css", ""); const dataUrl = new RegExp("url\\((\"?)data:[^)]{1024,}\\)", "g"); const rgb = new RegExp("rgb\\((\\d+), (\\d+), (\\d+)\\)", "g"); const hex = (n) => Number(n).toString(16).padStart(2, "0"); style.textContent = inlined.join("\n") .replace(dataUrl, "url(data:,gstack-stripped)") .replace(rgb, (m, r, g, b) => "#" + hex(r) + hex(g) + hex(b)); head.appendChild(style); } let scripts = 0; for (const el of Array.from(root.querySelectorAll("script"))) { if (el.textContent) { el.textContent = ""; scripts += 1; } } for (const el of Array.from(root.querySelectorAll("textarea"))) el.textContent = ""; for (const el of Array.from(root.querySelectorAll("*"))) { for (const attr of Array.from(el.attributes)) { const name = attr.name; const value = attr.value; if (name === "value" && (el.nodeName === "INPUT" || el.nodeName === "TEXTAREA")) el.setAttribute(name, ""); else if ((name === "value" || name.indexOf("data-") === 0) && value.length > 32) el.setAttribute(name, ""); else if (name === "content" && el.nodeName === "META" && el.getAttribute("name") !== "viewport") el.setAttribute(name, ""); else if (name === "href" && value.indexOf("?") !== -1) el.setAttribute(name, value.split("?")[0]); else if (value.indexOf("data:") === 0 && value.length > 1024) el.setAttribute(name, "data:,gstack-stripped"); } } const notes = ["shadow DOM and constructed stylesheets not captured"]; if (crossOrigin.length) notes.push("cross-origin stylesheets not resolved: " + crossOrigin.join(" ")); if (scripts) notes.push("scripts stripped: " + scripts + "; styles injected at runtime not captured"); return "\n" + root.outerHTML + "\n\n"; })()