document.addEventListener('DOMContentLoaded', () => { const repoForm = document.getElementById('repoForm'); const loading = document.getElementById('loading'); const results = document.getElementById('results'); repoForm.addEventListener('submit', async (e) => { e.preventDefault(); const username = document.getElementById('username').value.trim(); const repo = document.getElementById('repo').value.trim(); if (!username || !repo) { alert('Please enter both GitHub username and repository name'); return; } // Show loading indicator loading.classList.remove('hidden'); results.classList.add('hidden'); try { const response = await fetch(`https://api.github.com/repos/${username}/${repo}`); if (!response.ok) { throw new Error('Repository not found or API rate limit exceeded'); } const data = await response.json(); displayResults(data, username, repo); // Fetch README.md content const readmeResponse = await fetch(`https://api.github.com/repos/${username}/${repo}/readme`, { headers: { 'Accept': 'application/vnd.github.v3.raw' } }); if (readmeResponse.ok) { const readmeContent = await readmeResponse.text(); displayReadme(readmeContent); } } catch (error) { results.innerHTML = `
${error.message}
${data.description || 'No description'}
$1')
.replace(/!\[(.*?)\]\((.*?)\)/g, 'No README found for this repository.
'; } } });