u校园ai版挂时长

Close popup, monitor elements, and randomly click elements on page navigation.

目前為 2024-12-30 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         u校园ai版挂时长
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Close popup, monitor elements, and randomly click elements on page navigation.
// @author       HenryW
// @match        https://ucontent.unipus.cn/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Function to close the popup
    function closePopup() {
        const interval = setInterval(() => {
            try {
                const closeButton = document.querySelector(".dialog-header-pc--close-yD7oN");
                if (closeButton) {
                    closeButton.click();
                    console.log("Popup close button clicked.");
                }

                const dialogButton = document.querySelector("div.dialog-header-pc--dialog-header-2qsXD")?.parentElement?.querySelector("button");
                if (dialogButton) {
                    dialogButton.click();
                    console.log("Dialog button clicked.");
                }

                // Check if popup is closed
                if (!document.querySelector(".dialog-header-pc--close-yD7oN") &&
                    !document.querySelector("div.dialog-header-pc--dialog-header-2qsXD")) {
                    clearInterval(interval);
                    console.log("Popup closed successfully.");
                }
            } catch (error) {
                console.error("Error attempting to close popup:", error);
            }
        }, 500); // Check every 500ms
    }

    // Function to monitor and click .ant-btn-primary
    function monitorPrimaryButton() {
        const interval = setInterval(() => {
            try {
                const primaryButton = document.querySelector(".ant-btn-primary");
                if (primaryButton) {
                    primaryButton.click();
                    console.log("Primary button clicked.");
                    clearInterval(interval);
                }
            } catch (error) {
                console.error("Error attempting to click primary button:", error);
            }
        }, 500); // Check every 500ms
    }

    // Function to randomly click elements
    function randomClick() {
        const elements = Array.from(document.querySelectorAll(".pc-menu-node-name"));
        if (elements.length > 32) {
            const first32 = elements.slice(0, 32);
            const randomIndex = Math.floor(Math.random() * first32.length);
            first32[randomIndex].click();
            console.log(`Clicked element at index ${randomIndex}`);
        } else {
            console.warn("Less than 32 elements found.");
        }
    }

    // Function to start the random click loop
    function startRandomClickLoop() {
        const randomInterval = Math.floor(Math.random() * (4 * 60 * 1000 - 1 * 60 * 1000) + 1 * 60 * 1000); // 1-4 minutes in ms
        console.log(`Next click in ${randomInterval / 1000} seconds.`);

        setTimeout(() => {
            randomClick();
            startRandomClickLoop(); // Restart the loop
        }, randomInterval);
    }

    // Observe URL changes
    let lastUrl = location.href;
    const observer = new MutationObserver(() => {
        if (location.href !== lastUrl) {
            console.log("URL changed to", location.href);
            lastUrl = location.href;

            closePopup();
            monitorPrimaryButton();
            startRandomClickLoop();
        }
    });

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