-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathlike.html
More file actions
58 lines (49 loc) · 1.91 KB
/
like.html
File metadata and controls
58 lines (49 loc) · 1.91 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="./assets/css/style.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
<title>My Favorite Quotes</title>
</head>
<body>
<div class="container">
<h1>My Favorite Quotes</h1>
<div id="favorite-quotes"></div>
<button onclick="window.location.href='index.html'">Back to Home</button>
</div>
<script>
const FAVORITES_KEY = "favoriteQuotes";
const favoriteQuotesContainer = document.getElementById("favorite-quotes");
const favorites = JSON.parse(localStorage.getItem(FAVORITES_KEY)) || [];
function renderFavorites() {
favoriteQuotesContainer.innerHTML = "";
if (favorites.length > 0) {
favorites.forEach((quote, index) => {
const quoteElement = document.createElement("div");
quoteElement.classList.add("favorite-quote");
const quoteText = document.createElement("p");
quoteText.innerText = quote;
// Create delete icon
const deleteIcon = document.createElement("i");
deleteIcon.classList.add("fas", "fa-trash", "delete-icon");
deleteIcon.addEventListener("click", () => removeFavorite(index));
// Append quote text and delete icon to quote element
quoteElement.appendChild(quoteText);
quoteElement.appendChild(deleteIcon);
favoriteQuotesContainer.appendChild(quoteElement);
});
} else {
favoriteQuotesContainer.innerHTML = "<p>You have no favorite quotes yet.</p>";
}
}
function removeFavorite(index) {
favorites.splice(index, 1);
localStorage.setItem(FAVORITES_KEY, JSON.stringify(favorites));
renderFavorites();
}
renderFavorites();
</script>
</body>
</html>