From c0e5d7efaed37d416e9102e96fcfd77dd4afa8c3 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Wed, 13 Sep 2023 00:51:21 +0300 Subject: [PATCH] Save chat scroll position when user input overflows the line --- public/script.js | 5 +++-- public/scripts/RossAscends-mods.js | 4 ++++ public/scripts/extensions/hypebot/index.js | 8 ++++---- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/public/script.js b/public/script.js index eb7b6c3fb..cdc790ada 100644 --- a/public/script.js +++ b/public/script.js @@ -4436,13 +4436,14 @@ async function read_avatar_load(input) { }); $(".mes").each(async function () { - if ($(this).attr("is_system") == 'true') { + const nameMatch = $(this).attr("ch_name") == formData.get('ch_name'); + if ($(this).attr("is_system") == 'true' && !nameMatch) { return; } if ($(this).attr("is_user") == 'true') { return; } - if ($(this).attr("ch_name") == formData.get('ch_name')) { + if (nameMatch) { const previewSrc = $("#avatar_load_preview").attr("src"); const avatar = $(this).find(".avatar img"); avatar.attr('src', default_avatar); diff --git a/public/scripts/RossAscends-mods.js b/public/scripts/RossAscends-mods.js index 758abcaeb..13cdea5cb 100644 --- a/public/scripts/RossAscends-mods.js +++ b/public/scripts/RossAscends-mods.js @@ -863,8 +863,12 @@ export function initRossMods() { //this makes the chat input text area resize vertically to match the text size (limited by CSS at 50% window height) $('#send_textarea').on('input', function () { + const chatBlock = $('#chat'); + const originalScrollBottom = chatBlock[0].scrollHeight - (chatBlock.scrollTop() + chatBlock.outerHeight()); this.style.height = window.getComputedStyle(this).getPropertyValue('min-height'); this.style.height = (this.scrollHeight) + 'px'; + const newScrollTop = chatBlock[0].scrollHeight - (chatBlock.outerHeight() + originalScrollBottom); + chatBlock.scrollTop(newScrollTop); }); //Regenerate if user swipes on the last mesage in chat diff --git a/public/scripts/extensions/hypebot/index.js b/public/scripts/extensions/hypebot/index.js index a64fe5d9f..250ed97ce 100644 --- a/public/scripts/extensions/hypebot/index.js +++ b/public/scripts/extensions/hypebot/index.js @@ -62,11 +62,11 @@ const generateDebounced = debounce(() => generateHypeBot(), 500); * @param {string} text Text to set */ function setHypeBotText(text) { - const blockA = $('#chat'); - var originalScrollBottom = blockA[0].scrollHeight - (blockA.scrollTop() + blockA.outerHeight()); + const chatBlock = $('#chat'); + const originalScrollBottom = chatBlock[0].scrollHeight - (chatBlock.scrollTop() + chatBlock.outerHeight()); hypeBotBar.html(DOMPurify.sanitize(text)); - var newScrollTop = blockA[0].scrollHeight - (blockA.outerHeight() + originalScrollBottom); - blockA.scrollTop(newScrollTop); + const newScrollTop = chatBlock[0].scrollHeight - (chatBlock.outerHeight() + originalScrollBottom); + chatBlock.scrollTop(newScrollTop); } /**