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.0
// @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;

    // Define the selector for the button with the exact class name
    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!');
        }
    }

    // Create an IntersectionObserver to monitor the visibility of the button
    const observer = new IntersectionObserver((entries) => {
        entries.forEach(entry => {
            if (!isPaused && entry.isIntersecting) {
                checkForButtonAndClick();
            }
        });
    }, {
        root: null, // Use the viewport as the root
        threshold: 0.1 // Trigger when 10% of the button is visible
    });

    // Initial check to observe the button
    function observeButton() {
        const button = document.querySelector(buttonSelector);
        if (button) {
            observer.observe(button);
            console.log('Observing button element.');
        } else {
            console.log('Button element not found.');
        }
    }

    // Start observing the button if it is present
    observeButton();

    // 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
        }
    });

    // Recheck and start observing button periodically
    setInterval(observeButton, 1000); // Check every second
})();

QingJ © 2025

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