diff --git a/public/js/leaderboard.js b/public/js/leaderboard.js
index 6846f5f..e6b37b6 100644
--- a/public/js/leaderboard.js
+++ b/public/js/leaderboard.js
@@ -54,7 +54,7 @@ function saveLocationSelection(locationId, locationName) {
name: cleanName,
timestamp: new Date().toISOString()
};
-
+
setCookie('ninjacross_last_location', JSON.stringify(locationData), 90);
lastSelectedLocation = { id: locationId, name: cleanName };
console.log('💾 Location saved to cookie:', cleanName);
@@ -84,21 +84,21 @@ function showNotification(timeData) {
const notificationBubble = document.getElementById('notificationBubble');
const notificationTitle = document.getElementById('notificationTitle');
const notificationSubtitle = document.getElementById('notificationSubtitle');
-
+
// Format the time data
const playerName = timeData.player_name || (currentLanguage === 'de' ? 'Unbekannter Spieler' : 'Unknown Player');
const locationName = timeData.location_name || (currentLanguage === 'de' ? 'Unbekannter Standort' : 'Unknown Location');
const timeString = timeData.recorded_time || '--:--';
-
+
// Update notification content
const newTimeText = currentLanguage === 'de' ? 'Neue Zeit von' : 'New time from';
notificationTitle.textContent = `🏁 ${newTimeText} ${playerName}!`;
notificationSubtitle.textContent = `${timeString} • ${locationName}`;
-
+
// Show notification
notificationBubble.classList.remove('hide');
notificationBubble.classList.add('show');
-
+
// Auto-hide after 5 seconds
setTimeout(() => {
hideNotification();
@@ -109,7 +109,7 @@ function hideNotification() {
const notificationBubble = document.getElementById('notificationBubble');
notificationBubble.classList.remove('show');
notificationBubble.classList.add('hide');
-
+
// Remove hide class after animation
setTimeout(() => {
notificationBubble.classList.remove('hide');
@@ -120,7 +120,7 @@ function hideNotification() {
async function checkAuth() {
try {
const { data: { session } } = await supabase.auth.getSession();
-
+
if (session) {
// User is logged in, show dashboard button
document.getElementById('adminLoginBtn').style.display = 'none';
@@ -163,18 +163,18 @@ async function loadLocations() {
if (!response.ok) {
throw new Error('Failed to fetch locations');
}
-
+
const responseData = await response.json();
const locations = responseData.data || responseData; // Handle both formats
const locationSelect = document.getElementById('locationSelect');
-
+
// Store locations globally for distance calculations
locationsData = locations;
-
+
// Clear existing options and set default placeholder
const placeholderText = currentLanguage === 'de' ? '📍 Bitte Standort auswählen' : '📍 Please select location';
locationSelect.innerHTML = ``;
-
+
// Add locations from database
locations.forEach(location => {
const option = document.createElement('option');
@@ -182,12 +182,12 @@ async function loadLocations() {
option.textContent = `📍 ${location.name}`;
locationSelect.appendChild(option);
});
-
+
// Load and set last selected location
const lastLocation = loadLastSelectedLocation();
if (lastLocation) {
// Find the option that matches the last location name
- const matchingOption = Array.from(locationSelect.options).find(option =>
+ const matchingOption = Array.from(locationSelect.options).find(option =>
option.textContent === `📍 ${lastLocation.name}` || option.value === lastLocation.name
);
if (matchingOption) {
@@ -199,7 +199,7 @@ async function loadLocations() {
loadData();
}
}
-
+
} catch (error) {
console.error('Error loading locations:', error);
}
@@ -210,14 +210,14 @@ function calculateDistance(lat1, lon1, lat2, lon2) {
const R = 6371; // Earth's radius in kilometers
const dLat = toRadians(lat2 - lat1);
const dLon = toRadians(lon2 - lon1);
-
+
const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
Math.cos(toRadians(lat1)) * Math.cos(toRadians(lat2)) *
Math.sin(dLon / 2) * Math.sin(dLon / 2);
-
+
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
const distance = R * c; // Distance in kilometers
-
+
return distance;
}
@@ -229,10 +229,10 @@ function toRadians(degrees) {
async function findNearestLocation() {
const btn = document.getElementById('findLocationBtn');
const locationSelect = document.getElementById('locationSelect');
-
+
// Check if geolocation is supported
if (!navigator.geolocation) {
- const errorMsg = currentLanguage === 'de' ?
+ const errorMsg = currentLanguage === 'de' ?
'Geolocation wird von diesem Browser nicht unterstützt.' :
'Geolocation is not supported by this browser.';
showLocationError(errorMsg);
@@ -265,9 +265,9 @@ async function findNearestLocation() {
const locationsWithDistance = locationsData.map(location => ({
...location,
distance: calculateDistance(
- userLat,
- userLon,
- parseFloat(location.latitude),
+ userLat,
+ userLon,
+ parseFloat(location.latitude),
parseFloat(location.longitude)
)
}));
@@ -279,7 +279,7 @@ async function findNearestLocation() {
// Select the nearest location in the dropdown
locationSelect.value = nearestLocation.name;
-
+
// Trigger change event to update the leaderboard
locationSelect.dispatchEvent(new Event('change'));
@@ -289,27 +289,27 @@ async function findNearestLocation() {
} catch (error) {
console.error('Error getting location:', error);
let errorMessage = currentLanguage === 'de' ? 'Standort konnte nicht ermittelt werden.' : 'Location could not be determined.';
-
+
if (error.code) {
- switch(error.code) {
+ switch (error.code) {
case error.PERMISSION_DENIED:
- errorMessage = currentLanguage === 'de' ?
+ errorMessage = currentLanguage === 'de' ?
'Standortzugriff wurde verweigert. Bitte erlaube den Standortzugriff in den Browser-Einstellungen.' :
'Location access was denied. Please allow location access in browser settings.';
break;
case error.POSITION_UNAVAILABLE:
- errorMessage = currentLanguage === 'de' ?
+ errorMessage = currentLanguage === 'de' ?
'Standortinformationen sind nicht verfügbar.' :
'Location information is not available.';
break;
case error.TIMEOUT:
- errorMessage = currentLanguage === 'de' ?
+ errorMessage = currentLanguage === 'de' ?
'Zeitüberschreitung beim Abrufen des Standorts.' :
'Timeout while retrieving location.';
break;
}
}
-
+
showLocationError(errorMessage);
} finally {
// Reset button state
@@ -324,17 +324,17 @@ function showLocationSuccess(locationName, distance) {
const notificationBubble = document.getElementById('notificationBubble');
const notificationTitle = document.getElementById('notificationTitle');
const notificationSubtitle = document.getElementById('notificationSubtitle');
-
+
// Update notification content
const locationFoundText = currentLanguage === 'de' ? 'Standort gefunden!' : 'Location found!';
const distanceText = currentLanguage === 'de' ? 'km entfernt' : 'km away';
notificationTitle.textContent = `📍 ${locationFoundText}`;
notificationSubtitle.textContent = `${locationName} (${distance.toFixed(1)} ${distanceText})`;
-
+
// Show notification
notificationBubble.classList.remove('hide');
notificationBubble.classList.add('show');
-
+
// Auto-hide after 4 seconds
setTimeout(() => {
hideNotification();
@@ -346,19 +346,19 @@ function showLocationError(message) {
const notificationBubble = document.getElementById('notificationBubble');
const notificationTitle = document.getElementById('notificationTitle');
const notificationSubtitle = document.getElementById('notificationSubtitle');
-
+
// Change notification style to error
notificationBubble.style.background = 'linear-gradient(135deg, #dc3545, #c82333)';
-
+
// Update notification content
const errorText = currentLanguage === 'de' ? 'Fehler' : 'Error';
notificationTitle.textContent = `❌ ${errorText}`;
notificationSubtitle.textContent = message;
-
+
// Show notification
notificationBubble.classList.remove('hide');
notificationBubble.classList.add('show');
-
+
// Auto-hide after 6 seconds
setTimeout(() => {
hideNotification();
@@ -371,10 +371,10 @@ function showLocationError(message) {
function showLocationSelectionPrompt() {
const rankingList = document.getElementById('rankingList');
const emptyTitle = currentLanguage === 'de' ? 'Standort auswählen' : 'Select Location';
- const emptyDescription = currentLanguage === 'de' ?
+ const emptyDescription = currentLanguage === 'de' ?
'Bitte wähle einen Standort aus dem Dropdown-Menü aus
oder nutze den "📍 Mein Standort" Button, um automatisch
den nächstgelegenen Standort zu finden.' :
'Please select a location from the dropdown menu
or use the "📍 My Location" button to automatically
find the nearest location.';
-
+
rankingList.innerHTML = `