// Global variables let clientsData = []; let serversData = []; let allData = []; let filteredData = []; let currentView = 'grid'; let currentPage = 1; let itemsPerPage = 20; let totalPages = 1; // DOM Elements const navItems = document.querySelectorAll('.nav-item'); const pages = document.querySelectorAll('.page'); const searchInput = document.getElementById('search-input'); const typeFilter = document.getElementById('type-filter'); const categoryFilter = document.getElementById('category-filter'); const languageFilter = document.getElementById('language-filter'); const searchResults = document.getElementById('search-results'); const resultsCount = document.getElementById('results-count'); const viewButtons = document.querySelectorAll('.view-btn'); const modal = document.getElementById('project-modal'); const modalTitle = document.getElementById('modal-title'); const modalBody = document.getElementById('modal-body'); const modalClose = document.querySelector('.modal-close'); const paginationContainer = document.getElementById('pagination-container'); const prevBtn = document.getElementById('prev-btn'); const nextBtn = document.getElementById('next-btn'); const pageNumbers = document.getElementById('page-numbers'); const paginationInfo = document.getElementById('pagination-info'); // Initialize app document.addEventListener('DOMContentLoaded', async () => { await loadData(); setupEventListeners(); updateDashboard(); initializeSearch(); }); // Load data from JSON files with optimization async function loadData() { try { showLoading(); const [clientsResponse, serversResponse] = await Promise.all([ fetch('mcpso_clients_cleaned.json'), fetch('mcpso_servers_cleaned.json') ]); if (!clientsResponse.ok || !serversResponse.ok) { throw new Error('Failed to fetch data'); } clientsData = await clientsResponse.json(); serversData = await serversResponse.json(); // Combine all data and deduplicate by GitHub repository const rawData = [ ...clientsData.map(item => ({ ...item, type: 'client' })), ...serversData.map(item => ({ ...item, type: 'server' })) ]; // Process and deduplicate data allData = processAndDeduplicateData(rawData); filteredData = [...allData]; console.log(`Loaded ${clientsData.length} clients and ${serversData.length} servers (${allData.length} total projects)`); hideLoading(); } catch (error) { console.error('Error loading data:', error); showError('Failed to load data. Please refresh the page.'); hideLoading(); } } // Setup event listeners function setupEventListeners() { // Navigation navItems.forEach(item => { item.addEventListener('click', () => switchPage(item.dataset.page)); }); // Search and filters searchInput.addEventListener('input', debounce(performSearch, 300)); typeFilter.addEventListener('change', performSearch); categoryFilter.addEventListener('change', performSearch); languageFilter.addEventListener('change', performSearch); // View toggle viewButtons.forEach(btn => { btn.addEventListener('click', () => toggleView(btn.dataset.view)); }); // Modal modalClose.addEventListener('click', closeModal); modal.addEventListener('click', (e) => { if (e.target === modal) closeModal(); }); document.addEventListener('keydown', (e) => { if (e.key === 'Escape') closeModal(); }); // Pagination prevBtn.addEventListener('click', () => { if (currentPage > 1) { currentPage--; renderSearchResults(); renderPagination(); } }); nextBtn.addEventListener('click', () => { if (currentPage < totalPages) { currentPage++; renderSearchResults(); renderPagination(); } }); } // Switch between pages function switchPage(pageId) { // Update navigation navItems.forEach(item => { item.classList.toggle('active', item.dataset.page === pageId); }); // Update pages pages.forEach(page => { page.classList.toggle('active', page.id === pageId); }); // Initialize page-specific content if (pageId === 'search') { // Reset pagination when switching to search page currentPage = 1; performSearch(); populateFilters(); } } // Process and deduplicate data based on GitHub repository function processAndDeduplicateData(rawData) { const githubMap = new Map(); const processedData = []; for (const item of rawData) { // Only process items with valid GitHub data if (item.github && item.github.full_name && item.github.stargazers_count >= 0) { const githubKey = item.github.full_name.toLowerCase(); // Extract real project name from GitHub URL const realName = extractProjectNameFromGithub(item.github.full_name); // Check if we already have this repository if (githubMap.has(githubKey)) { const existing = githubMap.get(githubKey); // Keep the one with more complete information or higher stars if (item.github.stargazers_count > existing.github.stargazers_count || (item.github.stargazers_count === existing.github.stargazers_count && item.description && item.description.length > (existing.description || '').length)) { githubMap.set(githubKey, { ...item, displayName: realName }); } } else { githubMap.set(githubKey, { ...item, displayName: realName }); } } else { // For items without GitHub data, keep them as is but filter out obviously invalid names if (isValidProjectName(item.name)) { processedData.push({ ...item, displayName: item.name }); } } } // Add deduplicated GitHub projects processedData.push(...Array.from(githubMap.values())); return processedData; } // Extract project name from GitHub full_name function extractProjectNameFromGithub(fullName) { if (!fullName) return 'Unknown'; const parts = fullName.split('/'); return parts[parts.length - 1] || 'Unknown'; } // Check if project name is valid (filter out test names) function isValidProjectName(name) { if (!name || typeof name !== 'string') return false; const invalidPatterns = [ /^[0-9]+$/, // Pure numbers: 1, 11, 12, 11111 /^test$/i, // Just "test" /^[a-z]$/i, // Single letters /^.{1,2}$/, // Too short (1-2 characters) ]; return !invalidPatterns.some(pattern => pattern.test(name.trim())); } // Update dashboard statistics and charts function updateDashboard() { updateStatistics(); renderCharts(); renderTopProjects(); } // Update statistics function updateStatistics() { const clientsCount = clientsData.length; const serversCount = serversData.length; const categories = new Set([ ...clientsData.map(item => item.category).filter(Boolean), ...serversData.map(item => item.category).filter(Boolean) ]); const totalStars = allData .filter(item => item.github && item.github.stargazers_count) .reduce((sum, item) => sum + item.github.stargazers_count, 0); animateNumber('clients-count', clientsCount); animateNumber('servers-count', serversCount); animateNumber('categories-count', categories.size); animateNumber('stars-count', formatNumber(totalStars)); } // Animate numbers function animateNumber(elementId, target) { const element = document.getElementById(elementId); const start = 0; const duration = 1000; const startTime = performance.now(); function update(currentTime) { const elapsed = currentTime - startTime; const progress = Math.min(elapsed / duration, 1); const current = Math.floor(progress * ( typeof target === 'string' ? parseInt(target.replace(/[^\d]/g, '')) : target )); element.textContent = typeof target === 'string' ? formatNumber(current) : current; if (progress < 1) { requestAnimationFrame(update); } else { element.textContent = target; } } requestAnimationFrame(update); } // Format numbers function formatNumber(num) { if (num >= 1000000) { return (num / 1000000).toFixed(1) + 'M'; } else if (num >= 1000) { return (num / 1000).toFixed(1) + 'K'; } return num.toString(); } // Render charts function renderCharts() { renderCategoryChart(); renderLanguageChart(); } // Category distribution chart function renderCategoryChart() { const ctx = document.getElementById('categoryChart').getContext('2d'); const categoryCount = {}; allData.forEach(item => { if (item.category) { const category = formatCategoryName(item.category); categoryCount[category] = (categoryCount[category] || 0) + 1; } }); const sortedCategories = Object.entries(categoryCount) .sort((a, b) => b[1] - a[1]) .slice(0, 8); new Chart(ctx, { type: 'doughnut', data: { labels: sortedCategories.map(([category]) => category), datasets: [{ data: sortedCategories.map(([, count]) => count), backgroundColor: [ '#3b82f6', '#10b981', '#8b5cf6', '#f59e0b', '#ef4444', '#06b6d4', '#84cc16', '#f97316' ], borderWidth: 0, borderRadius: 4 }] }, options: { responsive: true, maintainAspectRatio: false, plugins: { legend: { position: 'bottom', labels: { padding: 20, usePointStyle: true, font: { family: 'Inter' } } } } } }); } // Language distribution chart function renderLanguageChart() { const ctx = document.getElementById('languageChart').getContext('2d'); const languageCount = {}; allData.forEach(item => { if (item.github && item.github.language) { const lang = item.github.language; languageCount[lang] = (languageCount[lang] || 0) + 1; } }); const sortedLanguages = Object.entries(languageCount) .sort((a, b) => b[1] - a[1]) .slice(0, 10); new Chart(ctx, { type: 'bar', data: { labels: sortedLanguages.map(([lang]) => lang), datasets: [{ label: 'Projects', data: sortedLanguages.map(([, count]) => count), backgroundColor: '#3b82f6', borderRadius: 6, borderSkipped: false }] }, options: { responsive: true, maintainAspectRatio: false, plugins: { legend: { display: false } }, scales: { y: { beginAtZero: true, grid: { color: '#f3f4f6' }, ticks: { font: { family: 'Inter' } } }, x: { grid: { display: false }, ticks: { font: { family: 'Inter' } } } } } }); } // Render top projects function renderTopProjects() { const container = document.getElementById('top-projects'); const topProjects = allData .filter(item => item.github && item.github.stargazers_count > 0) .sort((a, b) => b.github.stargazers_count - a.github.stargazers_count) .slice(0, 10); if (topProjects.length === 0) { container.innerHTML = `
No projects with GitHub data found
Try adjusting your search criteria
${escapeHtml(item.description)}