function escapeHtml(str) {
if (!str) return '';
return String(str)
.replace(/&/g, '&')
.replace(//g, '>')
.replace(/"/g, '"')
.replace(/'/g, ''');
}
function getLinkIconHtml(iconStr, linkUrl) {
if (iconStr === 'favicon') {
let domain = '';
try {
if (linkUrl) {
let u = linkUrl.trim();
if (!u.startsWith('http://') && !u.startsWith('https://')) {
u = 'https://' + u;
}
domain = new URL(u).hostname;
}
} catch (e) {}
if (domain) {
const favUrl = `https://www.google.com/s2/favicons?domain=${encodeURIComponent(domain)}&sz=64`;
return `
`;
}
return ``;
}
if (iconStr && (iconStr.startsWith('http://') || iconStr.startsWith('https://'))) {
const safeIcon = escapeHtml(iconStr);
return `
`;
}
const safeClass = escapeHtml(iconStr || 'fas fa-link');
return ``;
}
async function loadBioProfile() {
const hostname = window.location.hostname;
const res = await fetch('/api/bio/profile/' + hostname);
if (!res.ok) {
document.getElementById('bioName').textContent = 'Profile Not Configured';
document.getElementById('bioText').textContent = 'This handle owner has not configured their bio links yet.';
return;
}
const data = await res.json();
const p = data.profile;
if (p.is_disabled === 1 || p.is_disabled === true) {
document.getElementById('bioContainer').innerHTML = `
⚠️
Link Aggregator Suspended
This link aggregator page has been disabled by an Administrator due to a policy violation or security review.
If you are the handle owner, please contact your Administrator to request re-activation.
`;
return;
}
if (p.theme) {
document.body.className = 'theme-' + p.theme;
}
if (p.bg_image_url) {
document.getElementById('bioBgOverlay').style.backgroundImage = 'url("' + p.bg_image_url + '")';
}
if (p.bg_overlay_opacity !== undefined && p.bg_overlay_opacity !== null) {
document.getElementById('bioDarkOverlay').style.backgroundColor = 'rgba(0,0,0,' + p.bg_overlay_opacity + ')';
}
document.title = (p.display_name || p.handle) + ' (@' + p.handle + ')';
document.getElementById('bioName').textContent = p.display_name || p.handle;
document.getElementById('bioHandleText').textContent = '@' + p.handle;
document.getElementById('bioHandleLink').href = 'https://bsky.app/profile/' + p.handle;
document.getElementById('bioText').textContent = p.bio_text || '';
if (p.avatar_url) {
document.getElementById('bioAvatar').src = p.avatar_url;
}
const container = document.getElementById('linksList');
container.innerHTML = '';
if (p.items && p.items.length > 0) {
p.items.forEach(item => {
if (item.is_enabled === 0) return;
if (item.block_type === 'folder') {
const folderCard = document.createElement('div');
folderCard.className = 'bio-folder-card';
const folderHeader = document.createElement('div');
folderHeader.className = 'bio-folder-header';
const is18 = item.is_18plus === 1;
folderHeader.onclick = () => {
if (is18 && sessionStorage.getItem('sqpds_18plus_confirmed') !== 'true') {
showAgeConsentModal(() => folderCard.classList.add('open'));
} else {
folderCard.classList.toggle('open');
}
};
folderHeader.innerHTML = `
${getLinkIconHtml(item.icon, '')}
${escapeHtml(item.label)}
${is18 ? '🔞 18+' : ''}
`;
folderCard.appendChild(folderHeader);
const folderContent = document.createElement('div');
folderContent.className = 'bio-folder-content';
if (item.items && item.items.length > 0) {
item.items.forEach(child => {
if (child.is_enabled === 0) return;
const childCard = document.createElement('a');
childCard.className = 'bio-link-card';
childCard.href = child.url;
childCard.target = '_blank';
childCard.onclick = () => {
fetch('/api/bio/track', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ handle: p.handle, eventType: 'link_click', linkId: child.id })
});
};
childCard.innerHTML = `
${getLinkIconHtml(child.icon, child.url)}
${escapeHtml(child.label)}
`;
folderContent.appendChild(childCard);
});
}
folderCard.appendChild(folderContent);
container.appendChild(folderCard);
} else {
const card = document.createElement('a');
card.className = 'bio-link-card';
card.href = item.url;
card.target = '_blank';
card.onclick = () => {
fetch('/api/bio/track', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ handle: p.handle, eventType: 'link_click', linkId: item.id })
});
};
card.innerHTML = `
${getLinkIconHtml(item.icon, item.url)}
${escapeHtml(item.label)}
`;
container.appendChild(card);
}
});
}
// Record page view analytics
fetch('/api/bio/track', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ handle: p.handle, eventType: 'page_view' })
});
}
function showAgeConsentModal(onSuccess) {
const existing = document.getElementById('bioAgeModalOverlay');
if (existing) existing.remove();
const overlay = document.createElement('div');
overlay.id = 'bioAgeModalOverlay';
overlay.className = 'bio-age-modal-overlay';
overlay.innerHTML = `
🔞
Age Restricted Content (18+)
This section contains age-restricted links. By proceeding, you confirm that you are at least 18 years of age or older.
`;
document.body.appendChild(overlay);
document.getElementById('bioAgeConfirmBtn').onclick = () => {
sessionStorage.setItem('sqpds_18plus_confirmed', 'true');
overlay.remove();
if (typeof onSuccess === 'function') onSuccess();
};
document.getElementById('bioAgeCancelBtn').onclick = () => {
overlay.remove();
};
}
loadBioProfile();