(function() { 'use strict'; const token = localStorage.getItem('auth_token'); if (!token) { window.location.href = '/'; return; } function decodeJwt(token) { try { return JSON.parse(atob(token.split('.')[1])); } catch { return null; } } const decoded = decodeJwt(token); if (!decoded) { localStorage.removeItem('auth_token'); window.location.href = '/'; return; } // Check if admin and show admin tabs if (decoded.admin) { const adminTabWinners = document.getElementById('tab-winners'); if (adminTabWinners) adminTabWinners.classList.remove('d-none'); } // Logout const logOffBtn = document.getElementById('log-off'); if (logOffBtn) { logOffBtn.addEventListener('click', () => { localStorage.removeItem('auth_token'); window.location.href = '/'; }); } let categories = []; let myPicks = {}; let currentYear = null; let isSaving = false; // Prevent multiple simultaneous saves async function fetchActiveYear() { try { const res = await fetch('/api/settings/year'); if (!res.ok) throw new Error('Failed to fetch active year'); const data = await res.json(); return Number(data.year) || new Date().getFullYear(); } catch (err) { console.error('Error fetching active year:', err); return new Date().getFullYear(); } } function showAlert(message, type = 'info') { const container = document.getElementById('alert-container'); if (!container) return; container.innerHTML = `
| # | Catégorie | Choix | Nommés |
|---|---|---|---|
| ${cat.categoryNumber} | ${cat.categoryName} | ${selectedNominee ? ` ${selectedNominee} ` : 'Aucun choix'} |
${cat.nominees.map(nominee => {
const isSelected = selectedNominee === nominee.name;
return `
${isSelected ? '✓' : ''}
${nominee.name}
`;
}).join('')}
|
| # | Catégorie | Sélection | Gagnant |
|---|---|---|---|
| ${cat.categoryNumber} | ${cat.categoryName} | ${winner ? `${winner.name}` : '—'} |
| # | Utilisateur | Score | Total | Actions |
|---|---|---|---|---|
| ${rank}${medal ? ' ' + medal : ''} | ${score.userName} | ${actualScore} | ${totalCategories} |