From 12f6e5069d513f16083b918dcce409e6a8917195 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Mon, 22 Jul 2024 23:07:51 +0300 Subject: [PATCH 1/3] Improve auto-scroll snapping --- public/script.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/public/script.js b/public/script.js index 3607eca78..091ac68f9 100644 --- a/public/script.js +++ b/public/script.js @@ -9253,12 +9253,21 @@ jQuery(async function () { } }); const chatElementScroll = document.getElementById('chat'); - chatElementScroll.addEventListener('wheel', function () { - scrollLock = true; - }, { passive: true }); - chatElementScroll.addEventListener('touchstart', function () { - scrollLock = true; - }, { passive: true }); + const chatScrollHandler = function () { + const scrollIsAtBottom = Math.abs(chatElementScroll.scrollHeight - chatElementScroll.clientHeight - chatElementScroll.scrollTop) < 1; + + // Cancel autoscroll if the user scrolls up + if (scrollLock && scrollIsAtBottom) { + scrollLock = false; + } + + // Resume autoscroll if the user scrolls to the bottom + if (!scrollLock && !scrollIsAtBottom) { + scrollLock = true; + } + }; + chatElementScroll.addEventListener('wheel', chatScrollHandler, { passive: true }); + chatElementScroll.addEventListener('touchmove', chatScrollHandler, { passive: true }); chatElementScroll.addEventListener('scroll', function () { if (is_use_scroll_holder) { this.scrollTop = scroll_holder; From e84d0231916630e67ef5a3fb4693bb454fa39a82 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Mon, 22 Jul 2024 23:11:36 +0300 Subject: [PATCH 2/3] Restore old behavior for waifu mode --- public/script.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/public/script.js b/public/script.js index 091ac68f9..60c2d2b7e 100644 --- a/public/script.js +++ b/public/script.js @@ -9254,6 +9254,11 @@ jQuery(async function () { }); const chatElementScroll = document.getElementById('chat'); const chatScrollHandler = function () { + if (power_user.waifuMode) { + scrollLock = true; + return; + } + const scrollIsAtBottom = Math.abs(chatElementScroll.scrollHeight - chatElementScroll.clientHeight - chatElementScroll.scrollTop) < 1; // Cancel autoscroll if the user scrolls up From 9b97d88aeeebb1ebd8c4925ccde2819040ee3d22 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Tue, 23 Jul 2024 15:53:59 +0300 Subject: [PATCH 3/3] Comments are reverse --- public/script.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/script.js b/public/script.js index 60c2d2b7e..dd6af9884 100644 --- a/public/script.js +++ b/public/script.js @@ -9261,12 +9261,12 @@ jQuery(async function () { const scrollIsAtBottom = Math.abs(chatElementScroll.scrollHeight - chatElementScroll.clientHeight - chatElementScroll.scrollTop) < 1; - // Cancel autoscroll if the user scrolls up + // Resume autoscroll if the user scrolls to the bottom if (scrollLock && scrollIsAtBottom) { scrollLock = false; } - // Resume autoscroll if the user scrolls to the bottom + // Cancel autoscroll if the user scrolls up if (!scrollLock && !scrollIsAtBottom) { scrollLock = true; }