This repository has been archived by the owner on Apr 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.html
138 lines (124 loc) · 4.41 KB
/
popup.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<!DOCTYPE html>
<html>
<head>
<link href='http://fonts.googleapis.com/css?family=Merriweather' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="css/popup.css" type="text/css">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script>
var apiKey = ""; //don't forget your API key
function getReleases() {
$.ajax({
type: 'get',
url: "http://ws.audioscrobbler.com/2.0/?method=user.getnewreleases&format=json&user="+localStorage["lastfmUsername"]+"&api_key="+apiKey,
dataType: 'json',
async: false,
success: function(data) {
html = '';
if(data != null){
aAlbums = new Array();
if(data.albums.album instanceof Array)
aAlbums = data.albums.album;
else
aAlbums = [data.albums.album];
$.each(aAlbums, function(i,item){
albumInfo = getAlbumInfo(item.artist.name, item.name);
buyLinks = getBuyLinks(item.artist.name, item.name);
releaseDateTime = item["@attr"].releasedate.split(" ");
html += '<article>';
html += '<h3><a href="'+item.url+'" title="'+item.name+'" target="_blank">'+item.name+'</a> <span>by <a href="'+item.artist.url+'" title="'+item.artist.name+'" target="_blank">'+item.artist.name+'</a></span></h3>';
html += '<figure><a href="'+item.url+'" title="'+item.name+'" target="_blank">';
html += '<img src="images/case.png" alt="overlay" class="overlay"><img src="'+item.image[2]["#text"]+'" alt="">';
html += '</a></figure>';
html += '<p><strong>Released On</strong>:<br />'+releaseDateTime[0]+' '+releaseDateTime[1]+' '+releaseDateTime[2]+' '+releaseDateTime[3]+'</p>';
if(albumInfo != null)
html += '<p><strong>Activity</strong>:<br />'+albumInfo.playcount+' plays by '+albumInfo.listeners+' listeners</p>';
if(buyLinks.length > 0) {
html += '<div class="buyLinks"><p><strong>Buy Now</strong>:<br />';
for(var i in buyLinks) {
html += '<a href="'+buyLinks[i].buyLink+'" title="'+buyLinks[i].supplierName+'" target="_blank"><img src="'+buyLinks[i].supplierIcon+'" alt="'+buyLinks[i].supplierName+'"></a> ';
}
html += '</p></div>';
}
html += '</article>';
});
$('#newReleases').html(html);
}
}
});
}
function getAlbumInfo(artist, album) {
var albumInfo;
$.ajax({
type: 'get',
url: "http://ws.audioscrobbler.com/2.0/?method=album.getinfo&format=json&api_key="+apiKey+"&artist="+encodeURI(artist)+"&album="+encodeURI(album),
dataType: 'json',
async: false,
success: function(data) {
if(data != null){
albumInfo = data.album;
}
}
});
return albumInfo;
}
function getBuyLinks(artist, album) {
var buyLinks = [];
$.ajax({
type: 'get',
url: "http://ws.audioscrobbler.com/2.0/?method=album.getbuylinks&format=json&artist="+encodeURI(artist)+"&album="+encodeURI(album)+"&country=united%20states&api_key="+apiKey,
dataType: 'json',
async: false,
success: function(data) {
if(data.affiliations != null){
$.each(data.affiliations.downloads.affiliation, function(i,item){
buyLinks[i] = item;
});
}
}
});
return buyLinks;
}
$(document).ready(function() {
if(!localStorage["lastfmUsername"] || localStorage["lastfmUsername"] == "") {
$("#newReleases").hide();
$("#options").slideDown("slow");
} else {
getReleases();
$("#options").hide();
$("#newReleases").slideDown("slow");
}
$("form").submit(function() {
localStorage.setItem("lastfmUsername", $("input[name='username']").val());
$("#options").hide();
$("#newReleases").slideDown("slow");
getReleases();
return false;
});
});
</script>
</head>
<body>
<div id="wrapper">
<header>
<h1><img src="images/lastfm_red.png" alt="Last.fm"></h1>
<h2>New Releases</h2>
</header>
<section id="options">
<form id="options" name="options" action="">
<label>Last.fm Username:</label><br />
<input id="lastfmUsername" type="text" name="username"><br />
<input type="submit" value="Save Options" class="button blue">
</form>
</section>
<section id="newReleases">
<article>
<p>Loading New Releases...</p>
</article>
</section>
<footer>
<p>Developed by <a href="http://twitter.com/fleetingftw" target="_blank">James Fleeting</a> of <a href="http://monkeecreate.com" title="monkeeCreate" target="_blank">monkeeCreate</a><br />
Not affiliated in any way with last.fm</p>
</footer>
</div>
</body>
</html>