Last active 1518334493

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

Revision 3357ae3a867b4f56614c5dc15d4dbd170a4def8a

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/62b56b213344745465d8e59c9eaa22230b849890/gistfile1.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, dagdurl;
6 if (n.album["#text"]) {
7 album = " (from " + n.album["#text"] + ")";
8 } else {
9 album = "";
10 }
11 try {
12 var dagd = new XMLHttpRequest();
13 dagd.open("GET", "https://da.gd/?url=" + encodeURIComponent(n.url), false);
14 dagd.send();
15 dagdurl = " " + />(.*?)</.exec(dagd.responseText);
16 } catch(e) {
17 console.log("dagd: " + e.message);
18 dagdurl = "";
19 }
20 try {
21 var spotify = new XMLHttpRequest();
22 spotify.open("GET", "https://ws.spotify.com/search/1/track.json?q=" + encodeURIComponent(n.artist["#text"] + " - " + n.name), false);
23 spotify.send();
24 var spotresp = JSON.parse(spotify.responseText);
25 if (spotresp["tracks"].length > 0) {
26 var urisplit = spotresp["tracks"][0]["href"].split(":");
27 spurl = " https://open.spotify.com/" + urisplit[1] + "/" + urisplit[2];
28 } else {
29 console.log("spotify: couldn't get url");
30 spurl = "";
31 }
32 } catch(e) {
33 console.log("spotify: " + e.message);
34 spurl = "";
35 }
36 var r = "is listening to " + n.artist["#text"] + " - " + n.name + album + spurl + dagdurl;
37 cb().say("/me " + r);
38 }
39 var n = document.createElement("script");
40 n.setAttribute("type", "text/javascript");
41 n.setAttribute("src", "https://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=" + e + "&api_key=891a3154063e53a608e393b7ec9552f9&limit=1&format=json&callback=window.lfmRecentTrack");
42 document.body.appendChild(n)
43})()