// Main application script // GitHub API configuration const GITHUB_USERNAME = 'JoelA510'; const GITHUB_API_URL = `https://api.github.com/users/${GITHUB_USERNAME}/repos`; const PROJECTS_TO_SHOW = 4; // DOM Elements const projectsContainer = document.getElementById('projects-container'); // Fetch and display GitHub projects async function loadGitHubProjects() { try { // Show loading state projectsContainer.innerHTML = `
Loading projects...
`; const response = await fetch(GITHUB_API_URL); if (!response.ok) { throw new Error(`GitHub API error: ${response.status}`); } const repos = await response.json(); // Sort by last updated and take the most recent ones const recentRepos = repos .sort((a, b) => new Date(b.updated_at) - new Date(a.updated_at)) .slice(0, PROJECTS_TO_SHOW); // Clear loading state projectsContainer.innerHTML = ''; // Create project cards recentRepos.forEach((repo, index) => { const projectCard = document.createElement('project-card'); projectCard.setAttribute('title', repo.name); projectCard.setAttribute('description', repo.description || 'No description available'); projectCard.setAttribute('language', repo.language || 'Various'); projectCard.setAttribute('stars', repo.stargazers_count); projectCard.setAttribute('forks', repo.forks_count); projectCard.setAttribute('url', repo.html_url); projectCard.setAttribute('updated', new Date(repo.updated_at).toLocaleDateString()); projectCard.setAttribute('delay', index * 100); // Add progress visualization (simulated based on repo metrics) const progress = calculateProgress(repo); projectCard.setAttribute('progress', progress); projectsContainer.appendChild(projectCard); }); } catch (error) { console.error('Error loading GitHub projects:', error); projectsContainer.innerHTML = `

Unable to load projects

Please check your connection or try again later.

`; feather.replace(); } } // Calculate progress based on repository metrics function calculateProgress(repo) { // Simulate progress based on various factors let progress = 50; // Base progress // Adjust based on repository activity if (repo.has_pages) progress += 10; if (repo.has_issues) progress += 5; if (repo.has_projects) progress += 5; if (repo.has_wiki) progress += 5; // Adjust based on size (more files = more complete) if (repo.size > 1000) progress += 10; // Adjust based on age (newer = less complete) const daysSinceUpdate = (new Date() - new Date(repo.updated_at)) / (1000 * 60 * 60 * 24); if (daysSinceUpdate > 30) progress += 15; // Older projects might be more complete if (daysSinceUpdate > 90) progress += 10; // Cap at 100 return Math.min(progress, 100); } // Smooth scroll for anchor links document.addEventListener('DOMContentLoaded', function() { // Smooth scroll for anchor links document.querySelectorAll('a[href^="#"]').forEach(anchor => { anchor.addEventListener('click', function (e) { e.preventDefault(); const targetId = this.getAttribute('href'); if (targetId === '#') return; const targetElement = document.querySelector(targetId); if (targetElement) { window.scrollTo({ top: targetElement.offsetTop - 100, behavior: 'smooth' }); } }); }); // Add animation classes on scroll const observerOptions = { threshold: 0.1, rootMargin: '0px 0px -50px 0px' }; const observer = new IntersectionObserver((entries) => { entries.forEach(entry => { if (entry.isIntersecting) { entry.target.classList.add('animate-fadeInUp'); } }); }, observerOptions); // Observe elements to animate document.querySelectorAll('section > div').forEach(section => { observer.observe(section); }); // Initialize tooltips document.querySelectorAll('[data-tooltip]').forEach(element => { element.addEventListener('mouseenter', function() { const tooltip = document.createElement('div'); tooltip.className = 'absolute z-50 px-3 py-2 text-sm text-white bg-gray-900 rounded-lg shadow-lg'; tooltip.textContent = this.getAttribute('data-tooltip'); tooltip.style.top = `${this.offsetTop - 40}px`; tooltip.style.left = `${this.offsetLeft + this.offsetWidth / 2 - tooltip.offsetWidth / 2}px`; document.body.appendChild(tooltip); this.dataset.tooltipElement = tooltip; }); element.addEventListener('mouseleave', function() { if (this.dataset.tooltipElement) { document.body.removeChild(this.dataset.tooltipElement); delete this.dataset.tooltipElement; } }); }); // Initialize theme (light mode by default) document.documentElement.classList.remove('dark'); document.documentElement.classList.add('light'); // Load GitHub projects loadGitHubProjects(); }); // Utility function to format numbers function formatNumber(num) { if (num >= 1000000) { return (num / 1000000).toFixed(1) + 'M'; } if (num >= 1000) { return (num / 1000).toFixed(1) + 'K'; } return num.toString(); } // Export functions for use in components window.PortfolioUtils = { formatNumber, loadGitHubProjects };