-
Notifications
You must be signed in to change notification settings - Fork 0
/
playlist_stats_viewer.html
189 lines (174 loc) · 5.81 KB
/
playlist_stats_viewer.html
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Masonry Layout with File Upload</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
align-items: center;
height: 100vh;
background: #333;
color: #fff;
}
.upload-container {
margin: 20px;
}
.upload-container input[type="file"] {
padding: 10px;
font-size: 16px;
color: #333;
}
.grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
gap: 10px;
width: 90%;
max-width: 1200px;
margin: 0 auto;
}
.grid-item {
background: #444;
border: 1px solid #555;
border-radius: 5px;
overflow: hidden;
position: relative;
padding: 10px;
box-sizing: border-box;
display: flex;
flex-direction: column;
align-items: center;
}
.grid-item img {
width: 100%;
height: auto;
}
.grid-item .stats {
margin-top: 10px;
font-size: 14px;
color: #eee;
text-align: center;
}
.grid-item .stats .views,
.grid-item .stats .watch-time {
margin-bottom: 5px;
display: flex;
align-items: center;
justify-content: center;
}
.grid-item .stats .icon {
margin-right: 5px;
}
.grid-item .number-icon {
position: absolute;
top: 10px;
right: 10px;
font-size: 18px;
font-weight: bold;
background-color: rgba(0, 0, 0, 0.7);
color: #fff;
padding: 5px 10px;
border-radius: 3px;
display: flex;
align-items: center;
}
.grid-item .podium-icon {
font-size: 24px;
margin-left: 5px;
}
.grid-item.gold .podium-icon {
color: gold;
}
.grid-item.silver .podium-icon {
color: silver;
}
.grid-item.bronze .podium-icon {
color: #cd7f32;
}
</style>
</head>
<body>
<div class="upload-container">
<input type="file" id="fileInput" accept=".json">
</div>
<div class="grid">
<!-- Grid items will be added here dynamically -->
</div>
<script>
document.getElementById('fileInput').addEventListener('change', handleFileSelect, false);
function handleFileSelect(event) {
const file = event.target.files[0];
if (file && file.type === 'application/json') {
const reader = new FileReader();
reader.onload = function(e) {
try {
const data = JSON.parse(e.target.result);
renderMasonryLayout(data);
} catch (err) {
console.error('Error parsing JSON:', err);
}
};
reader.readAsText(file);
} else {
alert('Please upload a valid JSON file.');
}
}
function renderMasonryLayout(data) {
const grid = document.querySelector('.grid');
grid.innerHTML = ''; // Clear existing content
data.forEach((item, index) => {
// Create grid item
const gridItem = document.createElement('div');
gridItem.classList.add('grid-item');
// Apply podium effect for top 3
let podiumIconHTML = '';
if (index === 0) {
gridItem.classList.add('gold');
podiumIconHTML = '<i class="fas fa-medal podium-icon"></i>';
} else if (index === 1) {
gridItem.classList.add('silver');
podiumIconHTML = '<i class="fas fa-medal podium-icon"></i>';
} else if (index === 2) {
gridItem.classList.add('bronze');
podiumIconHTML = '<i class="fas fa-medal podium-icon"></i>';
}
// Create image element
const img = document.createElement('img');
img.src = item.imagePath;
img.alt = item.title;
// Create stats element
const stats = document.createElement('div');
stats.classList.add('stats');
stats.innerHTML = `
<div class="views"><i class="fas fa-eye icon"></i> ${formatNumber(item.views)}</div>
<div class="watch-time"><i class="fas fa-clock icon"></i> ${formatWatchTime(item.watchTimeInMinutes)}</div>
`;
// Create number icon element with podium icon for top 3
const numberIcon = document.createElement('div');
numberIcon.classList.add('number-icon');
numberIcon.innerHTML = `${index + 1} ${podiumIconHTML}`;
// Append number icon, image, and stats to grid item
gridItem.appendChild(numberIcon);
gridItem.appendChild(img);
gridItem.appendChild(stats);
// Append grid item to grid
grid.appendChild(gridItem);
});
}
function formatNumber(num) {
return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ' '); // Add space for thousands
}
function formatWatchTime(minutes) {
const hoursPart = Math.floor(minutes / 60);
const minutesPart = minutes % 60;
return `${hoursPart}h ${minutesPart}m`;
}
</script>
</body>
</html>