yuki.k4w411.net/js/lastfm.js

44 lines
1.3 KiB
JavaScript

// this script is under the MIT license (https://max.nekoweb.org/resources/license.txt)
const USERNAME = "kaaisudev"; // Put your LastFM username here
const BASE_URL = `https://lastfm-last-played.biancarosa.com.br/${USERNAME}/latest-song`;
const getTrack = async () => {
const request = await fetch(BASE_URL);
const json = await request.json();
let status;
let isPlaying = json.track["@attr"]?.nowplaying || false;
if (!isPlaying) {
// Trigger if a song isn't playing
return;
} else {
// Trigger if a song is playing
}
// Values:
// COVER IMAGE: json.track.image[1]['#text']
// TITLE: json.track.name
// ARTIST: json.track.artist['#text']
document.getElementById("listening").innerHTML = `
<div class="now-playing-wrapper box">
<!--<h2>listening to:</h2>-->
<a href="https://fm.yuki.k4w411.net/" target="_blank">
<div id="trackInfo">
<img src="${json.track.image[1]["#text"]}">
<div id="trackInfoText">
<h3 id="trackName">${json.track.name}</h3>
<p id="artistName">by ${json.track.artist["#text"]}</p>
</div>
</div>
</a>
</div>
`;
};
getTrack();
setInterval(() => {
getTrack();
}, 10000);