"); } return html + script; } function buildSrcdoc(rawHtml, baseHref) { let html = rawHtml; html = ensureBaseTag(html, baseHref); html = ensureResizeScript(html); const hasHtml = /]/i.test(html) || / "; return "" + head + "" + html + " "; } function setIframeHeight(iframe, height) { if (!iframe || !height) return; iframe.style.height = height + "px"; } function ensureIframe(el, srcdoc) { if (!currentIframe || currentIframe.parentNode !== el) { el.innerHTML = ""; currentIframe = document.createElement("iframe"); currentIframe.className = IFRAME_CLASS; currentIframe.setAttribute("loading", "lazy"); currentIframe.setAttribute("referrerpolicy", "no-referrer-when-downgrade"); el.appendChild(currentIframe); } if (currentIframe.srcdoc !== srcdoc) { currentIframe.srcdoc = srcdoc; } } function processHtmlContent() { const el = document.querySelector(".html-content"); if (!el) { removeInjectedAssets(); setSiteChromeHidden(false); currentIframe = null; return; } const currentHtml = el.innerHTML || ""; let raw = el.getAttribute(RAW_ATTR) || ""; if (!raw || currentHtml.indexOf(IFRAME_CLASS) === -1) { raw = currentHtml; el.setAttribute(RAW_ATTR, raw); } const sig = signature(raw); if (el.getAttribute(SIG_ATTR) === sig) { return; } el.setAttribute(SIG_ATTR, sig); const hideSite = raw.indexOf(HIDE_SITE_MARKER) !== -1; const showSite = raw.indexOf(SHOW_SITE_MARKER) !== -1; setSiteChromeHidden(hideSite && !showSite); const forceInline = raw.indexOf(INLINE_MARKER) !== -1; const forceIframe = raw.indexOf(IFRAME_MARKER) !== -1; const mode = forceInline ? "inline" : "iframe"; if (mode === "iframe") { el.classList.remove(STRIP_CLASS); removeInjectedAssets(); const baseHref = findBase(raw) || window.location.origin + "/"; const srcdoc = buildSrcdoc(raw, baseHref); ensureIframe(el, srcdoc); return; } // Inline mode (legacy) const stripHtmlChrome = raw.indexOf(STRIP_MARKER) !== -1; el.classList.toggle(STRIP_CLASS, stripHtmlChrome); removeInjectedAssets(); el.querySelectorAll('link[rel~="stylesheet"], style').forEach(function (node) { const clone = node.cloneNode(true); clone.setAttribute(ASSET_ATTR, "1"); document.head.appendChild(clone); if (node.parentNode) { node.parentNode.removeChild(node); } }); el.querySelectorAll("script").forEach(function (node) { const s = document.createElement("script"); Array.from(node.attributes || []).forEach(function (attr) { s.setAttribute(attr.name, attr.value); }); if (!node.src) { s.text = node.textContent || ""; } s.setAttribute(ASSET_ATTR, "1"); document.body.appendChild(s); if (node.parentNode) { node.parentNode.removeChild(node); } }); const bodyEl = el.querySelector("body"); if (bodyEl) { el.innerHTML = bodyEl.innerHTML; } else { const htmlEl = el.querySelector("html"); if (htmlEl) { el.innerHTML = htmlEl.innerHTML; } } el.setAttribute(SIG_ATTR, signature(el.innerHTML || "")); } window.addEventListener("message", function (event) { if (!currentIframe || event.source !== currentIframe.contentWindow) return; const data = event.data || {}; if (data.type !== "nasaq:iframe-height") return; setIframeHeight(currentIframe, data.height); }); const observer = new MutationObserver(function () { processHtmlContent(); }); observer.observe(document.body, { childList: true, subtree: true }); if (document.readyState === "loading") { document.addEventListener("DOMContentLoaded", processHtmlContent); } else { processHtmlContent(); } })();