Javare commited on
Commit
8227733
·
verified ·
1 Parent(s): 5a5f41d

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +61 -0
index.html CHANGED
@@ -64,6 +64,67 @@
64
  }
65
  });
66
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
  </script>
68
  </head>
69
  <body>
 
64
  }
65
  });
66
  });
67
+ // Système de leaderboard global connecté à l'API globale
68
+ async function loadLeaderboard() {
69
+ try {
70
+ const response = await fetch('/api/scores');
71
+ const scores = await response.json();
72
+
73
+ const tbody = document.getElementById('leaderboardBody');
74
+ tbody.innerHTML = '';
75
+
76
+ if(!scores || scores.length === 0) {
77
+ tbody.innerHTML = '<tr><td colspan="5" style="text-align:center; color:#888;">Aucun score global pour le moment. Soyez le premier !</td></tr>';
78
+ return;
79
+ }
80
+
81
+ scores.forEach((item, index) => {
82
+ const row = document.createElement('tr');
83
+ const isTop3 = index < 3 ? `<span class="badge-top">🥇 ${index + 1}</span>` : index + 1;
84
+ row.innerHTML = `
85
+ <td>${isTop3}</td>
86
+ <td><strong>${item.config}</strong></td>
87
+ <td>${item.browser}</td>
88
+ <td>${item.power}</td>
89
+ <td style="color: #2b6cb0; font-weight: bold;">${item.score.toFixed(2)} tps</td>
90
+ `;
91
+ tbody.appendChild(row);
92
+ });
93
+ } catch (error) {
94
+ console.error("Erreur lors du chargement du classement global:", error);
95
+ }
96
+ }
97
+
98
+ async function saveScore(finalScore) {
99
+ if (finalScore <= 0) return;
100
+
101
+ const type = document.getElementById('deviceType').value;
102
+ const brand = document.getElementById('deviceBrand').value;
103
+ const model = document.getElementById('deviceModel').value || "Modèle inconnu";
104
+ const browser = document.getElementById('browserType').value;
105
+
106
+ const configString = `${type} - ${brand} (${model})`;
107
+
108
+ const payload = {
109
+ config: configString,
110
+ browser: browser,
111
+ power: selectedPower,
112
+ score: finalScore
113
+ };
114
+
115
+ try {
116
+ // Envoi du score à notre API Python sécurisée
117
+ await fetch('/api/score', {
118
+ method: 'POST',
119
+ headers: { 'Content-Type': 'application/json' },
120
+ body: JSON.stringify(payload)
121
+ });
122
+ // Rechargement du classement mis à jour pour tout le monde
123
+ loadLeaderboard();
124
+ } catch (error) {
125
+ console.error("Erreur lors de l'envoi du score au serveur:", error);
126
+ }
127
+ }
128
  </script>
129
  </head>
130
  <body>