Skip to content

Instantly share code, notes, and snippets.

@Madbrad200
Forked from blha303/iclfm.js
Last active February 11, 2018 17:38
Show Gist options
  • Save Madbrad200/75d0bdb867fe648fdcf97231731b3eb4 to your computer and use it in GitHub Desktop.
Save Madbrad200/75d0bdb867fe648fdcf97231731b3eb4 to your computer and use it in GitHub Desktop.
IRCCloud last.fm now-playing bookmarklet - Change the 'e' variable to your own last.fm username.
javascript: (function () { var jB = document.createElement('script'); jB.setAttribute('type', 'text/javascript'); jB.setAttribute('src', 'https://gist.githubusercontent.com/Madbrad200/75d0bdb867fe648fdcf97231731b3eb4/raw/3a2d19fdf673e07c04cc93efe97a457e307ee99b/irccloudlastfm.js'); document.body.appendChild(jB); document.body.appendChild(jB); }());
(function () {
var e = "Madluke200";
window.lfmRecentTrack = function (t) {
var n = (new Array).concat(t.recenttracks.track)[0];
var album, spurl;
if (n.album["#text"]) {
album = " (from " + n.album["#text"] + ")";
} else {
album = "";
}
try {
var spotify = new XMLHttpRequest();
spotify.open("GET", "https://ws.spotify.com/search/1/track.json?q=" + encodeURIComponent(n.artist["#text"] + " - " + n.name), false);
spotify.send();
var spotresp = JSON.parse(spotify.responseText);
if (spotresp["tracks"].length > 0) {
//var urisplit = spotresp["tracks"][0]["href"].split(":");
//spurl = " https://open.spotify.com/" + urisplit[1] + "/" + urisplit[2];
spurl = spotresp["tracks"][0]["href"];
} else {
console.log("spotify: couldn't get url");
spurl = "";
}
} catch(e) {
console.log("spotify: " + e.message);
spurl = "";
}
var r = "is listening to " + n.name + " by " + n.artist["#text"] + " " + album + " (" + spurl + ")";
cb().say("/me " + r);
}
var n = document.createElement("script");
n.setAttribute("type", "text/javascript");
n.setAttribute("src", "https://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=" + e + "&api_key=dd5fb083b94a7196cf696b9d7d11bc63&limit=1&format=json&callback=window.lfmRecentTrack");
document.body.appendChild(n)
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment