main
Wiki 2025-02-12 16:21:44 +00:00
parent 5e46426e61
commit 494bd9fc37
6 changed files with 47 additions and 8 deletions

BIN
assets/day-bg.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

BIN
assets/evening-bg.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

BIN
assets/night-bg.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

View File

@ -1,5 +1,25 @@
<script src="./main.js"></script>
<!DOCTYPE html>
<body>listening to: <n></n></body>
<img id="trackIcon">
<a id="track"></a>
<table>
<tr>
<td>
<img id="left-border" style="position: absolute; top: 0; left: 0; image-rendering: pixelated; height: 100%;">
</td>
<td>
<div style="position: absolute; left: 15%;">
<body>
listening to: <n></n>
</body>
<img id="trackIcon">
<a id="track"></a>
</div>
</td>
<td>
<img id="right-border" style="position: absolute; top: 0; right: 0; image-rendering: pixelated; height: 100%; -webkit-transform: scaleX(-1); transform: scaleX(-1);">
</td>
</tr>
</table>
<script src="./main.js"></script>

27
main.js
View File

@ -1,13 +1,13 @@
async function getData() {
const url = "http://localhost:3000/userrecent?userName=sussyenby&limit=1";
const url = "http://localhost:3000/userrecent?userName=sussyenby&limit=1"; // request most recent track
try {
const response = await fetch(url);
if (!response.ok) {
throw new Error(`Response status: ${response.status}`);
throw new Error(`Response status: ${response.status}`); // return response
}
const json = await response.json();
try{ if (json.recenttracks.track[0]["@attr"].nowplaying) {
try{ if (json.recenttracks.track[0]["@attr"].nowplaying) { // check if most recent track is currently playing
console.log(json.recenttracks.track[0].name)
console.log(json.recenttracks.track[0].url)
console.log(json.recenttracks.track[0].image[0]["#text"])
@ -22,4 +22,23 @@ async function getData() {
}
}
async function setBg() {
const d = new Date();
let hour = d.getHours();
document.getElementById("track").innerHTML = hour
if (hour < 18 ) {
time = "day"
} else if (hour < 20) {
time = "evening"
} else {
time = "night"
}
console.log(`assets/${time}-bg`)
document.getElementById("left-border").setAttribute("src", `assets/${time}-bg.png`)
document.getElementById("right-border").setAttribute("src", `assets/${time}-bg.png`)
}
setBg()
getData()

0
style.css Normal file
View File