-
Notifications
You must be signed in to change notification settings - Fork 3
/
playlists.html
98 lines (86 loc) · 3.96 KB
/
playlists.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
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="icon" type="image/x-icon" href="/img/song.png">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>bread music player</title>
</head>
<body>
<div w3-include-html="components/navbar.html"></div>
<div w3-include-html="components/player.html"></div>
<script src="include.js"></script>
<center><h1 id="title">Your Playlists</h1></center>
<br>
<div class="song2" onclick="createPlaylist()" style="background-color: var(--primary-color);">
<div>
<h2 style="color:white;font-weight:900">Create New Playlist</h2>
<p>Go ahead, make a playlist.</p>
</div>
<img class="cover" src="img/plus.png"">
</div>
<div class="🎃" id="playlistsContainer">
<!-- Playlists will be dynamically added here -->
</div>
<script>
// Function to create a new playlist
function createPlaylist() {
const playlists = JSON.parse(localStorage.getItem("playlists")) || [];
const playlistName = prompt("Enter the name for your new playlist:");
if (playlistName) {
const newPlaylist = { name: playlistName, songs: [] };
playlists.push(newPlaylist);
localStorage.setItem("playlists", JSON.stringify(playlists));
updatePlaylistsMenu();
}
}
// Function to edit playlists
function editPlaylists() {
const playlists = JSON.parse(localStorage.getItem("playlists")) || [];
const playlistIndex = prompt("Enter the index of the playlist you want to edit:");
if (playlistIndex && playlistIndex >= 0 && playlistIndex < playlists.length) {
const newName = prompt("Enter the new name for the playlist:");
if (newName) {
playlists[playlistIndex].name = newName;
localStorage.setItem("playlists", JSON.stringify(playlists));
updatePlaylistsMenu();
}
}
}
// Function to update the playlists menu
function updatePlaylistsMenu() {
const playlistsContainer = document.getElementById("playlistsContainer");
const playlists = JSON.parse(localStorage.getItem("playlists")) || [];
// Clear existing playlists in the menu
playlistsContainer.innerHTML = "";
// Add each playlist to the menu
for (let i = 0; i < playlists.length; i++) {
const playlist = playlists[i];
const playlistElement = document.createElement("div");
playlistElement.classList.add("song2");
playlistElement.onclick = function () {
playPlaylist(playlist);
};
const playlistInfo = document.createElement("div");
playlistInfo.innerHTML = `<h2>${playlist.name}</h2><p>${playlist.songs.length} songs</p>`;
playlistElement.appendChild(playlistInfo);
const playlistImage = document.createElement("img");
playlistImage.classList.add("cover");
playlistImage.src = "img/playlist.png";
playlistElement.appendChild(playlistImage);
playlistsContainer.appendChild(playlistElement);
}
}
// Function to play songs from a playlist
function playPlaylist(playlist) {
// Implement logic to play songs from the selected playlist
// You can use the 'playlist.songs' array to get the list of songs in the playlist
// For simplicity, let's log the playlist name and songs to the console
console.log(`Playing playlist: ${playlist.name}`);
console.log('Songs:', playlist.songs);
}
</script>
<script src="script.js"></script>
</body>
</html>