Last active 1518334493

IRCCloud last.fm now-playing bookmarklet - Change the 'e' variable to your own last.fm username.

iclfm.js Raw
1javascript: (function () { var jB = document.createElement('script'); jB.setAttribute('type', 'text/javascript'); jB.setAttribute('src', 'https://gist.github.com/blha303/7602104/raw/6ad79edbd0bec1b6bce17472409843c61d899842/irccloudlastfm.js'); document.body.appendChild(jB); document.body.appendChild(jB); }());
irccloudlastfm.js Raw
1(function () {
2 var e = "blha303";
3 window.lfmRecentTrack = function (t) {
4 var n = (new Array).concat(t.recenttracks.track)[0];
5 var album, spurl;
6 if (n.album["#text"]) {
7 album = " (from " + n.album["#text"] + ")";
8 } else {
9 album = "";
10 }
11 try {
12 var spotify = new XMLHttpRequest();
13 spotify.open("GET", "https://ws.spotify.com/search/1/track.json?q=" + encodeURIComponent(n.artist["#text"] + " - " + n.name), false);
14 spotify.send();
15 var spotresp = JSON.parse(spotify.responseText);
16 if (spotresp["tracks"].length > 0) {
17 //var urisplit = spotresp["tracks"][0]["href"].split(":");
18 //spurl = " https://open.spotify.com/" + urisplit[1] + "/" + urisplit[2];
19 spurl = spotresp["tracks"][0]["href"];
20 } else {
21 console.log("spotify: couldn't get url");
22 spurl = "";
23 }
24 } catch(e) {
25 console.log("spotify: " + e.message);
26 spurl = "";
27 }
28 var r = "is listening to " + n.name + " by " + n.artist["#text"] + " " + album + " (" + spurl + ")";
29 cb().say("/me " + r);
30 }
31 var n = document.createElement("script");
32 n.setAttribute("type", "text/javascript");
33 n.setAttribute("src", "https://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=" + e + "&api_key=dd5fb083b94a7196cf696b9d7d11bc63&limit=1&format=json&callback=window.lfmRecentTrack");
34 document.body.appendChild(n)
35})()