Live Cricket Scores

ЁЯПП Live Cricket Scores

Loading matches...
``` ### Updated CSS (styles.css) ```css :root { --primary-color: #1a1a1a; --secondary-color: #00b894; --text-color: #ffffff; --card-bg: rgba(255, 255, 255, 0.05); } * { margin: 0; padding: 0; box-sizing: border-box; } body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background-color: var(--primary-color); color: var(--text-color); line-height: 1.6; } .container { max-width: 1200px; margin: 0 auto; padding: 20px; } .title { text-align: center; margin: 2rem 0; color: var(--secondary-color); font-size: 2.5em; } .filters { display: flex; gap: 10px; margin: 20px 0; justify-content: center; } .filter-btn { padding: 8px 20px; border: none; border-radius: 20px; background: var(--card-bg); color: var(--text-color); cursor: pointer; transition: all 0.3s ease; } .filter-btn.active { background: var(--secondary-color); color: var(--primary-color); } .match-card { background: var(--card-bg); border-radius: 10px; padding: 20px; margin: 15px 0; backdrop-filter: blur(5px); transition: transform 0.3s ease; border-left: 4px solid var(--secondary-color); } .match-card:hover { transform: translateY(-3px); } .match-header { display: flex; justify-content: space-between; margin-bottom: 15px; font-size: 0.9em; opacity: 0.8; } .teams { display: flex; justify-content: space-between; align-items: center; margin: 20px 0; } .team { display: flex; align-items: center; gap: 15px; width: 40%; } .team-logo { width: 40px; height: 40px; object-fit: contain; } .vs { font-weight: bold; color: var(--secondary-color); } .score { font-size: 1.1em; margin: 10px 0; color: var(--secondary-color); } .status { padding: 8px 15px; border-radius: 20px; font-size: 0.9em; display: inline-block; } .status.fixture { background: rgba(0, 184, 148, 0.2); color: var(--secondary-color); } .status.result { background: rgba(231, 76, 60, 0.2); color: #e74c3c; } .status.live { background: rgba(46, 204, 113, 0.2); color: #2ecc71; animation: pulse 1.5s infinite; } @keyframes pulse { 0% { opacity: 1; } 50% { opacity: 0.5; } 100% { opacity: 1; } } .loader { text-align: center; padding: 30px; font-size: 1.2em; color: rgba(255, 255, 255, 0.5); } @media (max-width: 768px) { .container { padding: 10px; } .team { flex-direction: column; text-align: center; width: 30%; } .team-logo { margin: 0 auto; } } ``` ### Updated JavaScript (script.js) ```javascript const API_URL = 'https://api.cricapi.com/v1/cricScore?apikey=00bac71d-0494-41d7-a39c-428a4316ddca'; const matchesContainer = document.getElementById('matches'); const filterButtons = document.querySelectorAll('.filter-btn'); let allMatches = []; // Filter matches based on status function filterMatches(filter) { matchesContainer.innerHTML = ''; const filteredMatches = allMatches.filter(match => { if (filter === 'all') return true; if (filter === 'live') return match.ms === 'live'; if (filter === 'upcoming') return match.ms === 'fixture'; if (filter === 'result') return match.ms === 'result'; return true; }); if (filteredMatches.length === 0) { matchesContainer.innerHTML = '
No matches found in this category
'; return; } filteredMatches.forEach(createMatchCard); } // Create match card element function createMatchCard(match) { const matchCard = document.createElement('div'); matchCard.className = 'match-card'; const statusClass = match.ms === 'result' ? 'result' : match.ms === 'fixture' ? 'fixture' : match.ms === 'live' ? 'live' : ''; matchCard.innerHTML = `
${match.series} ${match.matchType.toUpperCase()}
${match.t1}
${match.t1s || 'Yet to bat'}
VS
${match.t2}
${match.t2s || 'Yet to bat'}
${match.status}
`; matchesContainer.appendChild(matchCard); } // Fetch data from API async function fetchLiveScores() { try { const response = await fetch(API_URL); const data = await response.json(); if (data.status !== 'success') { throw new Error('Failed to fetch data'); } allMatches = data.data; filterMatches('all'); } catch (error) { matchesContainer.innerHTML = '
Error fetching data. Please try again later.
'; console.error('Error:', error); } } // Filter button click handler filterButtons.forEach(button => { button.addEventListener('click', () => { filterButtons.forEach(btn => btn.classList.remove('active')); button.classList.add('active'); filterMatches(button.dataset.filter); }); }); // Initial load fetchLiveScores(); // Auto-refresh every 15 seconds setInterval(fetchLiveScores, 15000); ```

No comments:

Post a Comment

Live Cricket Scores ЁЯПП Live Cricket Scores All Live U...