107 lines
3.1 KiB
JavaScript
107 lines
3.1 KiB
JavaScript
let refresh = parseInt(new URL(window.location.href).searchParams.get("autorefresh"));
|
|
let r = (refresh * 1000);
|
|
|
|
ref();
|
|
|
|
function ref() {
|
|
let d = window.location.pathname.replace("embed", "api");
|
|
fetch(d).then(async function(resp) {
|
|
let b = await resp.json();
|
|
let base = b.response;
|
|
|
|
// cover
|
|
if (document.querySelector(".cover")) {
|
|
if (base.cover !== null) {
|
|
document.querySelector(".cover").src = base.cover;
|
|
} else {
|
|
document.querySelector(".cover").src = "/assets/record.svg";
|
|
}
|
|
} else {
|
|
window.location.reload();
|
|
return;
|
|
}
|
|
|
|
// track
|
|
if (document.querySelector(".trackLink")) {
|
|
if (base.track.url !== null) {
|
|
document.querySelector(".trackLink").href = base.track.url;
|
|
} else {
|
|
document.querySelector(".trackLink").href = "#";
|
|
}
|
|
} else {
|
|
window.location.reload();
|
|
return;
|
|
}
|
|
if (document.getElementById("stream")) {
|
|
if (base.track.stream) {
|
|
document.getElementById("stream").href = base.track.stream;
|
|
document.getElementById("stream").style.display = "inline-block";
|
|
} else {
|
|
document.getElementById("stream").style.display = "none";
|
|
}
|
|
} else {
|
|
window.location.reload();
|
|
return;
|
|
}
|
|
document.querySelector(".track").innerHTML = base.track.name;
|
|
|
|
// artist
|
|
if (document.querySelector(".artistLink")) {
|
|
if (base.artist.url) {
|
|
document.querySelector(".artistLink").href = base.artist.url;
|
|
} else {
|
|
document.querySelector(".artistLink").href = "#";
|
|
}
|
|
} else {
|
|
window.location.reload();
|
|
return;
|
|
}
|
|
document.querySelector(".artist").innerHTML = base.artist.name;
|
|
|
|
// album
|
|
if (base.album == null) {
|
|
if (document.querySelector(".albumLink")) {
|
|
window.location.reload();
|
|
return;
|
|
}
|
|
} else {
|
|
if (document.querySelector(".albumLink")) {
|
|
if (base.album !== null && base.album.url) {
|
|
document.querySelector(".albumLink").href = base.album.url;
|
|
} else {
|
|
document.querySelector(".albumLink").href = "#"
|
|
}
|
|
} else {
|
|
window.location.reload();
|
|
return;
|
|
}
|
|
if (document.querySelector(".album")) {
|
|
if (base.album !== null && base.album.name) {
|
|
document.querySelector(".album").innerHTML = base.album.name;
|
|
} else {
|
|
window.location.reload();
|
|
return;
|
|
}
|
|
} else {
|
|
window.location.reload();
|
|
return;
|
|
}
|
|
}
|
|
|
|
// timestamp
|
|
if (base["est-timestamp"]) {
|
|
if (base["est-timestamp"] == "live") {
|
|
document.querySelector(".timestamp").innerHTML = `Listening now`;
|
|
document.querySelector(".timestamp").setAttribute("data-timestamp", base.timestamp);
|
|
} else {
|
|
document.querySelector(".timestamp").innerHTML = `Listened ${base["est-timestamp"]}`;
|
|
document.querySelector(".timestamp").setAttribute("data-timestamp", base.timestamp);
|
|
}
|
|
}
|
|
|
|
setTimeout(function() {ref()}, r);
|
|
}).catch(function(err) {
|
|
console.error(err);
|
|
setTimeout(function() {ref()}, r);
|
|
})
|
|
} |