This commit is contained in:
2024-09-03 01:09:23 +01:00
parent 3443cb8001
commit 3c1c031986
14 changed files with 201 additions and 22 deletions

0
static/js/links.js Normal file
View File

View File

@@ -40,7 +40,8 @@ function musicOut() {
}
function fetchData() {
let data = fetch('https://alfieking.dev/api/v1/current_song')
// allow cors
let data = fetch('https://alfieking.dev/api/nowplaying')
.then(response => response.json()).then(data => { return data; })
.catch(error => { return null;});
return data;
@@ -49,10 +50,10 @@ function fetchData() {
function updateUi(data) {
enableMusic = true;
document.getElementById('music').style.display = 'flex';
document.getElementById('music-icon').src = data.image;
document.getElementById('music-title').innerText = data.title;
document.getElementById('music-info').innerText = data.artist + ' - ' + data.album;
let progress = data.progress / data.length * 100;
document.getElementById('music-icon').src = data.item.album.images[0].url;
document.getElementById('music-title').innerText = data.item.name;
document.getElementById('music-info').innerText = data.item.artists[0].name + ' - ' + data.item.album.name;
let progress = data.progress_ms / data.item.duration_ms * 100;
document.getElementById('music-progress').style.width = progress + '%';
}
@@ -63,13 +64,8 @@ function hideUi() {
function update() {
fetchData().then(data => {
console.log(data);
if (data != null) {
if (data.idle) {
hideUi();
} else {
updateUi(data);
}
if (data.item != null) {
hideUi();
}
else {
hideUi();
@@ -78,4 +74,4 @@ function update() {
}
update();
setInterval(update, 10000);
setInterval(update, 3000);