Spaces:
Running
Running
Download script.js from zepor/gridiron-nexus-command: direct link, hf CLI and curl.
- Browser
- Download file 13.3 kB
-
https://huggingface.co/spaces/zepor/gridiron-nexus-command/resolve/main/script.js
- Command line
-
hf download hf://spaces/zepor/gridiron-nexus-command/script.js
-
curl -L -o script.js https://huggingface.co/spaces/zepor/gridiron-nexus-command/resolve/main/script.js
13.3 kB
| // Gridiron Nexus Command - Main JavaScript | |
| document.addEventListener('DOMContentLoaded', function() { | |
| // Initialize Feather Icons | |
| if (typeof feather !== 'undefined') { | |
| feather.replace(); | |
| } | |
| // Dashboard Role Selection | |
| const roleCards = document.querySelectorAll('.dashboard-role-card'); | |
| roleCards.forEach(card => { | |
| card.addEventListener('click', function() { | |
| // Remove active class from all cards | |
| roleCards.forEach(c => c.classList.remove('active')); | |
| // Add active class to clicked card | |
| this.classList.add('active'); | |
| const role = this.dataset.role; | |
| simulateDashboardChange(role); | |
| // Show notification | |
| showNotification(`Switched to ${role.charAt(0).toUpperCase() + role.slice(1)} Dashboard`); | |
| }); | |
| }); | |
| // Map Layer Toggles | |
| const mapToggles = document.querySelectorAll('.map-toggle'); | |
| mapToggles.forEach(toggle => { | |
| toggle.addEventListener('click', function() { | |
| const layer = this.dataset.layer; | |
| // Update active state | |
| mapToggles.forEach(t => t.classList.remove('bg-primary-700', 'text-white')); | |
| this.classList.add('bg-primary-700', 'text-white'); | |
| // Simulate layer change | |
| simulateMapLayerChange(layer); | |
| }); | |
| }); | |
| // Live Data Simulation | |
| let liveDataInterval; | |
| function startLiveDataSimulation() { | |
| if (liveDataInterval) clearInterval(liveDataInterval); | |
| liveDataInterval = setInterval(() => { | |
| // Update live metrics | |
| updateLiveMetrics(); | |
| // Animate data points | |
| animateDataBreath(); | |
| }, 3000); // Update every 3 seconds | |
| } | |
| function updateLiveMetrics() { | |
| const metrics = document.querySelectorAll('.ai-insight-card p span'); | |
| metrics.forEach(metric => { | |
| if (metric.textContent.includes('%')) { | |
| const currentValue = parseInt(metric.textContent); | |
| const change = Math.random() * 5 - 2.5; // Random change between -2.5 and +2.5 | |
| const newValue = Math.max(0, Math.min(100, Math.round(currentValue + change))); | |
| metric.textContent = `${newValue}%`; | |
| // Add visual feedback | |
| metric.style.color = newValue > currentValue ? '#10b981' : '#ef4444'; | |
| setTimeout(() => { | |
| metric.style.color = ''; | |
| }, 1000); | |
| } | |
| }); | |
| } | |
| function animateDataBreath() { | |
| const breathElements = document.querySelectorAll('.animate-breath'); | |
| breathElements.forEach(el => { | |
| el.style.animation = 'none'; | |
| setTimeout(() => { | |
| el.style.animation = 'breath 6s ease-in-out infinite'; | |
| }, 10); | |
| }); | |
| } | |
| // Simulate Dashboard Change | |
| function simulateDashboardChange(role) { | |
| const insights = document.querySelectorAll('.ai-insight-card'); | |
| const roleInsights = { | |
| coach: ['Game Management', 'Clock Control', 'Timeout Optimization'], | |
| analyst: ['Predictive Models', 'Trend Analysis', 'Statistical Significance'], | |
| scout: ['Player Evaluation', 'Opponent Weaknesses', 'Talent Projection'], | |
| player: ['Performance Review', 'Matchup Analysis', 'Development Goals'] | |
| }; | |
| insights.forEach((insight, index) => { | |
| const title = insight.querySelector('h4'); | |
| const content = insight.querySelector('p'); | |
| if (title && content) { | |
| title.textContent = `${roleInsights[role][index] || 'AI Insight'}`; | |
| content.textContent = getRandomInsightForRole(role); | |
| // Add animation | |
| insight.style.animation = 'slideInRight 0.5s ease-out'; | |
| setTimeout(() => { | |
| insight.style.animation = ''; | |
| }, 500); | |
| } | |
| }); | |
| } | |
| function getRandomInsightForRole(role) { | |
| const insights = { | |
| coach: [ | |
| 'Zone coverage showing 15% vulnerability on deep left side.', | |
| 'Red zone efficiency up 8% when using 2-TE sets.', | |
| 'Third down conversion rate optimal from 11 personnel.' | |
| ], | |
| analyst: [ | |
| 'EPA model predicts +0.12 advantage with RPO calls.', | |
| 'Correlation detected between defensive alignment and run success.', | |
| 'Machine learning identifies new passing lane vulnerability.' | |
| ], | |
| scout: [ | |
| 'WR prospect shows 95th percentile separation on go routes.', | |
| 'DT anchor strength metrics exceed NFL average by 12%.', | |
| 'RB vision score improved 22% over last season.' | |
| ], | |
| player: [ | |
| 'Your release time improved 0.08s from last game.', | |
| 'Route efficiency at 92% on crossing patterns.', | |
| 'Top speed reached 21.3 mph, career high.' | |
| ] | |
| }; | |
| const roleInsights = insights[role] || insights.coach; | |
| return roleInsights[Math.floor(Math.random() * roleInsights.length)]; | |
| } | |
| // Simulate Map Layer Change | |
| function simulateMapLayerChange(layer) { | |
| const map = document.querySelector('.map-visualization'); | |
| if (!map) return; | |
| // Remove existing layer classes | |
| map.classList.remove('heatmap-active', 'tracking-active', 'zones-active'); | |
| // Add new layer class | |
| map.classList.add(`${layer}-active`); | |
| // Update visual elements based on layer | |
| const aiCircle = map.querySelector('.ai-circle'); | |
| if (aiCircle) { | |
| switch(layer) { | |
| case 'heatmap': | |
| aiCircle.style.borderColor = '#ef4444'; | |
| aiCircle.querySelector('span').textContent = 'HOT'; | |
| break; | |
| case 'tracking': | |
| aiCircle.style.borderColor = '#06b6d4'; | |
| aiCircle.querySelector('span').textContent = 'TRK'; | |
| break; | |
| case 'zones': | |
| aiCircle.style.borderColor = '#10b981'; | |
| aiCircle.querySelector('span').textContent = 'ZONE'; | |
| break; | |
| } | |
| } | |
| } | |
| // Show Notification | |
| function showNotification(message, type = 'info') { | |
| const notification = document.createElement('div'); | |
| notification.className = `fixed top-4 right-4 px-6 py-3 rounded-lg shadow-lg z-50 transform translate-x-full transition-transform duration-300 ${ | |
| type === 'success' ? 'bg-green-900/90 border-l-4 border-green-500' : | |
| type === 'error' ? 'bg-red-900/90 border-l-4 border-red-500' : | |
| 'bg-surface border-l-4 border-primary-500' | |
| }`; | |
| notification.innerHTML = ` | |
| <div class="flex items-center"> | |
| <i data-feather="${type === 'success' ? 'check-circle' : type === 'error' ? 'alert-circle' : 'info'}" class="mr-3"></i> | |
| <span>${message}</span> | |
| </div> | |
| `; | |
| document.body.appendChild(notification); | |
| // Animate in | |
| setTimeout(() => { | |
| notification.style.transform = 'translateX(0)'; | |
| }, 10); | |
| // Animate out and remove | |
| setTimeout(() => { | |
| notification.style.transform = 'translateX(100%)'; | |
| setTimeout(() => { | |
| document.body.removeChild(notification); | |
| }, 300); | |
| }, 3000); | |
| // Replace feather icon | |
| if (typeof feather !== 'undefined') { | |
| feather.replace(); | |
| } | |
| } | |
| // Initialize Tooltips | |
| function initializeTooltips() { | |
| const tooltipElements = document.querySelectorAll('[data-tooltip]'); | |
| tooltipElements.forEach(el => { | |
| el.addEventListener('mouseenter', showTooltip); | |
| el.addEventListener('mouseleave', hideTooltip); | |
| }); | |
| } | |
| function showTooltip(e) { | |
| const tooltipText = this.dataset.tooltip; | |
| if (!tooltipText) return; | |
| const tooltip = document.createElement('div'); | |
| tooltip.className = 'fixed z-50 px-3 py-2 text-sm bg-gray-900 text-gray-100 rounded-lg shadow-lg border border-gray-700'; | |
| tooltip.textContent = tooltipText; | |
| document.body.appendChild(tooltip); | |
| const rect = this.getBoundingClientRect(); | |
| tooltip.style.left = `${rect.left + rect.width / 2 - tooltip.offsetWidth / 2}px`; | |
| tooltip.style.top = `${rect.top - tooltip.offsetHeight - 10}px`; | |
| this._tooltip = tooltip; | |
| } | |
| function hideTooltip(e) { | |
| if (this._tooltip) { | |
| document.body.removeChild(this._tooltip); | |
| this._tooltip = null; | |
| } | |
| } | |
| // Sports API Integration Example | |
| async function fetchSportsData() { | |
| try { | |
| // Example using a public sports API (using NFL schedule as example) | |
| const response = await fetch('https://site.api.espn.com/apis/site/v2/sports/football/nfl/scoreboard'); | |
| const data = await response.json(); | |
| // You would process the data here | |
| console.log('Sports data loaded:', data); | |
| // Update UI with live data if needed | |
| if (data.events && data.events.length > 0) { | |
| updateLiveScores(data.events); | |
| } | |
| } catch (error) { | |
| console.warn('Could not fetch live sports data:', error); | |
| // Fallback to simulated data | |
| simulateLiveScores(); | |
| } | |
| } | |
| function updateLiveScores(events) { | |
| // Update a scores widget if it exists | |
| const scoresWidget = document.getElementById('live-scores'); | |
| if (scoresWidget && events.length > 0) { | |
| const firstGame = events[0]; | |
| const homeTeam = firstGame.competitions[0].competitors.find(c => c.homeAway === 'home'); | |
| const awayTeam = firstGame.competitions[0].competitors.find(c => c.homeAway === 'away'); | |
| scoresWidget.innerHTML = ` | |
| <div class="text-xs text-gray-400 mb-1">LIVE</div> | |
| <div class="flex items-center justify-between"> | |
| <div class="flex items-center"> | |
| <span class="font-bold">${awayTeam.team.abbreviation}</span> | |
| <span class="ml-2">${awayTeam.score}</span> | |
| </div> | |
| <div class="text-gray-500">@</div> | |
| <div class="flex items-center"> | |
| <span class="font-bold">${homeTeam.team.abbreviation}</span> | |
| <span class="ml-2">${homeTeam.score}</span> | |
| </div> | |
| </div> | |
| `; | |
| } | |
| } | |
| function simulateLiveScores() { | |
| // Simulated live scores for demo | |
| const scores = [ | |
| { away: 'KC', awayScore: 24, home: 'BUF', homeScore: 27, quarter: '4th', time: '2:15' }, | |
| { away: 'SF', awayScore: 31, home: 'PHI', homeScore: 28, quarter: 'FINAL', time: '' }, | |
| { away: 'DAL', awayScore: 17, home: 'GB', homeScore: 20, quarter: '3rd', time: '8:42' } | |
| ]; | |
| // Update a scores widget if it exists | |
| const scoresWidget = document.getElementById('live-scores'); | |
| if (scoresWidget) { | |
| const randomGame = scores[Math.floor(Math.random() * scores.length)]; | |
| scoresWidget.innerHTML = ` | |
| <div class="text-xs text-gray-400 mb-1">${randomGame.quarter} ${randomGame.time}</div> | |
| <div class="flex items-center justify-between"> | |
| <div class="flex items-center"> | |
| <span class="font-bold">${randomGame.away}</span> | |
| <span class="ml-2">${randomGame.awayScore}</span> | |
| </div> | |
| <div class="text-gray-500">@</div> | |
| <div class="flex items-center"> | |
| <span class="font-bold">${randomGame.home}</span> | |
| <span class="ml-2">${randomGame.homeScore}</span> | |
| </div> | |
| </div> | |
| `; | |
| } | |
| } | |
| // Initialize everything | |
| function init() { | |
| startLiveDataSimulation(); | |
| initializeTooltips(); | |
| // Fetch live sports data (commented out for demo - uncomment with real API) | |
| // fetchSportsData(); | |
| // Simulate live scores for demo | |
| simulateLiveScores(); | |
| // Set first role card as active | |
| if (roleCards.length > 0) { | |
| roleCards[0].classList.add('active'); | |
| } | |
| // Set first map toggle as active | |
| if (mapToggles.length > 0) { | |
| mapToggles[0].classList.add('bg-primary-700', 'text-white'); | |
| } | |
| console.log('Gridiron Nexus Command initialized'); | |
| } | |
| // Start initialization | |
| init(); | |
| }); |