-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
38 lines (37 loc) · 1.38 KB
/
Copy pathapp.js
File metadata and controls
38 lines (37 loc) · 1.38 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
const input = document.getElementById('input').value;
const sir = document.getElementById('sir').addEventListener("click", function(){
const input = document.getElementById('input').value;
fetch(`https://api.lyrics.ovh/suggest/:${input}`)
.then(res => res.json())
.then(data => {
const value = data.data;
const show = document.getElementById('show');
show.innerHTML='';
for (let i = 0; i < value.length; i++) {
const element = value[i];
const artistName = element.artist.name;
const songTitle = element.title;
const show2 = document.createElement('p');
show2.innerHTML = `<div class="single-result row align-items-center my-3 p-3">
<div class="col-md-9">
<h3 class="lyrics-name">${songTitle}</h3>
<p class="author lead">Album by <span>${artistName}</span></p>
</div>
<div class="col-md-3 text-md-right text-center">
<button onclick="getLyric('${artistName}','${songTitle}')" class="btn btn-success">Get Lyrics</button>
</div>
</div>`
show.appendChild(show2);
}
})
})
const getLyric = (artist, title) => {
const url = `https://api.lyrics.ovh/v1/${artist}/${title}`;
fetch(url)
.then(res => res.json())
.then(data => {
console.log(data);
const showLyrics = document.getElementById('showLyrics');
showLyrics.innerHTML = data.lyrics;
})
}