better scrolling

This commit is contained in:
Jeeves 2025-02-18 23:12:23 -07:00
parent baf29cefa5
commit 297108ee4a

View file

@ -3,44 +3,39 @@ const statusLineElement2 = statusLineElement.cloneNode();
statusLineElement2.id = "status-line2";
document.body.appendChild(statusLineElement2);
let status = "Streamboy is connecting...";
let status = { blocks: [{ text: "Streamboy is connecting...", color: "#ffffff" }] };
let scroll = 0;
setInterval(() => {
let string = "";
for (const i in status.blocks) {
string += status.blocks[i].text;
if (i < status.blocks.length - 1) string += " | ";
}
if (scroll >= status.length) scroll = 0;
// if (scroll == 0) {
// statusLineElement.textContent = status;
// } else {
// let string = "";
// string += status.slice(scroll);
// string += status.slice(0, scroll);
// statusLineElement.textContent = string;
// }
const stringWidth = 8 * status.length;
const stringWidth = 8 * string.length + 72;
if (8 * string.length <= statusLineElement.parentElement.clientWidth) {
scroll = 0;
statusLineElement.style.removeProperty("position");
statusLineElement.style.removeProperty("left");
statusLineElement2.style.display = "none";
statusLineElement.textContent = string;
statusLineElement2.textContent = string;
} else {
statusLineElement.style.position = "absolute";
statusLineElement.style.left = `${-8 * scroll}px`;
statusLineElement2.style.position = "absolute";
statusLineElement2.style.left = `${-8 * scroll + stringWidth}px`;
// console.log(statusLineElement.style.left)
statusLineElement.textContent = status;
statusLineElement2.textContent = status;
statusLineElement2.style.removeProperty("display");
scroll += 1;
}, 750);
statusLineElement.textContent = string + " | ";
statusLineElement2.textContent = string + " | ";
}
}, 500);
const socket = new WebSocket("ws://localhost:8012");
socket.addEventListener("message", (event) => {
const data = JSON.parse(event.data);
let string = "";
for (const block of data.blocks) {
string += block.text;
string += " | ";
}
status = string;
status = JSON.parse(event.data);
});
// const status = {
// blocks: [
// "Something Fun For Everyone With Streamboy!!!!!!!! git.jeevio.xyz/jeeves/streamboy",
// "♪ Bonhomme de Neige (EarthBound) - Ridley Snipes feat. Earth Kid",
// ],
// };