Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!--
◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇
◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇
   last.fm sounds of the now
◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇
◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇
i learned about the last.fm stuff
       from the amazing
 Prashant Shrestha (prashant.me)
◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇
◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇

-->

<div id="lastfm">
  <div id="covers">
    <a id="albumartlink" target="_blank">
      <img id="albumart" style="display:none;" alt=" "><!-- the previous line denotes the image showing the artwork associated with the current song -->
    </a>
  </div>
  <div id="sounds">
    <h3>Sounds of the Now</h3>
    <p>
      <span id="current">I've been listening to <a id="tune">
          <!-- javascript will fill this area with the song title and artist name -->
        </a> lately.</span>
      <!-- the previous section (<span id="current"> etc</span>) vanishes entirely if nothing is playing -->
      <span id="silent">Nothing is currently playing... maybe you should recommend some music?!</span>
      <!--
and is replaced by the previous section (id="silent"), customize as you want -->

      Visit the <a href="#">playlists page here</a>, or my <a id="profile" target="_blank">Last.fm profile</a>.
      <!-- the previous sentence with the link to a playlists page can be altered in any way you want, to remove the link, add others, etc. Alternatively, remove it entirely. -->
    </p>
  </div>
</div>

<!-- widget ends here, the script bit below goes just below your </body> tag as usual -->

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
              
            
!

CSS

              
                body {
  /* for demonstrative purposes, i've constrained the page to a sidebar-like width of 30%. ignore this part, because usually, you'll be plopping this in your own sidebar or something */
  width: 30%;
  margin: auto;
}

/*
◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇
◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇
   last.fm sounds of the now
◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇
◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇
i learned about the last.fm stuff
       from the amazing
 Prashant Shrestha (prashant.me)
◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇
◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇
*/

#lastfm {
  width: 100%; /* this should remain 100% obviously, if you want it to entirely fill the container in which it is placed, ie, a sidebar, etc... */
  margin: 0.5em auto;
  border: 0.5em solid; /* border for the entire display container */
  border-radius: 0.5em;
  background-color: pink; /* the display background color */
  transition: 0.3s;
  display: inline-block;
}

#covers {
  width: 20%;
  float: left;
  display: block;
}

#lastfm a img#albumart {
  width: 100%;
  aspect-ratio: auto 1 / 1;
  margin: 0.5em;
  border: 0.5em solid black; /* border for the album art image, also can function as padding for it if you want to change it to the background color of #lastfm */
  border-radius: 0.5em;
}

#sounds {
  text-align: center;
  float: right;
  width: calc(80% - 1.5em);
  display: block;
}

/* the next four entries represent wholly aesthetic choices and can be played with and changed as you wish, mostly without breaking the widget :-) */

#sounds h3 {
  font-size: 1.5em;
  border-bottom: 1em double;
  text-align: center;
  margin: auto;
  font-family: impact;
  text-transform: uppercase;
}

#sounds p {
  margin: 0 0.5em 0.5em;
  text-align: center;
  font-size: 0.8em;
  font-weight: bold;
  padding: 0.4em;
  font-family: tahoma;
}

#sounds a {
  text-decoration: none;
  color: firebrick;
}

#sounds a:hover {
  text-decoration: underline;
}

              
            
!

JS

              
                //◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇
//◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇
//   last.fm sounds of the now
//◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇
//◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇
// i learned about last.fm's stuff
//       from the amazing
// Prashant Shrestha (prashant.me)
//◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇
//◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇
const apikey = "c0fba2a4e49b8d2fa38bfed35df268ab"; //last.fm API key goes here of course...
const username = "ClarityAnne"; //last.fm username goes here...
const s = 60; //number of seconds before each refresh
const profile = "https://last.fm/user/" + username;
const tunes = function () {
  $.ajax({
    type: "GET",
    url:
      "https://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=" +
      username +
      "&api_key=" +
      apikey +
      "&format=json&limit=1", //building the call, and calling out to last.fm for your most recent track, but will they grace us with a response? do not refuse the call. it is your destiny, last.fm
    dataType: "json",
    success: function (resp) {
      //oh, they responded - good... moving on...
      var tuning = resp.recenttracks.track[0]; //pull most recent track pls?

      var formatted = tuning.name + " by " + tuning.artist["#text"]; //format display of most recent track title and artist name
      $("#silent").hide(); //hides the error message if there's no error. i love weed...
      $("#tune").html(formatted); //adds a line of visible text including the song title and artist

      $("#albumart").attr("src", tuning.image[2]["#text"]);
      $("#albumart").on("load", function () {
        $("#albumart").show();
      }); //adds the albumart of the most recent song playe, but only once it has loaded so that there's no "gap" of sorts with a blank image

      $("#profile")
        .attr("href", profile)
        .attr("target", "_blank")
        .attr("title", username + " on Last.fm"); //links to your very own last.fm profile automatically!!

      $("#tune, #albumartlink") //links both the text displaying the current song and the album art to the song's page
        .attr("href", tuning.url)
        .attr("title", tuning.name + " by " + tuning.artist["#text"])
        .attr("target", "_blank");
    },
    //this part sets up an error function. it hides the text and the album art portion and shows the notice that nothing is playing. to preview what this looks like, remove your API key or replace it with dummy numbers instead.
    error: function (resp) {
      $("#covers").hide();
      $("#current").hide();
      $("#sounds").css("width", "100%");
      $("#silent").show();
    }
  });
};

tunes(); //the function executes when the page loads
setInterval(tunes, s * 1000);
// reloading to see what new stuff is playing. you can remove the latter line (setIntervals etc) if you only want this to load once per page load, without updating.
//i'm so zooted right now

              
            
!
999px

Console