Nedo Auto Contest Participation Script

Автоматом заходит в тему с розырышем и пролистывает до кнопки участия, после принятия участия выходит с темы и заходит в следуюущую.

目前为 2024-10-31 提交的版本。查看 最新版本

// ==UserScript==
// @name         Nedo Auto Contest Participation Script
// @namespace    http://tampermonkey.net/
// @version      1.3
// @description  Автоматом заходит в тему с розырышем и пролистывает до кнопки участия, после принятия участия выходит с темы и заходит в следуюущую.
// @author       eretly
// @match        https://lolz.live/threads/*
// @match        https://lolz.live/forums/contests/
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    const CONTEST_LIST_URL = 'https://lolz.live/forums/contests/';
    const CHECK_INTERVAL = 200; // ms
    const PARTICIPATION_WAIT = 3000; // ms, wait 3 seconds before checking for button hidden state

    function scrollToElement() {
        const xpath = "/html/body/div[4]/div/div/div/form/ol/li/div[2]/div[3]/article/div";
        const element = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;

        if (element) {
            const elementPosition = element.getBoundingClientRect().top + window.pageYOffset;
            window.scrollTo({
                top: elementPosition,
                behavior: 'smooth'
            });
        }
    }

    function clickFirstContestLink() {
        const selector = ".discussionListItem a.listBlock.main.PreviewTooltip";
        const link = document.querySelector(selector);
        if (link) {
            link.click();
        }
    }

    function checkParticipationComplete() {
        const participateButton = document.querySelector('a.LztContest--Participate.button.hidden');
        if (participateButton) {
            console.log('Participation complete, returning to contest list');
            setTimeout(() => {
                window.location.href = CONTEST_LIST_URL;
            }, 100);
            return true;
        }
        return false;
    }

    function clickParticipateButton() {
        const participateButton = document.querySelector('a.LztContest--Participate.button:not(.hidden):not(.disabled)');
        if (participateButton) {
            participateButton.click();
            console.log('Clicked participate button');
        } else {
            console.log('Participate button not found, hidden, or disabled');
        }
    }

    function init() {
        const currentURL = window.location.href;

        if (currentURL.includes('/threads/')) {
            console.log('On contest page, waiting before checking participation...');
            scrollToElement();

            setTimeout(clickParticipateButton, 100);

            // Wait for PARTICIPATION_WAIT
            setTimeout(() => {
                const interval = setInterval(() => {
                    if (checkParticipationComplete()) {
                        clearInterval(interval);
                    }
                }, CHECK_INTERVAL);
            }, PARTICIPATION_WAIT);
        } else if (currentURL === CONTEST_LIST_URL) {
            console.log('On contest list page, preparing to click first contest...');
            setTimeout(() => {
                clickFirstContestLink();
            }, 100);
        }
    }

    init();
})();

QingJ © 2025

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