-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyBiblioteca.html
363 lines (318 loc) · 11 KB
/
MyBiblioteca.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
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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Minha Biblioteca de Animes</title>
<link rel="stylesheet" href="MyBiblioteca.css" />
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<!-- SweetAlert CDN -->
<style>
/* Estilos gerais */
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f4f4f4;
}
h1 {
text-align: center;
margin: 20px 0;
color: #333;
}
/* Navbar */
nav {
background-color: #333;
color: white;
padding: 10px 20px;
display: flex;
justify-content: space-between;
align-items: center;
}
nav a {
color: white;
margin: 0 15px;
text-decoration: none;
font-size: 18px;
}
nav a:hover {
text-decoration: underline;
}
/* Botões */
button {
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
margin: 5px;
}
#back-button {
background-color: #4a90e2;
color: white;
}
#clear-library-button {
background-color: #e74c3c;
color: white;
}
#reviews-button {
background-color: #4caf50;
color: white;
}
/* Cards de anime */
.container {
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 20px;
padding: 20px;
}
.anime {
background-color: white;
padding: 15px;
border-radius: 8px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
width: 200px;
text-align: center;
transition: transform 0.3s ease;
}
.anime:hover {
transform: translateY(-10px);
}
.anime img {
max-width: 100%;
border-radius: 8px;
height: 250px;
object-fit: cover;
}
.anime h3 {
font-size: 18px;
margin: 10px 0;
color: #333;
}
.anime p {
color: #777;
}
/* Filtro de categorias */
.category-filter {
text-align: center;
margin-bottom: 20px;
}
.category-filter select {
padding: 10px;
font-size: 16px;
border-radius: 5px;
border: 1px solid #ccc;
}
</style>
</head>
<body>
<!-- Navbar -->
<nav>
<a href="#">Home</a>
<a href="#">Minha Biblioteca</a>
<a href="#">Resenhas</a>
<a href="#">Perfil</a>
</nav>
<h1>Minha Biblioteca de Animes</h1>
<!-- Botões de ação -->
<div style="text-align: center">
<button id="back-button" onclick="goBack()">Voltar</button>
<button id="clear-library-button" onclick="clearLibrary()">
Limpar Biblioteca
</button>
<button id="reviews-button" onclick="goToReviews()">
Minhas Resenhas
</button>
<button id="library-toggle-button" onclick="toggleLibraryView()">
Biblioteca Oculta
</button>
</div>
<!-- Filtro de Categorias -->
<div class="category-filter">
<label for="category-filter">Filtrar por Categoria:</label>
<select id="category-filter" onchange="filterByCategory()">
<option value="all">Todas as Categorias</option>
</select>
</div>
<!-- Exibição de Animes -->
<div class="container">
<div id="anime-list"></div>
</div>
<script>
const loggedInUser = JSON.parse(localStorage.getItem("loggedInUser"));
if (loggedInUser && loggedInUser.favorites) {
displayAnimes(loggedInUser.favorites);
populateCategoryFilter(loggedInUser.favorites);
} else {
document.getElementById("anime-list").innerHTML =
"<p>Nenhum anime favoritado ainda.</p>";
}
// Função para exibir os animes
function displayAnimes(animes) {
const animeList = document.getElementById("anime-list");
animeList.innerHTML = "";
if (animes.length === 0) {
animeList.innerHTML = "<p>Nenhum anime encontrado.</p>";
} else {
animes.forEach((anime) => {
const animeItem = document.createElement("div");
animeItem.classList.add("anime");
animeItem.innerHTML = `
<h3>${anime.title}</h3>
<img src="${anime.image}" alt="${anime.title}">
<p>Categoria: ${anime.category}</p>
<p>Progresso: ${
anime.progress || 0
} episódios assistidos</p>
<input type="number" min="0" placeholder="Episódios assistidos" id="progress-${
anime.id
}">
<button onclick="updateProgress('${
anime.id
}')">Atualizar Progresso</button>
<button onclick="deleteAnime('${
anime.id
}')">Deletar Anime</button>
`;
animeList.appendChild(animeItem);
});
}
}
// Função para atualizar o progresso com SweetAlert
function updateProgress(animeId) {
const progressInput = document.getElementById(`progress-${animeId}`);
const episodesWatched = parseInt(progressInput.value, 10);
if (isNaN(episodesWatched) || episodesWatched < 0) {
Swal.fire({
title: "Erro!",
text: "Por favor, insira um número válido de episódios assistidos.",
icon: "error",
confirmButtonText: "OK",
});
return;
}
const favorites = loggedInUser.favorites || [];
const animeToUpdate = favorites.find((anime) => anime.id === animeId);
if (animeToUpdate) {
animeToUpdate.progress = episodesWatched;
localStorage.setItem("loggedInUser", JSON.stringify(loggedInUser));
Swal.fire({
title: "Sucesso!",
text: `Progresso atualizado para ${episodesWatched} episódios assistidos.`,
icon: "success",
confirmButtonText: "OK",
});
displayAnimes(favorites);
}
}
// Função para deletar um anime com SweetAlert
function deleteAnime(animeId) {
Swal.fire({
title: "Tem certeza?",
text: "Você não poderá reverter essa ação!",
icon: "warning",
showCancelButton: true,
confirmButtonText: "Sim, deletar!",
cancelButtonText: "Cancelar",
}).then((result) => {
if (result.isConfirmed) {
const favorites = loggedInUser.favorites || [];
const updatedFavorites = favorites.filter(
(anime) => anime.id !== animeId
);
loggedInUser.favorites = updatedFavorites;
localStorage.setItem("users", JSON.stringify(updatedFavorites));
displayAnimes(updatedFavorites);
Swal.fire({
title: "Deletado!",
text: "O anime foi deletado da sua biblioteca.",
icon: "success",
confirmButtonText: "OK",
});
}
});
}
// Função para limpar toda a biblioteca com SweetAlert
function clearLibrary() {
Swal.fire({
title: "Tem certeza?",
text: "Isso irá deletar todos os animes da sua biblioteca!",
icon: "warning",
showCancelButton: true,
confirmButtonText: "Sim, limpar!",
cancelButtonText: "Cancelar",
}).then((result) => {
if (result.isConfirmed) {
loggedInUser.favorites = [];
localStorage.setItem("loggedInUser", JSON.stringify(loggedInUser));
displayAnimes([]);
Swal.fire({
title: "Biblioteca limpa!",
text: "Todos os animes foram removidos.",
icon: "success",
confirmButtonText: "OK",
});
}
});
}
// Função para voltar à página anterior
function goBack() {
window.history.back();
}
// Função para redirecionar para a página de resenhas
function goToReviews() {
window.location.href = "resenha.html";
}
// Função para preencher as opções do filtro de categorias
function populateCategoryFilter(animes) {
const categoryFilter = document.getElementById("category-filter");
const categories = new Set(animes.map((anime) => anime.category));
categories.forEach((category) => {
const option = document.createElement("option");
option.value = category;
option.textContent = category;
categoryFilter.appendChild(option);
});
}
// Função para filtrar os animes por categoria
function filterByCategory() {
const selectedCategory =
document.getElementById("category-filter").value;
const filteredAnimes =
selectedCategory === "all"
? loggedInUser.favorites
: loggedInUser.favorites.filter(
(anime) => anime.category === selectedCategory
);
displayAnimes(filteredAnimes);
}
let showingHiddenLibrary = false; // Estado para verificar qual biblioteca está sendo exibida
// Função para alternar entre biblioteca oculta e biblioteca normal
function toggleLibraryView() {
if (showingHiddenLibrary) {
// Exibir a biblioteca normal
const loggedInUser =
JSON.parse(localStorage.getItem("loggedInUser")) || {};
const favorites = loggedInUser.favorites || [];
displayAnimes(favorites, false); // Exibe a biblioteca normal
// Alterar o texto do botão para "Biblioteca Oculta"
document.getElementById("library-toggle-button").textContent =
"Ir para Biblioteca Oculta";
// Atualizar o estado
showingHiddenLibrary = false;
} else {
// Exibir a biblioteca oculta
const hiddenLibrary =
JSON.parse(localStorage.getItem("hiddenLibrary")) || [];
displayAnimes(hiddenLibrary, true); // Exibe a biblioteca oculta
// Alterar o texto do botão para "Ir para Biblioteca Normal"
document.getElementById("library-toggle-button").textContent =
"Ir para Biblioteca Normal";
// Atualizar o estado
showingHiddenLibrary = true;
}
}
</script>
</body>
</html>