forked from unimatrix/web
19 lines
4.7 KiB
JavaScript
19 lines
4.7 KiB
JavaScript
(()=>{
|
||
if(!['/','/index.html'].includes(location.pathname)||window.top!==window.self)return;
|
||
const main=document.querySelector('main#main');if(!main)return;
|
||
const el=(tag,text,cls)=>{const node=document.createElement(tag);if(text!==undefined)node.textContent=text;if(cls)node.className=cls;return node;};
|
||
const link=(label,href)=>{const a=el('a',label);a.href=href;return a;};
|
||
document.body.classList.add('portal-community');
|
||
const center=el('div',undefined,'portal-stories'),right=el('aside',undefined,'portal-realm-status');right.setAttribute('aria-label','Your realm briefing');
|
||
const previous=[...main.children];main.replaceChildren(center,right);for(const node of previous)center.append(node);
|
||
const report=el('iframe',undefined,'portal-mentat-frame');report.src='https://cp.dunerealms.com/mentat-report';report.title='Your personal Mentat Report';report.setAttribute('sandbox','allow-scripts allow-same-origin allow-top-navigation-by-user-activation');report.height='840';right.append(report);
|
||
window.addEventListener('message',event=>{if(event.origin!=='https://cp.dunerealms.com'||event.source!==report.contentWindow||event.data?.type!=='dune:mentat-size'||!Number.isSafeInteger(event.data.height)||event.data.height<100||event.data.height>1800)return;report.height=String(event.data.height);});
|
||
const sales=el('section',undefined,'portal-community-card portal-shop-sales');const logo=el('img');logo.src='/assets/imperial-heralds-logo-v1.png';logo.alt='Imperial Heralds';logo.width=260;logo.height=90;const saleHeading=el('div',undefined,'portal-sale-heading');saleHeading.append(el('span','SPECIAL OFFERS','portal-sale-ribbon'),el('h2','Shop Sales'));const saleItems=el('div',undefined,'portal-sale-items'),saleState=el('p','Opening the Imperial Heralds offers…','portal-sale-state');saleState.setAttribute('role','status');const shopLink=link('Explore all offers →','https://shop.dunerealms.com/catalog/EUR/catalog/sales');shopLink.className='portal-sale-action';sales.append(logo,saleHeading,saleState,saleItems,shopLink);right.append(sales);
|
||
void fetch('/api/shop-sales',{cache:'default',credentials:'omit'}).then(async response=>{if(!response.ok)throw Error();return response.json();}).then(data=>{if(data.source!=='oscommerce'||!Array.isArray(data.items))throw Error();window.dispatchEvent(new CustomEvent('dune:shop-promotions',{detail:{active:data.items.length>0,source:'oscommerce'}}));if(!data.items.length){shopLink.href='https://shop.dunerealms.com/catalog/EUR/catalog/all-products';shopLink.textContent='Browse the collection →';}saleState.textContent=data.items.length?'Selected offers from our osCommerce shop.':'No active sales right now. Explore the collection.';for(const item of data.items){const card=el('a',undefined,'portal-sale-product');card.href=item.url;const image=el('img');image.src=item.image||'/assets/imperial-heralds-logo-v1.png';image.alt=item.name;image.loading='lazy';image.onerror=()=>{image.onerror=null;image.src='/assets/imperial-heralds-logo-v1.png';};const copy=el('div'),prices=el('div',undefined,'portal-sale-prices');prices.append(el('del',item.regularPrice),el('strong',item.salePrice));copy.append(el('span','−'+item.savingPercent+'%','portal-sale-saving'),el('h3',item.name),prices,el('span','View offer →','portal-sale-view'));card.append(image,copy);saleItems.append(card);}}).catch(()=>{saleState.textContent='Current offers are temporarily unavailable. Visit Imperial Heralds to browse the collection.';});
|
||
for(const [title,copy,href,label]of [['Around the realm','Explore the latest discussions and meet the organisations shaping the season.','https://forums.dunerealms.com/','Visit the forums →'],['Upcoming events','Event highlights will appear here when the portal event feed is connected.',null,null],['Community gallery','A place for player creations and stories. Gallery publishing is not connected yet.',null,null]]){
|
||
const section=el('section',undefined,'panel portal-community-card');section.append(el('h2',title),el('p',copy));if(href)section.append(link(label,href));else section.append(el('span','Preview · awaiting connection','portal-placeholder'));center.append(section);
|
||
}
|
||
const featured=el('section',undefined,'portal-community-card');featured.append(el('h2','Featured travellers'),el('p','Community spotlights will be published here.'),el('span','Preview · no featured members selected','portal-placeholder'));right.append(featured);
|
||
function arrange(){const worlds=document.querySelector('.world-status');if(worlds&&worlds.parentElement!==right)right.insertBefore(worlds,featured);const welcome=document.querySelector('.dune-page-marker');if(welcome&&welcome.parentElement!==center)center.prepend(welcome);}
|
||
arrange();new MutationObserver(arrange).observe(document.body,{childList:true,subtree:true});
|
||
})();
|

Staff