-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
36 lines (34 loc) · 1.37 KB
/
script.js
File metadata and controls
36 lines (34 loc) · 1.37 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
document.getElementById('searchButton').addEventListener('click', function() {
const query = document.getElementById('searchBox').value.toLowerCase();
fetch('songs.json')
.then(response => response.json())
.then(data => {
const results = data.songs.filter(song =>
song.title.toLowerCase().includes(query) ||
song.artist.toLowerCase().includes(query)
);
let resultHTML = '';
if (results.length > 0) {
results.forEach(song => {
resultHTML += `<div class="song-result" onclick="showLyrics('${song.title}')">
<h3>${song.title} - ${song.artist}</h3>
</div>`;
});
} else {
resultHTML = '<p>No se encontraron canciones.</p>';
}
document.getElementById('songList').innerHTML = resultHTML;
});
});
function showLyrics(title) {
fetch('songs.json')
.then(response => response.json())
.then(data => {
const song = data.songs.find(song => song.title === title);
if (song) {
document.getElementById('lyricsContent').innerHTML = `
<h3>${song.title} - ${song.artist}</h3>
<pre>${song.lyrics}</pre>`;
}
});
}