web/website/scripts/realm-switch.mjs
2026-11-27 23:43:05 +00:00

8 lines
2.8 KiB
JavaScript

export function realmSurface(url){const u=new URL(url,'https://www.dunerealms.com');if(u.hostname==='clans.dunerealms.com')return 'clan';if(u.hostname==='corp.dunerealms.com')return 'company';if(u.hostname==='pol.dunerealms.com'||u.hostname==='www.dunerealms.com'&&u.pathname==='/government.html')return 'politics';return null;}
// Realm Hub in the primary header owns workspace switching.
export function renderRealmSwitch(doc,url){doc.querySelector('[data-realm-switch]')?.remove();}
export const REALM_SWITCH_CSS=`
.dune-context-banner:has(.dune-realm-switch){flex-wrap:wrap;gap:18px;padding-top:14px;padding-bottom:14px}.dune-realm-switch{display:flex;gap:12px;justify-content:center;order:1;margin:auto;max-width:100%;box-sizing:border-box}.dune-realm-choice{position:relative;display:flex;align-items:center;gap:12px;min-width:150px;padding:12px 20px;border:3px double #b99a55;border-radius:10px;background:linear-gradient(145deg,#214939ed,#0d241fed);color:#efd797;text-decoration:none;box-shadow:inset 0 0 0 3px #122b23,0 4px 9px #0005;box-sizing:border-box}.dune-realm-company{background:linear-gradient(145deg,#28495bed,#102831ed)}.dune-realm-politics{background:linear-gradient(145deg,#493954ed,#182a2aed)}.dune-realm-choice img{width:52px;height:52px;object-fit:contain;filter:drop-shadow(0 3px 4px #0008)}.dune-realm-choice strong{display:block;font:700 20px Georgia,serif}.dune-realm-choice small{display:block;margin-top:5px;color:#d1c29d;font:11px Arial,sans-serif}.dune-realm-choice[aria-current]{border-color:#f2d17e;box-shadow:inset 0 0 0 3px #b2954d55,0 0 16px #e3bb5633}.dune-realm-active{position:absolute;right:8px;top:-9px;padding:3px 7px;background:#bd9c53;color:#10251e;font:700 9px Arial,sans-serif;letter-spacing:.08em;border-radius:4px}.dune-realm-choice:hover,.dune-realm-choice:focus-visible{outline:2px solid #f1d58f;outline-offset:3px}@media(max-width:1100px){.dune-realm-switch{flex-basis:100%;order:3}}@media(max-width:600px){.dune-realm-switch{gap:7px;width:100%}.dune-realm-choice{flex:1;min-width:0;padding:12px 5px;gap:6px;flex-direction:column;text-align:center}.dune-realm-choice img{width:38px;height:38px}.dune-realm-choice strong{font-size:15px}.dune-realm-choice small{display:none}.dune-realm-active{font-size:8px;right:4px}}
`;
export const REALM_SWITCH_SCRIPT='\n/* Dune realm switch begin */\n(()=>{if(window.top!==window.self)return;const realmSurface='+realmSurface.toString()+';const renderRealmSwitch='+renderRealmSwitch.toString()+';const sync=()=>renderRealmSwitch(document,location.href);sync();new MutationObserver(sync).observe(document.body,{childList:true,subtree:true});})();\n/* Dune realm switch end */\n';
export function withRealmSwitch(source){return source.replace(/\n?\/\* Dune realm switch begin \*\/[^]*?\/\* Dune realm switch end \*\/\n?/g,'')+REALM_SWITCH_SCRIPT;}