-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload.js
62 lines (57 loc) · 1.87 KB
/
upload.js
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
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString)
let at = localStorage.getItem('access_token');
async function getPlaylists(){
const response = await fetch('https://api.spotify.com/v1/me/playlists', {
method: 'GET',
headers: {
'Authorization': "Bearer "+ at,
'Content-Type': 'application/json'
},
})
const res = (await response.json())
getUsername(res)
}
async function getUsername(json_file) {
const response = await fetch('https://api.spotify.com/v1/me', {
method: 'GET',
headers: {
"Authorization": "Bearer " + at
}
})
const res = (await response.json())
topTenPlaylists(json_file, res.display_name)
}
class Playlist{
constructor(name, id, photoID){
this.name = name
this.id = id
this.photoID = photoID
}
}
function topTenPlaylists(json_file, user) {
let playlists = [];
const items = json_file.items;
let x = 0;
let i = 0;
while (x < 10 && i < items.length) {
let playlist = items[i];
if (playlist.owner.display_name === user) {
playlists.push(new Playlist(playlist.name, playlist.id, playlist.images[0].url));
let imageElement = document.getElementById("image" + (x + 1));
document.getElementById('p' + (x + 1)).innerHTML = playlist.name;
if (imageElement) {
imageElement.src = playlist.images[0].url;
}
x++;
}
i++;
}
localStorage.setItem('playlistCollection', JSON.stringify(playlists));
}
function selectPlaylist(num){
const storedList = JSON.parse(localStorage.getItem('playlistCollection'));
const selectedPlaylist = storedList[num-1]
localStorage.setItem('playlistImage', selectedPlaylist.photoID)
localStorage.setItem('selectedPlaylist', selectedPlaylist.id)
}