-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjukebox.html
91 lines (79 loc) · 3.1 KB
/
jukebox.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
<!DOCTYPE html>
<html>
<head>
<title>Jukebox 320</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="resources/css/bootstrap.min.css">
<link rel="stylesheet" href="resources/fonts/material-icons.css">
<script src="resources/js/jquery.min.js"></script>
<script src="resources/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container-fluid pastel">
<div class="container header py-4">
<h2 class="display-4">Queue Songs</h2>
</div>
</div>
<br>
<div class="px-4">
<div class="input-group mb-3">
<input type="text" class="form-control" placeholder="Song Title" id="songTitleInput">
<div class="input-group-append">
<button class="btn btn-primary" id="searchSong">Search</button>
</div>
</div>
</div>
<ul class="list-group mx-2" id="songList"></ul>
<script>
const songTitleInput = document.querySelector('#songTitleInput')
const songList = document.querySelector('#songList')
const spotifyQueue = new XMLHttpRequest()
spotifyQueue.onreadystatechange = function() {
if (this.readyState === 4 && this.status === 200) {
// let response = JSON.parse(this.responseText)
alert(`Your song was added to the queue.`)
}
}
function SongListItem(item) {
this.li = document.createElement('li')
this.li.classList.add('list-group-item', 'd-flex', 'justify-content-between', 'align-items-center')
this.img = document.createElement('img')
this.img.src = item.album.images[0].url
this.img.style.maxHeight = '50px'
this.string = document.createElement('span')
this.string.innerText = `${item.name} - ${item.artists.map(x => x.name).join(', ')}`
this.queueButton = document.createElement('span')
this.queueButton.classList.add('badge', 'badge-success', 'badge-pill', 'material-icons')
this.queueButton.style.cursor = 'pointer'
this.queueButton.innerText = 'queue'
this.queueButton.dataset.uri = item.uri
this.queueButton.addEventListener('click', function() {
let uri = this.dataset.uri
spotifyQueue.open('GET', `https://api.joshthings.com/queue_song?uri=${uri}`)
spotifyQueue.send()
})
this.li.appendChild(this.img)
this.li.appendChild(this.string)
this.li.appendChild(this.queueButton)
return this.li
}
const spotifySearch = new XMLHttpRequest()
spotifySearch.onreadystatechange = function() {
if (this.readyState === 4 && this.status === 200) {
let response = JSON.parse(this.responseText)
songList.innerHTML = ''
response.tracks.items.forEach(item => {
songList.appendChild(new SongListItem(item))
});
}
}
// spotifySearch.open('GET', 'https://a105-207-62-170-220.ngrok.io/search_spotify?q=grenade')
// spotifySearch.send()
document.querySelector('#searchSong').addEventListener('click', () => {
spotifySearch.open('GET', `https://api.joshthings.com/search_spotify?q=${songTitleInput.value}`)
spotifySearch.send()
})
</script>
</body>
</html>