This commit is contained in:
EduardSkibidiEdger 2024-12-01 22:04:30 +02:00
parent 791cd5254c
commit 630e63588e
2 changed files with 28 additions and 48 deletions

View file

@ -114,7 +114,6 @@
<script src="https://unpkg.com/butterchurn/lib/butterchurn.min.js"></script>
<script src="https://unpkg.com/butterchurn-presets/lib/butterchurnPresets.min.js"></script>
<script src="./index.js"></script>
<script>
let username = localStorage.getItem('lastfmUsername') || 'yetiuard';
const url = `https://lastfm-last-played.biancarosa.com.br/${username}/latest-song`;
@ -123,7 +122,7 @@
const backgroundElement = document.getElementById('background');
const placeholderImage = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=";
let previousAlbumImage = "";
function updateSongDisplay(track) {
const { name, artist, album, image } = track;
songElement.classList.remove('updated');
@ -146,7 +145,7 @@
backgroundElement.style.backgroundImage = `url(${albumImage})`;
}
}
async function fetchLastPlayedSong() {
try {
const response = await fetch(url);
@ -159,10 +158,10 @@
console.error('Error fetching LastFM data:', error);
}
}
fetchLastPlayedSong();
setInterval(fetchLastPlayedSong, 3000);
function openUsernamePrompt() {
const newUsername = prompt('Enter your Last.fm username:', username);
if (newUsername && newUsername !== username) {
@ -171,13 +170,13 @@
window.location.reload();
}
}
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('./service-worker.js').catch(error =>
console.log('Service Worker registration failed:', error)
);
}
document.querySelectorAll('.dropdown-content a[data-title]').forEach(element => {
element.addEventListener('click', function (event) {
event.preventDefault();
@ -187,41 +186,22 @@
document.getElementById('favicon').href = newIcon;
});
});
// New onTrackDidChange functionality
const unsubscribe = webamp.onTrackDidChange((trackInfo) => {
if (trackInfo && trackInfo.metaData) {
const { title = "Unknown Title", artist = "Unknown Artist" } = trackInfo.metaData;
console.log("New track playing:", { title, artist });
} else if (trackInfo) {
console.log("New track URL:", trackInfo.url);
} else {
console.log("No track is currently playing.");
}
});
// Example: Unsubscribe when no longer needed
// unsubscribe();
</script>
<script>
let currentSong = {
title: '',
artist: ''
};
// Update currentSong with the track details every time the track changes
webamp.onTrackDidChange((trackInfo) => {
if (trackInfo) {
currentSong = {
title: trackInfo.metaData.title || '',
artist: trackInfo.metaData.artist || ''
};
console.log('Currently playing:', currentSong);
} else {
// If no track is playing, set the song to empty values
currentSong = {
title: '',
artist: ''
};
console.log('No track is currently playing');
}
});
// You can check the current song at any time
function getCurrentSong() {
return currentSong;
}
// Example of how you can get the current song manually:
setInterval(() => {
console.log('Current Song:', getCurrentSong());
}, 5000); // Logs the current song every 5 seconds
</script>
</body>
</html>

View file

@ -1497,21 +1497,21 @@ const webamp = new Webamp({
"artist": "OutKast",
"title": "So Fresh, So Clean"
},
"url": "https://8.prigoana.lol/OutKast - So Fresh, So Clean.flac"
"url": "https://8.prigoana.lol/Outkast - So Fresh, So Clean.flac"
},
{
"metaData": {
"artist": "OutKast",
"title": "Spaghetti Junction"
},
"url": "https://8.prigoana.lol/OutKast - Spaghetti Junction.flac"
"url": "https://8.prigoana.lol/Outkast - Spaghetti Junction.flac"
},
{
"metaData": {
"artist": "OutKast with Khujo Goodie",
"title": "Gasoline Dreams"
},
"url": "https://8.prigoana.lol/OutKast with Khujo Goodie - Gasoline Dreams.flac"
"url": "https://8.prigoana.lol/Outkast with Khujo Goodie - Gasoline Dreams.flac"
},
{
"metaData": {
@ -1623,14 +1623,14 @@ const webamp = new Webamp({
"artist": "OutKast",
"title": "B.O.B. (Bombs Over Baghdad)"
},
"url": "https://9.prigoana.lol/OutKast - B.O.B. (Bombs Over Baghdad).flac"
"url": "https://9.prigoana.lol/Outkast - B.O.B. (Bombs Over Baghdad).flac"
},
{
"metaData": {
"artist": "OutKast",
"title": "Xplosion"
},
"url": "https://9.prigoana.lol/OutKast - Xplosion.flac"
"url": "https://9.prigoana.lol/OutKast-%20Xplosion.flac"
},
{
"metaData": {
@ -1651,7 +1651,7 @@ const webamp = new Webamp({
"artist": "OutKast",
"title": "ATLiens"
},
"url": "https://9.prigoana.lol/OutKast - ATLiens.flac"
"url": "https://9.prigoana.lol/OutKast- ATLiens.flac"
},
{
"metaData": {