Never Let Chat Pause (Memory Leak Fix)

Keeps chat active to most recent messages, will not allow it to scroll up and see previous messages

当前为 2024-08-28 提交的版本,查看 最新版本

// ==UserScript==
// @name         Never Let Chat Pause (Memory Leak Fix)
// @namespace    https://gf.qytechs.cn/en/users/1200587-trilla-g
// @version      3.7
// @description  Keeps chat active to most recent messages, will not allow it to scroll up and see previous messages
// @author       Trilla_G
// @match        *://*.kick.com/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    let isPaused = false;
    const buttonSelector = 'div.flex.cursor-pointer.items-center.gap-1.rounded.bg-secondary-lighter\\/80.py-1\\.5.pl-2.pr-3.font-semibold.hover\\:bg-secondary-lightest\\/80';

    // Function to check for the button and click it
    function checkForButtonAndClick() {
        if (isPaused) return;
        const button = document.querySelector(buttonSelector);
        if (button) {
            button.click();
            console.log('Button clicked!');
        }
    }

    // Function to handle mutations
    function handleMutations(mutations) {
        let buttonFound = false;
        mutations.forEach(mutation => {
            if (mutation.addedNodes.length) {
                mutation.addedNodes.forEach(node => {
                    if (node.nodeType === Node.ELEMENT_NODE) {
                        if (node.matches(buttonSelector)) {
                            buttonFound = true;
                        } else {
                            const potentialButton = node.querySelector(buttonSelector);
                            if (potentialButton) {
                                buttonFound = true;
                            }
                        }
                    }
                });
            }
        });

        if (buttonFound) {
            checkForButtonAndClick();
        }
    }

    // Create a MutationObserver to monitor DOM changes
    const observer = new MutationObserver(handleMutations);

    // Start observing the body for added nodes
    observer.observe(document.body, { childList: true, subtree: true });

    // Initial check in case the button is already present when the script runs
    checkForButtonAndClick();

    // Set a periodic check to ensure the button is detected even if it's scrolled out of view
    setInterval(checkForButtonAndClick, 1000); // Check every second

    // Add an event listener for the specific keystroke to pause the function
    document.addEventListener('keydown', (event) => {
        if (event.code === 'Delete') {
            isPaused = true;
            console.log('Paused for 15 seconds');
            setTimeout(() => {
                isPaused = false;
                console.log('Resumed');
            }, 15000); // 15000 milliseconds = 15 seconds
        }
    });
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址