Twitch Auto Point Collector

Automatically clicks the point claim button on Twitch

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Twitch Auto Point Collector
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Automatically clicks the point claim button on Twitch
// @author       HyakuAr
// @match        https://www.twitch.tv/*
// @license      MIT
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    let hasClicked = false;

    function findAndClickButton() {
        // Find button using multiple language-independent selectors
        let button = null;

        // Method 1: Look for the specific icon structure
        const icons = document.querySelectorAll('.claimable-bonus__icon');
        for (const icon of icons) {
            const btn = icon.closest('button');
            if (btn) {
                button = btn;
                break;
            }
        }

        // Method 2: Look for button with the specific SVG path (gift box icon)
        if (!button) {
            const svgs = document.querySelectorAll('svg path[d*="M13 12h-2v2h2v-2"]');
            for (const svg of svgs) {
                const btn = svg.closest('button');
                if (btn) {
                    button = btn;
                    break;
                }
            }
        }

        if (!button) {
            hasClicked = false;
            return;
        }

        // Check if button is visible
        const isVisible = button.offsetParent !== null;

        if (isVisible && !hasClicked) {
            console.log('Bonus button found');
            hasClicked = true;

            setTimeout(() => {
                button.click();
                console.log('Bonus button clicked');
            }, 1000);
        }
    }

    // Check for the button every 2 seconds
    setInterval(findAndClickButton, 2000);

    // Also observe DOM changes for faster detection
    const observer = new MutationObserver(() => {
        findAndClickButton();
    });

    observer.observe(document.body, {
        childList: true,
        subtree: true
    });

    console.log('Twitch Auto Point Collector activated');
})();