-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
315 lines (260 loc) · 9.79 KB
/
Copy pathscript.js
File metadata and controls
315 lines (260 loc) · 9.79 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
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
// DOM Elements
const gamesContainer = document.getElementById('gamesContainer');
const searchBar = document.querySelector('.search-bar');
// State
let checkedGames = {};
let filteredTopics = [];
let gamesData = { topics: [] };
let collapsedSections = {};
// Initialize the application
async function init() {
await loadGamesData();
loadCheckedGames();
// Initialize all sections as collapsed
gamesData.topics.forEach(topic => {
collapsedSections[topic.id] = true;
});
renderGames();
setupEventListeners();
}
// Load games data from external JSON file
async function loadGamesData() {
try {
const response = await fetch('dailys.json');
if (!response.ok) {
throw new Error('Failed to load dailys data');
}
gamesData = await response.json();
} catch (error) {
console.error('Error loading dailys data:', error);
gamesContainer.innerHTML = `
<div class="empty-state">
<i class="fas fa-exclamation-triangle"></i>
<h3>Failed to load dailys</h3>
<p>Please check if dailys.json exists and is valid</p>
</div>
`;
}
}
// Load checked games from localStorage
function loadCheckedGames() {
const today = new Date().toDateString();
const storedData = localStorage.getItem('dailysChecked');
if (storedData) {
const parsedData = JSON.parse(storedData);
// Check if the stored data is from today
if (parsedData.date === today) {
checkedGames = parsedData.games;
} else {
// Reset if it's a new day
checkedGames = {};
saveCheckedGames();
}
}
}
// Save checked games to localStorage
function saveCheckedGames() {
const today = new Date().toDateString();
const dataToStore = {
date: today,
games: checkedGames
};
localStorage.setItem('dailysChecked', JSON.stringify(dataToStore));
}
// Toggle game completion status
function toggleGameCheck(gameId) {
if (checkedGames[gameId]) {
delete checkedGames[gameId];
} else {
checkedGames[gameId] = true;
}
saveCheckedGames();
// Update only the affected section, not all sections
updateSectionCompletion(gameId);
}
// Update section completion status without re-rendering everything
function updateSectionCompletion(gameId) {
// Find which topic this game belongs to
let targetTopic = null;
let targetTopicId = null;
const topicsToCheck = filteredTopics.length > 0 ? filteredTopics : gamesData.topics;
for (const topic of topicsToCheck) {
for (const game of topic.games) {
if (game.id === gameId) {
targetTopic = topic;
targetTopicId = topic.id;
break;
}
}
if (targetTopic) break;
}
if (!targetTopic) return;
// Update the section checkmark
const isTopicComplete = isTopicCompleted(targetTopic);
const sectionTitle = document.querySelector(`[data-topic-id="${targetTopicId}"] .section-title h2`);
if (sectionTitle) {
const checkmark = sectionTitle.querySelector('.section-checkmark');
if (checkmark) {
if (isTopicComplete) {
checkmark.classList.add('checked');
} else {
checkmark.classList.remove('checked');
}
}
}
// Update the game card
const gameCard = document.querySelector(`[data-game-id="${gameId}"]`);
if (gameCard) {
if (checkedGames[gameId]) {
gameCard.classList.add('checked');
gameCard.querySelector('.game-title').style.textDecoration = 'line-through';
gameCard.querySelector('.game-title').style.color = 'var(--text-secondary)';
} else {
gameCard.classList.remove('checked');
gameCard.querySelector('.game-title').style.textDecoration = 'none';
gameCard.querySelector('.game-title').style.color = '';
}
}
}
// Check if all games in a topic are completed
function isTopicCompleted(topic) {
return topic.games.every(game => checkedGames[game.id]);
}
// Render all games
function renderGames() {
// Clear container
gamesContainer.innerHTML = '';
// Use filtered topics if search is active, otherwise use all topics
const topicsToRender = filteredTopics.length > 0 ? filteredTopics : gamesData.topics;
if (topicsToRender.length === 0) {
gamesContainer.innerHTML = `
<div class="empty-state">
<i class="fas fa-search"></i>
<h3>No dailys found</h3>
<p>Try adjusting your search terms</p>
</div>
`;
return;
}
// Render each topic section
topicsToRender.forEach(topic => {
const topicElement = document.createElement('div');
topicElement.className = 'topic-section';
topicElement.setAttribute('data-topic-id', topic.id);
const isTopicComplete = isTopicCompleted(topic);
const isCollapsed = collapsedSections[topic.id];
const gamesGrid = topic.games.map(game => {
const isChecked = checkedGames[game.id] || false;
return `
<div class="game-card ${isChecked ? 'checked' : ''}" data-game-id="${game.id}">
<div class="game-content">
<div class="game-info">
<div class="game-favicon">
${game.favicon ?
`<img src="${game.favicon}" alt="${game.name} icon" onerror="this.style.display='none'; this.parentNode.innerHTML='<i class=\\'fas fa-gamepad\\'></i>';">` :
`<i class="fas fa-gamepad"></i>`
}
</div>
<div class="game-title" style="${isChecked ? 'text-decoration: line-through; color: var(--text-secondary)' : ''}">${game.name}</div>
</div>
<a href="${game.url}" target="_blank" class="game-link">
Play Now <i class="fas fa-external-link-alt"></i>
</a>
</div>
</div>
`;
}).join('');
topicElement.innerHTML = `
<div class="section-title ${isCollapsed ? 'collapsed' : ''}">
<div>
<h2>
<div class="section-icon">
<i class="${topic.icon}"></i>
</div>
${topic.name}
<div class="section-checkmark ${isTopicComplete ? 'checked' : ''}">
<i class="fas fa-check"></i>
</div>
</h2>
<div class="section-description">${topic.description}</div>
</div>
<i class="fas fa-chevron-down collapse-icon"></i>
</div>
<div class="games-grid" style="display: ${isCollapsed ? 'none' : 'grid'}">
${gamesGrid}
</div>
`;
gamesContainer.appendChild(topicElement);
});
// Add event listeners to game cards and section titles
setupGameCardListeners();
setupSectionToggleListeners();
}
// Setup event listeners for game cards
function setupGameCardListeners() {
document.querySelectorAll('.game-card').forEach(card => {
// Make entire card clickable (except the Play Now link)
card.addEventListener('click', (e) => {
// Don't trigger if the click was on the Play Now link
if (e.target.closest('.game-link')) {
return;
}
const gameId = card.getAttribute('data-game-id');
toggleGameCheck(gameId);
});
});
}
// Setup event listeners for section toggling
function setupSectionToggleListeners() {
document.querySelectorAll('.section-title').forEach(title => {
title.addEventListener('click', () => {
const topicSection = title.closest('.topic-section');
const topicId = topicSection.getAttribute('data-topic-id');
const gamesGrid = title.nextElementSibling;
const isCollapsed = gamesGrid.style.display === 'none';
if (isCollapsed) {
gamesGrid.style.display = 'grid';
title.classList.remove('collapsed');
delete collapsedSections[topicId];
} else {
gamesGrid.style.display = 'none';
title.classList.add('collapsed');
collapsedSections[topicId] = true;
}
});
});
}
// Filter games based on search query
function filterGames(query) {
const lowerQuery = query.toLowerCase().trim();
if (!lowerQuery) {
filteredTopics = [];
renderGames();
return;
}
filteredTopics = gamesData.topics.map(topic => {
const filteredGames = topic.games.filter(game =>
game.name.toLowerCase().includes(lowerQuery) ||
topic.name.toLowerCase().includes(lowerQuery) ||
topic.description.toLowerCase().includes(lowerQuery)
);
return filteredGames.length > 0 ? { ...topic, games: filteredGames } : null;
}).filter(topic => topic !== null);
renderGames();
}
// Setup all event listeners
function setupEventListeners() {
// Search functionality
searchBar.addEventListener('input', (e) => {
filterGames(e.target.value);
});
// Clear search on escape key
searchBar.addEventListener('keydown', (e) => {
if (e.key === 'Escape') {
searchBar.value = '';
filterGames('');
}
});
}
// Initialize the app when DOM is loaded
document.addEventListener('DOMContentLoaded', init);