File size: 4,324 Bytes
2fc2053
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
701a252
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fad9455
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2f8c35e
deacdff
 
568ef55
deacdff
 
568ef55
deacdff
 
 
2f8c35e
deacdff
 
 
 
 
 
0648934
3d661b3
deacdff
 
 
3d661b3
deacdff
 
 
 
 
 
 
3d661b3
deacdff
 
3d661b3
deacdff
3d661b3
deacdff
 
3d661b3
 
0648934
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
// Get all the add-to-playlist buttons
const addToPlaylistButtons = document.querySelectorAll('.add-to-playlist');

// Add event listener to each button
addToPlaylistButtons.forEach(button => {
  button.addEventListener('click', function() {
    // Get the song details
    const songCard = this.closest('.movie');
    const songTitle = songCard.querySelector('.title').textContent;
    const songDescription = songCard.querySelector('.description').textContent;
    const songSrc = songCard.querySelector('source').getAttribute('src');
    
    // Create a new list item element
    const newSongItem = document.createElement('li');
    newSongItem.classList.add('song-item', 'row');
    
    // Create the song item content
    const songItemContent = `
      <div class="song-details col-10 col-md-11">
        <p class="song-title">${songTitle}</p>
        <p class="song-artist">${songDescription}</p>
      </div>
    `;
    
    // Set the content of the new list item
    newSongItem.innerHTML = songItemContent;
    
    // Append the new song item to the playlist
    const playlist = document.querySelector('.song-list');
    playlist.appendChild(newSongItem);
    
    // Update the audio source and display the audio player
    const audioPlayer = document.querySelector('#audio');
    audioPlayer.querySelector('source').setAttribute('src', songSrc);
    audioPlayer.classList.remove('d-none');
  });
});


function validateSignup() {
    var username = document.forms["signupForm"]["username"].value;
    var password = document.forms["signupForm"]["password"].value;
    var email = document.forms["signupForm"]["email"].value;

    if (username === "" || password === "" || email === "") {
      alert("Please enter all the required fields");
      return false;
    }

    var existingUsernames = ['user1', 'user2', 'user3'];
    if (existingUsernames.includes(username)) {
      alert("Username already exists. Please choose a different username");
      return false;
    }

    var existingEmails = ['user1@example.com', 'user2@example.com', 'user3@example.com'];
    if (existingEmails.includes(email)) {
      alert("Email already exists. Please enter a different email address");
      return false;
    }

    // If all validations pass, you can proceed with submitting the form
    return true;
}


function validateLogin() {
    var username = document.forms["loginForm"]["username"].value;
    var password = document.forms["loginForm"]["password"].value;

    if (username === "" || password === "") {
      alert("Please enter both username and password");
      return false;
    }
    
    // Your login validation logic goes here
    // For example:
    if (username !== "admin" || password !== "password") {
      alert("Incorrect username or password");
      return false;
    }

    return true;
}



document.addEventListener('DOMContentLoaded', function () {
    const searchBar = document.getElementById('searchBar');
    const movieContainers = document.querySelectorAll('.movie');

    searchBar.addEventListener('input', function () {
        const searchText = searchBar.value.toLowerCase().trim();

        movieContainers.forEach(function (container) {
            const title = container.querySelector('.title').textContent.toLowerCase();
            const description = container.querySelector('.description').textContent.toLowerCase();

            if (title.includes(searchText) || description.includes(searchText)) {
                container.style.display = 'block';
            } else {
                container.style.display = 'none';
            }
        });
    });

    movieContainers.forEach(function (container) {
        container.addEventListener('click', function () {
            const audio = this.querySelector('audio');

            movieContainers.forEach(function (otherContainer) {
                const otherAudio = otherContainer.querySelector('audio');
                if (otherAudio !== audio && !otherAudio.paused) {
                    otherAudio.pause();
                    otherAudio.classList.add('d-none');
                }
            });

            if (audio.paused) {
                audio.play();
            } else {
                audio.pause();
            }

            audio.classList.toggle('d-none');
        });
    });
});