/** Shared site chrome. Public pages and native adapters consume these same templates. */ export const FOOTER_SPONSORS=""; export const SHARED_FOOTER = ``; export function applySharedFooter(html){ const existing=html.match(/]*>[\s\S]*?<\/footer>/); if(!existing)return html.replace('',SHARED_FOOTER+''); // The footer no longer carries the decorative Patrick Stewart memorial; dedicated awards pages are untouched. const memorial=existing[0].match(/<(aside|section)\b[^>]*class="[^"]*(?:memorial|tribute)[^"]*"[^>]*>[\s\S]*?<\/\1>/)?.[0]||''; return html.replace(existing[0],SHARED_FOOTER.replace('',/dune-memorial|Patrick Stewart/i.test(memorial)?'':memorial+'')); } export const SHARED_FOOTER_SCRIPT=`(()=>{if(window.top!==window.self)return;const html=${JSON.stringify(SHARED_FOOTER)};let footer=document.querySelector('body>footer,.dune-shared-footer');if(footer?.dataset.sharedChrome==='3')return;const template=document.createElement('template');template.innerHTML=html;const fresh=template.content.firstElementChild;if(footer)footer.replaceWith(fresh);else document.body.append(fresh);})();`; // Existing native adapters and old compiled pages use this same canonical sponsor fragment. function mountSharedFooterBrands(html){ if(window.top!==window.self)return; function sync(){for(const footer of document.querySelectorAll('footer.dune-shared-footer')){if(footer.querySelector('[data-footer-sponsors]'))continue;const template=document.createElement('template');template.innerHTML=html;const old=footer.querySelector('.dune-hosting-badge');if(old)old.replaceWith(template.content);else footer.insertBefore(template.content,footer.querySelector('small'));}} sync();new MutationObserver(sync).observe(document.body,{childList:true,subtree:true}); } export function sharedFooterBrandScript(){return '\n;('+mountSharedFooterBrands.toString()+')('+JSON.stringify(FOOTER_SPONSORS)+');\n';} export function applySharedHeader(html,header,label){ if(/]*class="[^"]*dune-site-header/.test(html))return html.replace(/]*class="[^"]*dune-site-header[^"]*"[^>]*>[\s\S]*?<\/header>/,header); // Non-homepage legacy mastheads are compiled into the shared header as before. if(html.includes('
')){ const start=html.indexOf('
'),end=html.indexOf('\{if\(window.top!==window.self\)\{document.documentElement.classList.add\('dune-embedded'\);return;\}const links=[\s\S]*?\}\)\(\);/g,'');} export function assertSharedChrome(html,header,label='document'){ const headers=(html.match(/]*class="[^"]*dune-site-header/g)||[]).length; const footers=(html.match(/data-shared-chrome="3"/g)||[]).length; const banners=(html.match(/class="dr-page-banner"/g)||[]).length; const homeHeader=header.replace('class="dr-header-account"','class="dr-header-account" data-play'); if(label==='index.html'&&banners!==0)throw Error('Homepage banner is not allowed'); if(headers!==1||footers!==1||banners>1||!html.includes(header)&&!html.includes(homeHeader))throw Error('Shared chrome contract failed: '+label); return html; }