40 lines
7.4 KiB
JavaScript
40 lines
7.4 KiB
JavaScript
/** Shared site chrome. Public pages and native adapters consume these same templates. */
|
|
export const FOOTER_SPONSORS="<div class=\"dune-footer-sponsors\" data-footer-sponsors=\"1\"><a class=\"dune-corrino-badge\" href=\"https://www.dunerealms.com/corrino-group.html\" aria-label=\"Corrino Group\"><img src=\"https://www.dunerealms.com/assets/corrino-group-v4.png\" alt=\"Corrino Group\" width=\"165\" height=\"58\"></a><a class=\"dune-hosting-badge\" href=\"https://www.hetzner.com/\" target=\"_blank\" rel=\"noopener noreferrer\"><span>Powered by</span><img src=\"data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxODEuNDIgMjIuMjQiPjxkZWZzPjxzdHlsZT4uY2xzLTF7ZmlsbDojZDUwYzJkO308L3N0eWxlPjwvZGVmcz48dGl0bGU+RWxlbWVudCAxPC90aXRsZT48ZyBpZD0iRWJlbmVfMiIgZGF0YS1uYW1lPSJFYmVuZSAyIj48ZyBpZD0iTG9nb19QdXIiIGRhdGEtbmFtZT0iTG9nbyBQdXIiPjxnIGlkPSJMb2dvIj48ZyBpZD0iSEVUWk5FUiI+PHBhdGggY2xhc3M9ImNscy0xIiBkPSJNMTc0LjA1LDE0LjEyYTEwLjIyLDEwLjIyLDAsMCwwLDQuNTMtMmwwLDBhNi4xNSw2LjE1LDAsMCwwLDEuNjgtNC43OCw3LjcxLDcuNzEsMCwwLDAtMS4xNC00LjA2QTYuNDcsNi40NywwLDAsMCwxNzMuODQuMDlsLTEuMDksMEwxNzAuMiwwLDE1OC42NiwwYy0uNywwLTEsLjI5LTEsMVYyMS4yMmMwLC43LjI5LDEsMSwxaDNjLjcsMCwxLS4yOSwxLTF2LTYuN2gzLjY3YTMuNDgsMy40OCwwLDAsMSwyLjE3LjkxbDUuODIsNS44NWEzLjA4LDMuMDgsMCwwLDAsMiwuOTJoNC40N2MuNywwLC44Ny0u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Ny42OCwxMDEuMTcsMTcuMzksMTAwLjQ3LDE3LjM5WiIvPjxwYXRoIGNsYXNzPSJjbHMtMSIgZD0iTTc0LjE5LDBINTMuNTVjLS43MSwwLTEsLjI4LTEsMVYzLjc2YzAsLjcuMjgsMSwxLDFoNy43OFYyMS4yNGMwLC43LjI5LDEsMSwxaDMuM2MuNywwLDEtLjI5LDEtMVY0Ljc1aDcuNTdjLjcsMCwxLS4yOSwxLTFWMUM3NS4xOC4zMiw3NC44OSwwLDc0LjE5LDBaIi8+PHBhdGggY2xhc3M9ImNscy0xIiBkPSJNNDcuOTEsMTcuNTJIMzEuNDFWMTMuMzVINDQuNmMuNywwLDEtLjI5LDEtMVY5LjkyYzAtLjctLjI4LTEtMS0xSDMxLjQxVjQuNzZoMTYuNWMuNywwLDEtLjI5LDEtMVYxYzAtLjctLjI5LTEtMS0xSDI3LjMzYy0uNywwLTEsLjI5LTEsMVYyMS4yNGMwLC43LjI5LDEsMSwxSDQ3LjkxYy43LDAsMS0uMjksMS0xVjE4LjUxQzQ4LjksMTcuODEsNDguNjEsMTcuNTIsNDcuOTEsMTcuNTJaIi8+PHBhdGggY2xhc3M9ImNscy0xIiBkPSJNMjEuNjMsMEgxOC41MmMtLjcsMC0xLC4yOS0xLDFWOC44N0g1LjEzVjFjMC0uNy0uMjktMS0xLTFIMUMuMjksMCwwLC4yOSwwLDFWMjEuMjVjMCwuNzEuMjksMSwxLDFINC4xM2MuNywwLDEtLjI4LDEtMXYtOGgxMi40djhjMCwuNy4yOSwxLDEsMWgzLjExYy43LDAsMS0uMjksMS0xVjFDMjIuNjIuMzIsMjIuMzMsMCwyMS42MywwWiIvPjwvZz48L2c+PC9nPjwvZz48L3N2Zz4=\" alt=\"Hetzner\" width=\"181\" height=\"22\"></a></div>";
|
|
export const SHARED_FOOTER = `<footer class="dune-shared-footer" data-shared-chrome="3"><a class="dune-footer-brand" href="https://www.dunerealms.com/">✦ dunerealms.com</a><nav aria-label="Footer navigation"><a href="https://wiki.dunerealms.com/">Dunopedia</a><a href="https://support.dunerealms.com/">Support</a><a href="https://cp.dunerealms.com/">Account</a><a href="https://www.dunerealms.com/wiki.html">Disclaimer & contact</a><a data-dune-git-footer="1" href="https://www.dunerealms.com/git/unimatrix/MC">DuneGit</a><a data-dune-api-footer="1" href="https://www.dunerealms.com/api.html">Developer API</a><a data-bank-rates="1" href="https://www.dunerealms.com/rates-and-charges.html">Rates & Charges</a></nav>${FOOTER_SPONSORS}<small>Independent fan project · Not affiliated with Dune rights holders, Mojang or Microsoft.</small></footer>`;
|
|
export function applySharedFooter(html){
|
|
const existing=html.match(/<footer\b[^>]*>[\s\S]*?<\/footer>/);
|
|
if(!existing)return html.replace('</body>',SHARED_FOOTER+'</body>');
|
|
// 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('</footer>',/dune-memorial|Patrick Stewart/i.test(memorial)?'</footer>':memorial+'</footer>'));
|
|
}
|
|
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(/<header\b[^>]*class="[^"]*dune-site-header/.test(html))return html.replace(/<header\b[^>]*class="[^"]*dune-site-header[^"]*"[^>]*>[\s\S]*?<\/header>/,header);
|
|
// Non-homepage legacy mastheads are compiled into the shared header as before.
|
|
if(html.includes('<header class="masthead">')){
|
|
const start=html.indexOf('<div class="utility">'),end=html.indexOf('<main');
|
|
if(start<0||end<start)throw Error('Legacy chrome boundary missing');
|
|
return html.slice(0,start)+header.replace('class="dr-header-account"','class="dr-header-account" data-play')+'\n'+html.slice(end);
|
|
}
|
|
return html;
|
|
}
|
|
|
|
export function cleanLegacyChromeScript(script){return script.replace(/\(\(\)=>\{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(/<header\b[^>]*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;
|
|
}
|

Staff