JAYASWAROOP commited on
Commit
0b5b1d5
1 Parent(s): abe5ac1

Update audio.js

Browse files
Files changed (1) hide show
  1. audio.js +35 -1
audio.js CHANGED
@@ -1,3 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  function addToPlaylist() {
2
  // Get information about the song
3
  const songTitle = document.querySelector('.title').innerText;
@@ -24,19 +44,33 @@ function addToPlaylist() {
24
  audioSourceElem.setAttribute('type', 'audio/mpeg');
25
 
26
  newAudio.appendChild(audioSourceElem);
27
-
28
  newSongDiv.appendChild(newSongTitle);
29
  newSongDiv.appendChild(newArtist);
30
  newSongDiv.appendChild(newAudio);
31
 
32
  // Add the new song to the playlist
33
  playlist.appendChild(newSongDiv);
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  }
35
 
36
 
37
 
38
 
39
 
 
40
  function validateSignup() {
41
  var username = document.forms["signupForm"]["username"].value;
42
  var password = document.forms["signupForm"]["password"].value;
 
1
+ let songAdded = false; // Flag to track if the song is already added to the playlist
2
+
3
+ function togglePlaylist() {
4
+ const loveIcon = document.querySelector('.love-icon');
5
+
6
+ if (!songAdded) {
7
+ // Add the song to the playlist
8
+ addToPlaylist();
9
+
10
+ // Change the color of the love icon to indicate it's selected
11
+ loveIcon.classList.add('selected');
12
+ } else {
13
+ // Remove the song from the playlist
14
+ removeFromPlaylist();
15
+
16
+ // Change the color of the love icon back to its original color
17
+ loveIcon.classList.remove('selected');
18
+ }
19
+ }
20
+
21
  function addToPlaylist() {
22
  // Get information about the song
23
  const songTitle = document.querySelector('.title').innerText;
 
44
  audioSourceElem.setAttribute('type', 'audio/mpeg');
45
 
46
  newAudio.appendChild(audioSourceElem);
47
+
48
  newSongDiv.appendChild(newSongTitle);
49
  newSongDiv.appendChild(newArtist);
50
  newSongDiv.appendChild(newAudio);
51
 
52
  // Add the new song to the playlist
53
  playlist.appendChild(newSongDiv);
54
+
55
+ songAdded = true; // Set the flag to true after adding the song
56
+ }
57
+
58
+ function removeFromPlaylist() {
59
+ const playlist = document.querySelector('.playlist');
60
+ const songEntry = playlist.querySelector('.song1');
61
+
62
+ // Remove the song from the playlist
63
+ if (songEntry) {
64
+ playlist.removeChild(songEntry);
65
+ songAdded = false; // Set the flag to false after removing the song
66
+ }
67
  }
68
 
69
 
70
 
71
 
72
 
73
+
74
  function validateSignup() {
75
  var username = document.forms["signupForm"]["username"].value;
76
  var password = document.forms["signupForm"]["password"].value;