Never Let Chat Pause

Automatically clicks elements on Kick.com to keep the chat or other elements active, with a pause feature using the Delete key.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Never Let Chat Pause
// @namespace    https://greasyfork.org/en/users/1200587-trilla-g
// @version      5.2
// @description  Automatically clicks elements on Kick.com to keep the chat or other elements active, with a pause feature using the Delete key.
// @author       Trilla_G
// @match        *://*.kick.com/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
    'use strict';

    // Define the selector for the target element
    const targetSelector = '.betterhover\\:hover\\:bg-surface-highest';

    // State to track whether the script is paused
    let scriptPaused = false;

    // Function to click the target element
    function clickTarget() {
        if (scriptPaused) return;

        const target = document.querySelector(targetSelector);
        if (target) {
            target.click();
            console.log('Clicked target:', target);
        }
    }

    // Set up an observer to watch for the target entering the viewport
    const observer = new IntersectionObserver(entries => {
        entries.forEach(entry => {
            if (!scriptPaused && entry.isIntersecting) {
                entry.target.click();
                console.log('Clicked via IntersectionObserver:', entry.target);
            }
        });
    });

    // Function to monitor and observe the target
    function observeTarget() {
        if (scriptPaused) return;

        const target = document.querySelector(targetSelector);
        if (target) {
            // Click immediately when detected
            clickTarget();

            // Observe for future interactions
            observer.observe(target);
        }
    }

    // Set up a MutationObserver to detect changes in the page and find the target
    const mutationObserver = new MutationObserver(() => {
        if (!scriptPaused) observeTarget();
    });
    mutationObserver.observe(document.body, { childList: true, subtree: true });

    // Automatic clicking every 15 seconds as a fallback
    const autoClickInterval = setInterval(() => {
        if (!scriptPaused) {
            clickTarget();
        }
    }, 15000);

    // Pause the script for 15 seconds when the Delete key is pressed
    document.addEventListener('keydown', (event) => {
        if (event.key === 'Delete' && !scriptPaused) {
            console.log('Script paused for 15 seconds.');
            scriptPaused = true;

            // Disconnect observers and pause automatic actions
            observer.disconnect();
            mutationObserver.disconnect();

            // Resume script after 15 seconds
            setTimeout(() => {
                console.log('Script resumed.');
                scriptPaused = false;

                // Reconnect observers
                observeTarget();
                mutationObserver.observe(document.body, { childList: true, subtree: true });
            }, 15000);
        }
    });

    // Initial observation
    observeTarget();
})();