-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlastfm-app.xml
128 lines (110 loc) · 4.84 KB
/
lastfm-app.xml
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
<?xml version="1.0" encoding="UTF-8"?>
<Module>
<ModulePrefs
title="__MSG_appTitle__"
description="__MSG_appDescription__"
author="Jonas Alves"
author_location="São Paulo, Brazil"
author_email="jonasfa@gmail.com"
screenshot="http://github.com/jonasfa/lastfm-opensocial/raw/master/screenshot.png"
thumbnail="http://github.com/jonasfa/lastfm-opensocial/raw/master/thumbnail.png">
<Require feature="opensocial-0.8" />
<Locale messages="http://github.com/jonasfa/lastfm-opensocial/raw/master/i18n/ALL_ALL.xml"/>
<Locale lang="en" messages="http://github.com/jonasfa/lastfm-opensocial/raw/master/i18n/en_ALL.xml"/>
<Locale lang="pt" messages="http://github.com/jonasfa/lastfm-opensocial/raw/master/i18n/pt_ALL.xml"/>
</ModulePrefs>
<Content type="html"><![CDATA[
<!-- ALm6fM1yOonmCB8VVj0iLD_AK4t1nJ0kAbnMJtvIBi7zxjtT8FuJn7cIsFBAOtlQ08vPfcIyuA5I3D0FLcON3Mri-BHzzzh9-9dTRZBeJE3fyl72T-yxHeNUMR7PBzmShrIansGo4ROV4xTXcxjwGJbetDu6TT4mh96CsNtwx2IpNh4nqHGYOlw= -->
<div id="owner_form_div" style="display:none">
<form action="#" id="owner_form" onsubmit="ownerSubmit();return(false);">
<label for="lastfm_username">__MSG_username__:</label>
<input type="text" name="lastfm_username" id="lastfm_username" />
<input type="submit" value="__MSG_submit__" />
</form>
</div>
<div id="chart">
</div>
<a target="_blank" href="#" id="visit">__MSG_visit__</a>
<a target="_blank" href="http://www.last.fm/about" id="about">__MSG_about__</a>
<style type="text/css">
@import url(http://github.com/jonasfa/lastfm-opensocial/raw/master/style.css);
</style>
<script type="text/javascript">
var lastfmUsername = null;
var prefs = new gadgets.Prefs();
gadgets.util.registerOnLoadHandler(loadGadget);
function loadGadget() {
var req = opensocial.newDataRequest();
req.add(req.newFetchPersonRequest("OWNER"), "get_owner");
req.send(responseOwner);
}
function responseOwner(dataResponse) {
var owner = dataResponse.get("get_owner").getData();
if (owner != null) {
if (owner.isViewer()) {
document.getElementById("owner_form_div").style.display = "";
}
loadLastFMUsername(owner);
setTimeout("loadChart()", 1000);
}
}
function ownerSubmit() {
req = opensocial.newDataRequest();
lastfmUsername = document.getElementById('lastfm_username').value;
req.add(req.newUpdatePersonAppDataRequest("VIEWER", 'lastfm_username', lastfmUsername));
req.send(loadChart);
}
function loadLastFMUsername(owner) {
var req = opensocial.newDataRequest();
var idspec = opensocial.newIdSpec({ "userId" : "OWNER", "groupId" : "SELF" });
req.add(req.newFetchPersonAppDataRequest(idspec, "lastfm_username"), "get_data");
req.send(function(response) {
if (response.get("get_data").hadError()) {
document.getElementById("chart").innerHTML = "ERROR";
} else {
data = response.get("get_data").getData();
lastfmUsername = data[owner.getId()]["lastfm_username"];
document.getElementById("visit").href = "http://www.last.fm/user/" + lastfmUsername;
document.getElementById("visit").style.display = "inline";
document.getElementById("lastfm_username").value = lastfmUsername;
}
});
}
function loadChart() {
var url = "http://ws.audioscrobbler.com/1.0/user/" + lastfmUsername + "/recenttracks.rss?" + new Date().getTime()
var params = {};
params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.FEED;
params[gadgets.io.RequestParameters.NUM_ENTRIES] = 10;
gadgets.io.makeRequest(url, loadChart_callback, params);
}
function loadChart_callback(response) {
var html_output = "<table>";
for(entry in response.data.Entry) {
html_output += "<tr>";
html_output += "<td class='title'><a target='_blank' href='" + response.data.Entry[entry].Link + "'>" + response.data.Entry[entry].Title + "</a></td>";
html_output += "<td class='date'>";
html_output += new Date(response.data.Entry[entry].Date).toFormattedString();
html_output += "</td>";
html_output += "</tr>";
}
html_output += "</table>";
document.getElementById("chart").innerHTML = html_output;
}
Date.prototype.toFormattedString = function() {
output = "";
output += this.getDate() + " ";
output += prefs.getMsg("month_name_"+this.getMonth());
output += " ";
if (this.getHours() < 10) {
output += "0";
}
output += this.getHours() + ":";
if (this.getMinutes() < 10) {
output += "0";
}
output += this.getMinutes();
return(output);
}
</script>
]]></Content>
</Module>