added auto-scrolling for preview
This commit is contained in:
parent
1c64d1f431
commit
fe0f338803
1 changed files with 22 additions and 4 deletions
|
@ -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();
|
||||
}
|
||||
};
|
||||
};
|
||||
})();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue