`;
const website_icon = ``;
const email_icon = ``;
const fb_icon = ``;
const getName = () => {
const { hostname } = window.location;
if (hostname.endsWith('deweb.me') > -1) {
return hostname.replace('.deweb.me', '');
} else if (hostname.endsWith('.onl') > -1) {
return hostname.replace('.onl', '');
} else {
return hostname.split('.')?.shift();
}
}
const name = getName();
document.title = `BLob | ${name}`;
const getTweets = async () => {
try {
const res = await fetch(`https://apiprd.sat20.org/mainnet/ns/values/${name}/blog`)
const data = await res.json()
const a = data?.data?.kvs || []
return a.map(kv => ({
t: kv.key.replace('blog_', ''),
c: kv.value,
h: kv.inscriptionId
}));
} catch (error) {
return [];
}
}
const getPersonalInfo = async () => {
try {
const res = await fetch(`https://apiprd.sat20.org/mainnet/ns/name/${name}`)
const data = await res.json()
const a = data?.data?.kvs || []
const avatar = a.find(kv => kv.key === 'avatar')?.value || '';
const userName = a.find(kv => kv.key === 'personal_name')?.value || name;
const desc = a.find(kv => kv.key === 'personal_desc')?.value || '';
const twitter_link = a.find(kv => kv.key === 'personal_twitter')?.value || '';
const website_link = a.find(kv => kv.key === 'personal_website')?.value || '';
const email_link = a.find(kv => kv.key === 'personal_email')?.value || '';
const fb_link = a.find(kv => kv.key === 'personal_facebook')?.value || '';
const links = [];
if (twitter_link) {
links.push({
label: "twitter",
href: twitter_link
})
}
if (website_link) {
links.push({
label: "website",
href: website_link
})
}
if (email_link) {
links.push({
label: "email",
href: email_link
})
}
if (fb_link) {
links.push({
label: "facebook",
href: fb_link
})
}
return {
avatar,
name: userName,
desc,
links,
}
} catch (error) {
return {
avatar: '',
name,
desc: '',
links: []
};
}
}
document.addEventListener('DOMContentLoaded', async () => {
function renderPersonalInfo(info) {
const { avatar, name, desc, links } = info;
const aside = document.querySelector('.profile');
aside.querySelector('.avatar iframe').src = `https://ordinals.com/preview/${avatar}`;
aside.querySelector('h1').textContent = name;
aside.querySelector('p').textContent = desc;
links.forEach(({ label, href }) => {
const linkEl = document.createElement('a');
linkEl.href = href;
linkEl.target = '_blank';
let src = website_icon
if (label === 'twitter') {
src = twitter_icon
} else if (label === 'email') {
src = email_icon
linkEl.href = `mailto:${href}`
linkEl.target = '';
} else if (label === 'facebook') {
src = fb_icon
}
const base64Svg = btoa(src);
const imgSrc = `data:image/svg+xml;base64,${base64Svg}`;
linkEl.innerHTML = ``
aside.querySelector('.contacts').appendChild(linkEl)
})
}
const personalInfo = await getPersonalInfo();
renderPersonalInfo(personalInfo);
const tweets = await getTweets();
function renderTweets(tweets) {
const tweetContainer = document.querySelector('.twitter-feed');
tweets.forEach(tweet => {
const time = new Date(parseInt(tweet.t)).toLocaleString();
const tweetElement = document.createElement('div');
tweetElement.className = 'tweet';
const href = `https://ordinals.com/content/${tweet.h}`;
tweetElement.innerHTML = `
`;
tweetContainer.appendChild(tweetElement);
});
}
renderTweets(tweets);
});