a2s.su/pages/js/lastfm-nowplay.js

33 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

export function update_lastfm_nowplay() {
let user = 'Alex_Popov';
let apikey = '5556942dcf4c422dca68d57fbbfdee23';
let url = `https://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=${user}&api_key=${apikey}&format=json&limit=1`;
let status_text = document.getElementById('lastfm_card_title');
let song_text = document.getElementById('lastfm_card_content');
let desc_text = document.getElementById('lastfm_card_footer');
fetch(url)
.then((response) => response.json())
.then((data) => {
// update desc
let desc_string = `Всего прослушано ${data.recenttracks['@attr'].total} треков`;
desc_text.innerText = desc_string;
// update content
let track_string = `${data.recenttracks.track[0].artist['#text']}${data.recenttracks.track[0].name}`;
song_text.innerText = track_string;
// TODO: get play now
status_text.innerText = 'Последний проигранный трек';
})
.catch((err) => console.warn('Something went wrong.', err));
}
/*
Application name a2s
API key 5556942dcf4c422dca68d57fbbfdee23
Shared secret e1e1baa61478c5745c35b985ed2a49a9
Registered to Alex_Popov
*/