75 lines
4.0 KiB
JavaScript
75 lines
4.0 KiB
JavaScript
// Fonction pour ajouter la vitesse aux pronostics
|
|
function addSpeedInfo() {
|
|
try {
|
|
// Charger les données de vitesse depuis notre API
|
|
fetch('/api/vitesse')
|
|
.then(response => response.json())
|
|
.then(speedData => {
|
|
// Attendre que le contenu soit chargé
|
|
setTimeout(() => {
|
|
// Ajouter la vitesse dans les sections bases/chances/outsiders
|
|
const sections = ['bases', 'chances', 'outsiders'];
|
|
|
|
sections.forEach(section => {
|
|
const sectionElement = document.querySelector(`.prono-section.${section}`);
|
|
if (sectionElement) {
|
|
const horses = sectionElement.querySelectorAll('.prono-horse');
|
|
horses.forEach(horseElement => {
|
|
const horseName = horseElement.querySelector('.prono-horse-name').textContent.trim();
|
|
|
|
// Trouver les données de vitesse pour ce cheval
|
|
const horseData = speedData.predictions?.[section]?.find(h => h.horse_name === horseName);
|
|
if (horseData && horseData.speed_info) {
|
|
const speedInfo = horseData.speed_info;
|
|
const speedText = speedInfo.avg_time_formatted !== 'N/A'
|
|
? `${speedInfo.avg_time_formatted} (${speedInfo.races} courses)`
|
|
: 'N/A';
|
|
|
|
// Ajouter l'info vitesse
|
|
const nameElement = horseElement.querySelector('.prono-horse-name');
|
|
nameElement.innerHTML = `${horseName} <span class="prono-horse-speed">⏱️ ${speedText}</span>`;
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
// Ajouter la colonne vitesse dans la table des partants
|
|
const oddsTable = document.querySelector('.odds-table');
|
|
if (oddsTable) {
|
|
// Ajouter l'en-tête
|
|
const headerRow = oddsTable.querySelector('thead tr');
|
|
if (headerRow && headerRow.children.length === 3) {
|
|
const th = document.createElement('th');
|
|
th.textContent = 'Vitesse';
|
|
headerRow.appendChild(th);
|
|
}
|
|
|
|
// Ajouter les données
|
|
const rows = oddsTable.querySelectorAll('tbody tr');
|
|
rows.forEach(row => {
|
|
const horseName = row.cells[1]?.textContent?.trim().split('⭐')[0]?.trim();
|
|
if (horseName) {
|
|
let speedInfo = null;
|
|
for (let section of ['bases', 'chances', 'outsiders']) {
|
|
speedInfo = speedData.predictions?.[section]?.find(h => h.horse_name === horseName)?.speed_info;
|
|
if (speedInfo) break;
|
|
}
|
|
const speedText = speedInfo ? speedInfo.avg_time_formatted : 'N/A';
|
|
|
|
const td = document.createElement('td');
|
|
td.className = 'speed-val';
|
|
td.textContent = speedText;
|
|
row.appendChild(td);
|
|
}
|
|
});
|
|
}
|
|
}, 2000); // Attendre 2 secondes que le contenu soit chargé
|
|
});
|
|
} catch (error) {
|
|
console.error('Erreur:', error);
|
|
}
|
|
}
|
|
|
|
// Lancer la fonction quand la page est chargée
|
|
document.addEventListener('DOMContentLoaded', addSpeedInfo);
|