forked from HapoTV/HapoPay
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnew_functions.js
More file actions
98 lines (84 loc) · 3.39 KB
/
new_functions.js
File metadata and controls
98 lines (84 loc) · 3.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Game Activities
window.addToRecentActivity = function(activity) {
try {
// Get existing activities from localStorage or initialize empty array
const activities = JSON.parse(localStorage.getItem('gameActivities') || '[]');
// Add timestamp if not provided
if (!activity.timestamp) {
activity.timestamp = new Date().toISOString();
}
// Add the new activity to the beginning of the array
activities.unshift(activity);
// Keep only the last 10 activities
const recentActivities = activities.slice(0, 10);
// Save back to localStorage
localStorage.setItem('gameActivities', JSON.stringify(recentActivities));
// Update the UI
updateRecentGameActivities();
} catch (error) {
console.error('Error adding to recent activity:', error);
}
};
// Function to update the recent game activities UI
function updateRecentGameActivities() {
try {
const gameActivityList = document.getElementById('gameActivityList');
if (!gameActivityList) return;
// Get activities from localStorage
const activities = JSON.parse(localStorage.getItem('gameActivities') || '[]');
if (activities.length === 0) {
// Show empty state if no activities
gameActivityList.innerHTML = `
<div class="empty-activity">
<div class="empty-icon">
<i class="fas fa-gamepad"></i>
</div>
<p class="empty-text">No games played yet</p>
<p class="empty-subtext">Start playing games to see your activity here</p>
</div>
`;
return;
}
// Create HTML for each activity
const activitiesHtml = activities.map(activity => {
const gameName = getGameDisplayName(activity.game) || 'Game';
const points = activity.points || 0;
const difficulty = activity.difficulty ? ` ${activity.difficulty.charAt(0).toUpperCase() + activity.difficulty.slice(1)}` : '';
const date = new Date(activity.timestamp);
const timeAgo = formatTimeAgo(date);
return `
<div class="activity-item">
<div class="activity-icon">
<i class="fas fa-${getGameIcon(activity.game)}"></i>
</div>
<div class="activity-details">
<div class="activity-header">
<span class="activity-title">${gameName} ${difficulty}</span>
<span class="activity-points">+${points} pts</span>
</div>
<div class="activity-meta">
<span class="activity-time">${timeAgo}</span>
</div>
</div>
</div>
`;
}).join('');
// Update the UI
gameActivityList.innerHTML = `
<div class="activity-list">
${activitiesHtml}
</div>
`;
} catch (error) {
console.error('Error updating recent game activities:', error);
}
}
// Helper function to get game icon
function getGameIcon(gameType) {
const icons = {
memory: 'brain',
math: 'calculator',
fun: 'gamepad'
};
return icons[gameType] || 'gamepad';
}