From 94b3bac95ac9461dac29fdf15357877a44c9041b Mon Sep 17 00:00:00 2001 From: Dvorinka Date: Fri, 20 Jun 2025 10:25:39 +0200 Subject: [PATCH] fes --- achievements.js | 39 +++++++++++---- admin-dashboard.html | 111 +++++++++++++++++++++++++------------------ index.html | 50 +++++++++++-------- main.go | 103 ++++++++++++++++++++++++++++----------- 4 files changed, 199 insertions(+), 104 deletions(-) diff --git a/achievements.js b/achievements.js index d28daa9..3c30efb 100644 --- a/achievements.js +++ b/achievements.js @@ -96,19 +96,38 @@ async function checkAchievements() { try { const response = await fetch('/api/visitor-stats'); const stats = await response.json(); - - // Check for monthly achievements - Object.values(ACHIEVEMENTS).forEach(achievement => { - if (achievement.period === "monthly" && stats.monthly_visits >= achievement.threshold) { - unlockAchievement(achievement); - } - }); + const visitorId = getCookie('visitor_id'); // First visit achievement - if (stats.total_visits === 1) { - unlockAchievement(ACHIEVEMENTS.first_visit); + if (!localStorage.getItem('first_visit_' + visitorId)) { + unlockAchievement('first_visit'); + localStorage.setItem('first_visit_' + visitorId, 'true'); } - + + // Get visitor's stats + const visitor = stats.unique_visitors[visitorId]; + if (!visitor) return; + + // Monthly achievements + const monthlyVisits = stats.monthly_visits; + if (monthlyVisits >= ACHIEVEMENTS.frequent_visitor.threshold && + !localStorage.getItem('frequent_visitor_' + visitorId)) { + unlockAchievement('frequent_visitor'); + localStorage.setItem('frequent_visitor_' + visitorId, 'true'); + } + + if (monthlyVisits >= ACHIEVEMENTS.power_user.threshold && + !localStorage.getItem('power_user_' + visitorId)) { + unlockAchievement('power_user'); + localStorage.setItem('power_user_' + visitorId, 'true'); + } + + if (monthlyVisits >= ACHIEVEMENTS.super_fan.threshold && + !localStorage.getItem('super_fan_' + visitorId)) { + unlockAchievement('super_fan'); + localStorage.setItem('super_fan_' + visitorId, 'true'); + } + // Apply highest unlocked achievement theme const unlocked = Array.from(unlockedAchievements); if (unlocked.length > 0) { diff --git a/admin-dashboard.html b/admin-dashboard.html index d40e7f7..25c12e7 100644 --- a/admin-dashboard.html +++ b/admin-dashboard.html @@ -4367,36 +4367,48 @@ document.addEventListener('DOMContentLoaded', function() { // Browser stats const browserStats = document.getElementById('browserStats'); - browserStats.innerHTML = Object.entries(stats.browser_stats) - .sort((a, b) => b[1] - a[1]) - .map(([browser, count]) => ` -
- ${browser} - ${count} -
- `).join(''); + if (stats.browser_stats) { + browserStats.innerHTML = Object.entries(stats.browser_stats) + .sort((a, b) => b[1] - a[1]) + .map(([browser, count]) => ` +
+ ${browser} + ${count} +
+ `).join(''); + } else { + browserStats.innerHTML = '
Žádná data
'; + } // OS stats const osStats = document.getElementById('osStats'); - osStats.innerHTML = Object.entries(stats.os_stats) - .sort((a, b) => b[1] - a[1]) - .map(([os, count]) => ` -
- ${os} - ${count} -
- `).join(''); + if (stats.os_stats) { + osStats.innerHTML = Object.entries(stats.os_stats) + .sort((a, b) => b[1] - a[1]) + .map(([os, count]) => ` +
+ ${os} + ${count} +
+ `).join(''); + } else { + osStats.innerHTML = '
Žádná data
'; + } // Active hours const activeHours = document.getElementById('activeHours'); - activeHours.innerHTML = stats.most_active_hours - .sort((a, b) => b.count - a.count) - .map(hour => ` -
- ${hour.hour}:00 - ${hour.count} -
- `).join(''); + if (stats.most_active_hours && stats.most_active_hours.length > 0) { + activeHours.innerHTML = stats.most_active_hours + .sort((a, b) => b.count - a.count) + .map(hour => ` +
+ ${hour.hour}:00 + ${hour.count} +
+ `).join(''); + } else { + activeHours.innerHTML = '
Žádná data
'; + } // Active days const activeDays = document.getElementById('activeDays'); @@ -4410,31 +4422,40 @@ document.addEventListener('DOMContentLoaded', function() { 'Sunday': 'Neděle' }; - activeDays.innerHTML = stats.most_active_days - .sort((a, b) => b.count - a.count) - .map(day => ` -
- ${dayMap[day.day] || day.day} - ${day.count} -
- `).join(''); + if (stats.most_active_days && stats.most_active_days.length > 0) { + activeDays.innerHTML = stats.most_active_days + .sort((a, b) => b.count - a.count) + .filter(day => day.count > 0) // Filter out days with 0 visits + .map(day => ` +
+ ${dayMap[day.day] || day.day} + ${day.count} +
+ `).join(''); + } else { + activeDays.innerHTML = '
Žádná data
'; + } // Unique visitors const uniqueVisitors = document.getElementById('uniqueVisitors'); - uniqueVisitors.innerHTML = Object.entries(stats.unique_visitors) - .map(([id, visitor]) => ` -
-
-
${visitor.ip}
-
${visitor.user_agent}
+ if (stats.unique_visitors) { + uniqueVisitors.innerHTML = Object.entries(stats.unique_visitors) + .map(([id, visitor]) => ` +
+
+
${visitor.ip}
+
${visitor.user_agent}
+
+
+ ${visitor.visits} návštěv + | + ${visitor.last_visit.toLocaleString()} +
-
- ${visitor.visits} návštěv - | - ${visitor.last_visit.toLocaleString()} -
-
- `).join(''); + `).join(''); + } else { + uniqueVisitors.innerHTML = '
Žádná data
'; + } initializeCharts(); updateVisitorStats(stats); diff --git a/index.html b/index.html index 134c108..5b7bb93 100644 --- a/index.html +++ b/index.html @@ -618,33 +618,41 @@ }); -
-
- -
-

Nováček

-

První návštěva na portálu

+