3
3
// Use this on a website that is lucky enough to not use a javascript powered framework
4
4
// for a personal-website frontend
5
5
6
+ // Make sure you import jquery before using this!
7
+
8
+ // Use this on a website that is lucky enough to not use a javascript powered framework
9
+ // for a personal-website frontend
10
+
6
11
$ . ajax ( {
7
12
url : 'https://yourweb.site/api/currentplaying' ,
8
13
type : 'get' ,
9
14
dataType : 'JSON' ,
10
15
success : function ( resp ) {
11
- //console.log("DONE!");
12
- //console.log(resp['trackname']);
13
- //console.log(resp['author']);
14
- //console.log(resp);
16
+
15
17
if ( resp [ 'playing' ] == true ) {
16
18
//console.log(resp['url']);
17
19
//console.log(resp['playing']);
@@ -20,16 +22,28 @@ $.ajax({
20
22
21
23
a . className += " show" ;
22
24
var songName = resp [ 'trackname' ] ;
23
- var artists = resp [ 'author' ] ;
24
25
var albumTitle = resp [ 'albumtitle' ] ;
25
26
var albumArtURL = resp [ 'albumart' ] ;
27
+ var authors = "" ;
28
+
29
+ //Getting Author(s)
30
+ if ( resp . urls . artists . length > 1 ) {
31
+ for ( i = 0 ; i < resp . urls . artists . length ; i ++ ) {
32
+ //authors[i] = {"name": data.body.item.artists[i].name, "url": data.body.item.artists[i].external_urls.spotify};
33
+ authors += resp . urls . artists [ i ] . name + ", " ;
34
+ }
35
+ } else {
36
+ authors += resp . urls . artists [ 0 ] . name
37
+ }
26
38
27
39
$ ( songname ) . text ( songName ) ;
28
- $ ( songartists ) . text ( "by " + artists ) ;
40
+ $ ( songartists ) . text ( "by " + authors ) ;
29
41
$ ( album ) . text ( "on " + albumTitle )
30
- $ ( spotifyURL ) . attr ( "href" , resp [ 'url' ] ) ;
42
+ $ ( albumURL ) . attr ( "href" , resp . urls . albumURL )
43
+ //$(albumURL).attr("href", "#") // Needs to be replaced with new api responses in future.
44
+ $ ( songURL ) . attr ( "href" , resp . urls . trackURL ) ;
31
45
$ ( albumart ) . attr ( "src" , albumArtURL )
32
46
33
47
}
34
48
}
35
- } )
49
+ } )
0 commit comments