Civitai Auto-Clicker for Buzz and Follow

Automatically clicks "Claim 25 Buzz" once and "Follow" on three different pages per session on Civitai

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Civitai Auto-Clicker for Buzz and Follow
// @namespace    http://tampermonkey.net/
// @version      1.3
// @description  Automatically clicks "Claim 25 Buzz" once and "Follow" on three different pages per session on Civitai
// @author       Your Name
// @match        https://civitai.com/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    const buttonConfig = {
        "Claim 25 Buzz": { limit: 1, clicked: 0 },
        "Follow": { limit: 3, clicked: 0, pages: [] }
    };

    function initializeSession() {
        Object.keys(buttonConfig).forEach(key => {
            const storedValue = sessionStorage.getItem(key);
            if (storedValue === null) {
                sessionStorage.setItem(key, JSON.stringify(buttonConfig[key]));
            } else {
                buttonConfig[key] = JSON.parse(storedValue);
            }
        });
    }

    function updateClickCount(buttonText) {
        buttonConfig[buttonText].clicked++;
        if (buttonText === "Follow") {
            buttonConfig[buttonText].pages.push(window.location.href);
        }
        sessionStorage.setItem(buttonText, JSON.stringify(buttonConfig[buttonText]));
    }

    function findButtonByText(text) {
        return Array.from(document.querySelectorAll('button')).find(
            button => button.textContent.trim() === text
        );
    }

    function clickButton(button, buttonText) {
        if (button && !button.disabled && button.offsetParent !== null) {
            button.click();
            updateClickCount(buttonText);
            console.log(`Clicked button: ${buttonText}. Click count: ${buttonConfig[buttonText].clicked}`);
        }
    }

    function checkAndClickButtons() {
        Object.keys(buttonConfig).forEach(buttonText => {
            if (buttonConfig[buttonText].clicked < buttonConfig[buttonText].limit) {
                if (buttonText === "Follow") {
                    if (!buttonConfig[buttonText].pages.includes(window.location.href)) {
                        const button = findButtonByText(buttonText);
                        if (button) clickButton(button, buttonText);
                    }
                } else {
                    const button = findButtonByText(buttonText);
                    if (button) clickButton(button, buttonText);
                }
            }
        });
    }

    function isScriptFinished() {
        return Object.keys(buttonConfig).every(key =>
            buttonConfig[key].clicked >= buttonConfig[key].limit
        );
    }

    // Initialize session
    initializeSession();

    // Initial check
    checkAndClickButtons();

    // Set up a MutationObserver to watch for DOM changes
    const observer = new MutationObserver((mutations) => {
        if (!isScriptFinished()) {
            checkAndClickButtons();
        } else {
            observer.disconnect();
            console.log("All click limits reached. Script finished.");
        }
    });

    // Start observing the document with the configured parameters
    observer.observe(document.body, {
        childList: true,
        subtree: true,
        attributes: true,
        attributeFilter: ['style', 'class']
    });

    // Also check periodically, just in case
    const intervalId = setInterval(() => {
        if (!isScriptFinished()) {
            checkAndClickButtons();
        } else {
            clearInterval(intervalId);
            console.log("All click limits reached. Script finished.");
        }
    }, 1000);

    // Log to confirm script is running
    console.log("Civitai Auto-Clicker script is active");
    console.log("Current state:", JSON.stringify(buttonConfig));
})();