forked from unimatrix/web
30 lines
5.4 KiB
JavaScript
30 lines
5.4 KiB
JavaScript
const $=id=>document.getElementById(id),el=(tag,value,cls)=>{const n=document.createElement(tag);if(value!=null)n.textContent=value;if(cls)n.className=cls;return n;};
|
||
const text=(id,value)=>{$(id).textContent=value??'—';},username=decodeURIComponent(location.pathname.split('/').filter(Boolean)[1]||'');
|
||
function sealCard(m){const card=el('figure',null,'profile-seal'),image=el('img');image.src=m.url;image.alt=m.label;image.loading='lazy';image.width=image.height=128;card.append(image,el('figcaption',m.label),el('small',m.group||'Recognition'));return card;}
|
||
function render(p){
|
||
document.title=(p.displayName||p.username)+' | DuneRealms';text('passport-title',p.displayName||p.username);text('handle','@'+p.username);text('status',p.showcase?'Verified official DuneRealms account':'DuneRealms community member');if(p.showcase){text('recognition-title','Seal & award showcase');text('recognition-description','The general DuneRealms catalogue. Personal seals and the Holy Order of the Crysknife are excluded.');}text('joined',p.joinedAt?new Date(p.joinedAt).toLocaleDateString('en-GB'):null);text('clan',p.clan?.status==='member'?p.clan.name:'No clan listed');text('forum',p.forum?.status==='linked'?p.forum.username:'Not linked');
|
||
if(typeof p.avatar==='string'&&/^https:\/\/cp\.dunerealms\.com\/api\/avatars\//.test(p.avatar)){$('avatar').src=p.avatar;$('avatar').hidden=false;}
|
||
for(const rank of p.ranks||[]){if(rank.label==='Unknown rank')continue;const chip=el('span',rank.label,'chip');chip.dataset.staff=String(rank.key.startsWith('org_'));$('ranks').append(chip);}
|
||
const functions=p.functions||[];
|
||
for(const f of functions){const card=el('article',null,'profile-function');card.append(el('strong',f.roleLabel),el('span',f.scopeLabel));$('department').append(card);}
|
||
if(!functions.length)$('department').append(el('p','No staff functions listed.','muted'));
|
||
if(p.support?.status==='available')text('tickets',(p.support.closed??0)+' verified support tickets closed');
|
||
if(p.bio)text('bio',p.bio);if(p.publicInfo){text('public-info',p.publicInfo);$('public-info').hidden=false;}
|
||
for(const [label,value]of Object.entries(p.socials||{})){try{const u=new URL(value);if(u.protocol!=='https:'||u.username||u.password)continue;const a=el('a',label,'chip');a.href=u.href;a.rel='noopener noreferrer';a.target='_blank';$('socials').append(a);}catch{}}
|
||
const medals=(p.medals||[]).filter(m=>typeof m.url==='string'&&/^https:\/\/(www|support|forums)\.dunerealms\.com\/assets\/seals\/[a-zA-Z0-9_./-]+\.png$/.test(m.url));
|
||
const personal=medals.find(m=>m.key==='personal-role');if(personal){$('personal-seal-panel').hidden=false;$('personal-seal').append(sealCard(personal));}
|
||
if(!p.showcase&&(p.ranks||[]).some(r=>r.key==='crysknife'))$('order-panel').hidden=false;
|
||
const groups=new Map();for(const m of medals){if(['personal-role','rank-crysknife'].includes(m.key))continue;const group=m.group||'Recognition';if(!groups.has(group))groups.set(group,[]);groups.get(group).push(m);}
|
||
for(const [name,items]of groups){const section=el('section'),cards=el('div',null,'profile-awards');section.append(el('h3',name));for(const m of items)cards.append(sealCard(m));section.append(cards);$('seals').append(section);}
|
||
if(!groups.size)$('seals').append(el('p','No additional seals or awards recorded.','muted'));
|
||
if(/^\/memorial\/[a-z0-9-]+$/.test(p.memorial||'')){const a=el('a','Visit community memorial →','chip');a.href=p.memorial;$('socials').append(a);text('status','Community remembrance profile');}
|
||
const community=(heading,value,note,link)=>{const c=el('article');c.append(el('h3',heading),el('strong',value),el('small',note));if(link){const a=el('a','Open →');a.href=link;c.append(el('br'),a);}$('community').append(c);return c;};
|
||
if(p.forum?.status==='linked')community('Forum contributions',String(p.forum.posts||0)+' posts',String(p.forum.threads||0)+' threads · '+String(p.forum.reputation||0)+' reputation',p.forum.url);
|
||
else community('Forum','Not linked','No linked forum record is available.');
|
||
const clanImage=el('img');clanImage.src=p.clan?.emblem||'https://www.dunerealms.com/assets/nav-clan-v2.webp';clanImage.alt=p.clan?.status==='member'?p.clan.name+' clan emblem':'Clan placeholder';clanImage.width=clanImage.height=110;clanImage.className='profile-clan-emblem';
|
||
if(p.clan?.status==='member')community('Clan',p.clan.name,(p.clan.role||'Member')+' · '+String(p.clan.members||0)+' members','https://clans.dunerealms.com/').prepend(clanImage);
|
||
else community('Clan','No membership listed','Clan membership is maintained by the clan system.').prepend(clanImage);
|
||
community('Adventures',p.quests?.completed==null?'No verified totals':String(p.quests.completed)+' completed',p.quests?.completed==null?'Quest statistics are not connected yet.':'Verified quest progress');
|
||
}
|
||
async function load(){if(!/^[a-z0-9_]{3,32}$/.test(username)){text('status','Invalid profile name');return;}text('handle','@'+username);try{const response=await fetch('https://cp.dunerealms.com/api/people/'+encodeURIComponent(username),{credentials:'include',cache:'no-store'});if(response.status===401){text('status','Sign in to view this member’s profile.');const a=el('a','Sign in');a.href='https://cp.dunerealms.com/?return_to='+encodeURIComponent('/people/'+username);$('status').append(' ',a);return;}if(!response.ok){text('status',response.status===404?'Profile not found':'Profile temporarily unavailable');return;}render((await response.json()).profile);}catch{text('status','Unable to load the profile. Please try again.');}}
|
||
void load();
|

Staff