`;
// Close modal when clicking overlay
modal.addEventListener('click', (e) => {
if (e.target === modal) {
modal.remove();
}
});
document.body.appendChild(modal);
// Generate QR code
generateBitcoinQR(`bitcoin:${address}`, 'qr-container');
}
function generateBitcoinQR(bitcoinUri, containerId) {
// Use QR Server API to generate QR code
const qrContainer = document.getElementById(containerId);
const size = 200;
const qrUrl = `https://api.qrserver.com/v1/create-qr-code/?size=${size}x${size}&data=${encodeURIComponent(bitcoinUri)}&margin=2`;
qrContainer.innerHTML = `
`;
}
// Main function to load item details
async function loadItemDetails() {
const uri = getQueryParam('uri');
const display = getQueryParam('display');
const parent_frame = getQueryParam('parent_frame');
const theme = getQueryParam('theme');
// Hide navigation if display mode is set
if (display) {
let nav = document.querySelector("#navigation")
if (nav) {
nav.style.display = 'none';
}
}
if (!uri) {
document.getElementById('profileSection').innerHTML = `
No Item Selected
Please select an item from the home page.
`;
return;
}
// Reset state
currentLinks = [];
currentPosts = [];
try {
// Load featured data
const featuredItems = await loadFeaturedData();
// Check if it's a GitHub URL
const githubRegex = /github\.com\/(.+)\/(.+)/i;
const match = githubRegex.exec(uri);
let item = {};
if (match && match.length > 0) {
// It's a GitHub URL - fetch repo data
const owner = match[1];
const repo = match[2];
const repoData = await fetchGitHubRepo(owner, repo);
if (repoData) {
let downloadURL
if (parent_frame) {
downloadURL = `${parent_frame}?mode=download&uri=${repoData.html_url}`
} else {
downloadURL = `pinokio://download?uri=${repoData.html_url}`
}
item = {
title: repoData.name,
description: repoData.description,
image: repoData.owner.avatar_url,
url: repoData.html_url,
path: repoData.full_name,
download: repoData.html_url,
downloadURL,
id: repoData.full_name
};
// Fetch additional metadata
await fetchPinokioMeta(repoData.full_name);
}
}
// Check if this item is in featured list and override with featured data
for (const featuredItem of featuredItems) {
if (featuredItem.url.toLowerCase() === uri.toLowerCase() ||
(item.url && featuredItem.url.toLowerCase() === item.url.toLowerCase())) {
// Override with featured data
if (featuredItem.title) item.title = featuredItem.title;
if (featuredItem.image) item.image = featuredItem.image;
if (featuredItem.url) item.url = featuredItem.url;
if (featuredItem.path) item.path = featuredItem.path;
if (featuredItem.description) item.description = featuredItem.description;
if (featuredItem.download) item.download = featuredItem.download;
if (featuredItem.version) item.version = featuredItem.version;
if (featuredItem.branch) item.branch = featuredItem.branch;
if (featuredItem.author_avatar) item.author_avatar = featuredItem.author_avatar;
if (featuredItem.author_url) item.author_url = featuredItem.author_url;
if (featuredItem.author_username) item.author_username = featuredItem.author_username;
if (featuredItem.links && Array.isArray(featuredItem.links)) {
currentLinks = featuredItem.links;
}
// Update download URL
if (parent_frame) {
item.downloadURL = `${parent_frame}?mode=download&uri=${item.download}`
} else {
item.downloadURL = `pinokio://download?uri=${item.download}`
}
if (item.branch) {
item.downloadURL += "&branch=" + item.branch;
}
break;
}
}
// If no GitHub match, check featured items directly
if (!match) {
for (const featuredItem of featuredItems) {
if (featuredItem.url.toLowerCase() === uri.toLowerCase()) {
item = { ...featuredItem };
if (parent_frame) {
item.downloadURL = `${parent_frame}?mode=download&uri=${item.download}`
} else {
item.downloadURL = `pinokio://download?uri=${item.download}`
}
if (item.branch) {
item.downloadURL += "&branch=" + item.branch;
}
if (item.links && Array.isArray(item.links)) {
currentLinks = item.links;
}
break;
}
}
}
currentItem = item;
// Render the UI based on display mode
if (!display || display === 'profile') {
renderItemProfile(item);
}
if (!display || display === 'feed') {
const container = document.getElementById('tweetsContainer');
renderTweets(container, currentPosts);
}
} catch (error) {
console.error('Error loading item details:', error);
document.getElementById('profileSection').innerHTML = `