forked from Dev-tanay/Rubik-Cube
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogress.js
46 lines (40 loc) · 1.74 KB
/
progress.js
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
document.addEventListener('DOMContentLoaded', function() {
// Example function to fetch data
fetchProgressData();
function fetchProgressData() {
// This function should fetch data from your server or local storage
// Here we simulate data fetching with a static example
const progressData = {
totalSolves: 100,
bestTime: '1:23',
averageTime: '1:45',
cubeTypes: '3x3, 4x4',
recentSolves: [
{ time: '1:30', cubeType: '3x3' },
{ time: '2:15', cubeType: '4x4' }
]
};
displayProgressData(progressData);
}
// Store data in localStorage if it doesn't already exist
if (!localStorage.getItem('progressData')) {
localStorage.setItem('progressData', JSON.stringify(initialData));
}
// Retrieve data from localStorage
const progressData = JSON.parse(localStorage.getItem('progressData'));
function displayProgressData(data) {
document.getElementById('total-solves').textContent = data.totalSolves;
document.getElementById('best-time').textContent = data.bestTime;
document.getElementById('average-time').textContent = data.averageTime;
document.getElementById('cube-types').textContent = data.cubeTypes;
const recentSolvesList = document.getElementById('recent-solves');
recentSolvesList.innerHTML = ''; // Clear previous entries
data.recentSolves.forEach(solve => {
const listItem = document.createElement('li');
listItem.textContent = `${solve.time} - ${solve.cubeType}`;
recentSolvesList.appendChild(listItem);
});
}
// Fetch and display data on page load
fetchProgressData();
});