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/lib/butterchurn.min.js"></script>
<script src="https://unpkg.com/butterchurn-presets/lib/butterchurnPresets.min.js"></script> <script src="https://unpkg.com/butterchurn-presets/lib/butterchurnPresets.min.js"></script>
<script src="./index.js"></script> <script src="./index.js"></script>
<script> <script>
let username = localStorage.getItem('lastfmUsername') || 'yetiuard'; let username = localStorage.getItem('lastfmUsername') || 'yetiuard';
const url = `https://lastfm-last-played.biancarosa.com.br/${username}/latest-song`; const url = `https://lastfm-last-played.biancarosa.com.br/${username}/latest-song`;
@ -123,7 +122,7 @@
const backgroundElement = document.getElementById('background'); const backgroundElement = document.getElementById('background');
const placeholderImage = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII="; const placeholderImage = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=";
let previousAlbumImage = ""; let previousAlbumImage = "";
function updateSongDisplay(track) { function updateSongDisplay(track) {
const { name, artist, album, image } = track; const { name, artist, album, image } = track;
songElement.classList.remove('updated'); songElement.classList.remove('updated');
@ -146,7 +145,7 @@
backgroundElement.style.backgroundImage = `url(${albumImage})`; backgroundElement.style.backgroundImage = `url(${albumImage})`;
} }
} }
async function fetchLastPlayedSong() { async function fetchLastPlayedSong() {
try { try {
const response = await fetch(url); const response = await fetch(url);
@ -159,10 +158,10 @@
console.error('Error fetching LastFM data:', error); console.error('Error fetching LastFM data:', error);
} }
} }
fetchLastPlayedSong(); fetchLastPlayedSong();
setInterval(fetchLastPlayedSong, 3000); setInterval(fetchLastPlayedSong, 3000);
function openUsernamePrompt() { function openUsernamePrompt() {
const newUsername = prompt('Enter your Last.fm username:', username); const newUsername = prompt('Enter your Last.fm username:', username);
if (newUsername && newUsername !== username) { if (newUsername && newUsername !== username) {
@ -171,13 +170,13 @@
window.location.reload(); window.location.reload();
} }
} }
if ('serviceWorker' in navigator) { if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('./service-worker.js').catch(error => navigator.serviceWorker.register('./service-worker.js').catch(error =>
console.log('Service Worker registration failed:', error) console.log('Service Worker registration failed:', error)
); );
} }
document.querySelectorAll('.dropdown-content a[data-title]').forEach(element => { document.querySelectorAll('.dropdown-content a[data-title]').forEach(element => {
element.addEventListener('click', function (event) { element.addEventListener('click', function (event) {
event.preventDefault(); event.preventDefault();
@ -187,41 +186,22 @@
document.getElementById('favicon').href = newIcon; 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>
<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> </body>
</html> </html>

View file

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