added auto-scrolling for preview

This commit is contained in:
Daniel Fichtinger 2025-07-13 17:20:59 -04:00
parent 1c64d1f431
commit fe0f338803

View file

@ -1,6 +1,24 @@
const ws = new WebSocket("__SOCKET_ADDRESS_");
ws.onmessage = event => {
(() => {
// if user at the bottom before reload, scroll to new bottom
if (localStorage.getItem("wasAtBottom") === "1") {
localStorage.removeItem("wasAtBottom");
window.addEventListener("load", () => {
requestAnimationFrame(() => {
window.scrollTo(0, document.body.scrollHeight);
});
});
}
const ws = new WebSocket("__SOCKET_ADDRESS_");
ws.onmessage = event => {
if (event.data === "reload") {
location.reload();
// store flag if user currently at bottom
const nearBottom = window.innerHeight + window.scrollY
>= document.body.scrollHeight - 100;
if (nearBottom) {
localStorage.setItem("wasAtBottom", "1");
}
location.reload();
}
};
};
})();