Lock Scroll to Bottom

Automatically keep the scroll locked to the bottom of the chat container on t3.chat

As of 2025-05-18. See the latest version.

// ==UserScript==
// @name         Lock Scroll to Bottom
// @namespace    https://github.com/prudentbird
// @version      1.0
// @description  Automatically keep the scroll locked to the bottom of the chat container on t3.chat
// @author       Prudent Bird
// @match        https://t3.chat/*
// @match        https://beta.t3.chat/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=t3.chat
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    function waitForElement(selector, callback) {
        const el = document.querySelector(selector);
        if (el) {
            callback(el);
        } else {
            setTimeout(() => waitForElement(selector, callback), 500);
        }
    }

    waitForElement('div.absolute.inset-0.overflow-y-scroll', (el) => {
        const scrollToBottom = () => {
            setTimeout(() => {
                el.scrollTop = el.scrollHeight;
            }, 0);
        };

        scrollToBottom();

        const observer = new MutationObserver(scrollToBottom);
        observer.observe(el, { childList: true, subtree: true });

        console.log('Scroll lock observer set up');
    });
})();