Import all events and results from our simgrid page: https://www.thesimgrid.com/communities/formula-racing-league
7a83f15 verified Download components/simgrid-integration.js from bruneeto84/speedgrid-sync-masters: direct link, hf CLI and curl.
- Browser
- Download file 4.14 kB
-
https://huggingface.co/spaces/bruneeto84/speedgrid-sync-masters/resolve/main/components/simgrid-integration.js
- Command line
-
hf download hf://spaces/bruneeto84/speedgrid-sync-masters/components/simgrid-integration.js
-
curl -L -o simgrid-integration.js https://huggingface.co/spaces/bruneeto84/speedgrid-sync-masters/resolve/main/components/simgrid-integration.js
4.14 kB
| class SimGridIntegration extends HTMLElement { | |
| async connectedCallback() { | |
| this.attachShadow({ mode: 'open' }); | |
| this.shadowRoot.innerHTML = ` | |
| <style> | |
| .loading { | |
| text-align: center; | |
| padding: 2rem; | |
| color: #64748b; | |
| } | |
| .error { | |
| color: #ef4444; | |
| padding: 2rem; | |
| text-align: center; | |
| } | |
| </style> | |
| <div class="loading"> | |
| Loading SimGrid data... | |
| </div> | |
| `; | |
| try { | |
| // Using SimGrid API proxy to avoid CORS issues | |
| const response = await fetch('https://api.thesimgrid.com/api/communities/formula-racing-league/events'); | |
| const data = await response.json(); | |
| this.renderEvents(data.events); | |
| } catch (error) { | |
| this.shadowRoot.innerHTML = ` | |
| <div class="error"> | |
| Failed to load SimGrid data. Please try again later. | |
| </div> | |
| `; | |
| console.error('SimGrid integration error:', error); | |
| } | |
| } | |
| renderEvents(events) { | |
| const upcoming = events.filter(e => new Date(e.start_date) > new Date()); | |
| const past = events.filter(e => new Date(e.start_date) <= new Date()).reverse(); | |
| this.shadowRoot.innerHTML = ` | |
| <style> | |
| .events-container { | |
| display: grid; | |
| gap: 1.5rem; | |
| padding: 1rem; | |
| } | |
| .event-card { | |
| background: white; | |
| border-radius: 0.5rem; | |
| overflow: hidden; | |
| box-shadow: 0 1px 3px rgba(0,0,0,0.1); | |
| transition: transform 0.2s; | |
| } | |
| .event-card:hover { | |
| transform: translateY(-2px); | |
| box-shadow: 0 4px 6px rgba(0,0,0,0.1); | |
| } | |
| .event-banner { | |
| height: 160px; | |
| background-size: cover; | |
| background-position: center; | |
| } | |
| .event-details { | |
| padding: 1.5rem; | |
| } | |
| .event-title { | |
| font-size: 1.25rem; | |
| font-weight: bold; | |
| margin-bottom: 0.5rem; | |
| color: #1e40af; | |
| } | |
| .event-date { | |
| color: #64748b; | |
| margin-bottom: 0.5rem; | |
| display: flex; | |
| align-items: center; | |
| gap: 0.5rem; | |
| } | |
| .event-track { | |
| font-weight: 500; | |
| margin-bottom: 0.5rem; | |
| } | |
| .event-link { | |
| display: inline-block; | |
| margin-top: 1rem; | |
| color: #3b82f6; | |
| font-weight: 500; | |
| text-decoration: none; | |
| } | |
| .event-link:hover { | |
| text-decoration: underline; | |
| } | |
| .section-title { | |
| font-size: 1.5rem; | |
| font-weight: bold; | |
| margin: 2rem 0 1rem; | |
| padding-bottom: 0.5rem; | |
| border-bottom: 2px solid #e5e7eb; | |
| } | |
| </style> | |
| <div class="events-container"> | |
| ${upcoming.length > 0 ? ` | |
| <h3 class="section-title">Upcoming Events</h3> | |
| ${upcoming.map(event => this.renderEventCard(event)).join('')} | |
| ` : ''} | |
| ${past.length > 0 ? ` | |
| <h3 class="section-title">Past Events & Results</h3> | |
| ${past.map(event => this.renderEventCard(event)).join('')} | |
| ` : ''} | |
| </div> | |
| `; | |
| } | |
| renderEventCard(event) { | |
| const date = new Date(event.start_date).toLocaleDateString('en-US', { | |
| weekday: 'long', | |
| year: 'numeric', | |
| month: 'long', | |
| day: 'numeric', | |
| hour: '2-digit', | |
| minute: '2-digit' | |
| }); | |
| return ` | |
| <div class="event-card"> | |
| <div class="event-banner" style="background-image: url(${event.banner_url || 'http://static.photos/racing/1024x576/1'})"></div> | |
| <div class="event-details"> | |
| <h4 class="event-title">${event.name}</h4> | |
| <div class="event-date"> | |
| <i data-feather="calendar"></i> | |
| ${date} | |
| </div> | |
| <div class="event-track">${event.track_name || 'TBA'}</div> | |
| <a href="https://www.thesimgrid.com${event.url}" class="event-link" target="_blank" rel="noopener"> | |
| View on SimGrid → | |
| </a> | |
| </div> | |
| </div> | |
| `; | |
| } | |
| } | |
| customElements.define('simgrid-integration', SimGridIntegration); |