Rule34Video Auto-Player Ultimate

Auto-advance videos with full state control

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

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

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

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

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

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

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

Advertisement:

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

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

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

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

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

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

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

Advertisement:

// ==UserScript==
// @name         Rule34Video Auto-Player Ultimate
// @namespace    http://tampermonkey.net/
// @version      1.4
// @description  Auto-advance videos with full state control
// @author       YourName
// @match        https://rule34video.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    let isProcessing = false;
    let checkInterval;
    const config = {
        checkInterval: 100,     // Progress check frequency
        nextDelay: 1000,         // Delay before next click
        actionDelay: 2000,       // Post-navigation wait
        playDelay: 250,          // Play->fullscreen delay
        retryInterval: 250,      // State check interval
        maxRetries: 4096            // Max retry attempts per state
    };

    function parseTime(timeStr) {
        const [mins, secs] = timeStr.split(':').map(Number);
        return mins * 60 + secs;
    }

    function enforcePlayerState() {
        let retries = 0;
        const stateChecker = setInterval(() => {
            const player = document.getElementById('kt_player');
            const playButton = document.querySelector('.fp-play');
            const fsButton = document.querySelector('.fp-screen');

            if (!player) {
                clearInterval(stateChecker);
                return;
            }

            // Check and enforce playing state
            if (!player.classList.contains('is-playing') && playButton) {
                playButton.click();
            }

            // Check and enforce fullscreen state
            if (!player.classList.contains('is-fullscreen') && fsButton) {
                fsButton.click();
            }

            // Stop checking when both states are present or max retries reached
            if ((player.classList.contains('is-playing') &&
                 player.classList.contains('is-fullscreen')) ||
                retries >= config.maxRetries) {
                clearInterval(stateChecker);
            }

            retries++;
        }, config.retryInterval);
    }

    function performPlayActions() {
        const playButton = document.querySelector('.fp-play');
        if (playButton) {
            playButton.click();

            setTimeout(() => {
                const fsButton = document.querySelector('.fp-screen');
                if (fsButton) {
                    fsButton.click();
                    enforcePlayerState();
                }
            }, config.playDelay);
        }
    }

    function triggerNextSequence() {
        if (isProcessing) return;
        isProcessing = true;

        setTimeout(() => {
            const nextBtn = document.querySelector('a.link-video.next.js-url-next');
            if (nextBtn) {
                nextBtn.click();

                setTimeout(() => {
                    performPlayActions();
                    isProcessing = false;
                }, config.actionDelay);
            }
        }, config.nextDelay);
    }

    function checkPlaybackProgress() {
        const elapsedElem = document.querySelector('.fp-time-elapsed');
        const durationElem = document.querySelector('.fp-time-duration');

        if (!elapsedElem || !durationElem) return;

        const elapsed = parseTime(elapsedElem.textContent);
        const duration = parseTime(durationElem.textContent);

        if (duration > 0 && elapsed >= duration - 1) {
            clearInterval(checkInterval);
            triggerNextSequence();
        }
    }

    function init() {
        clearInterval(checkInterval);
        checkInterval = setInterval(checkPlaybackProgress, config.checkInterval);
    }

    // Initial setup
    init();

    // Handle SPA navigation
    new MutationObserver((mutations) => {
        if (document.querySelector('.fp-time-duration')) {
            init();
        }
    }).observe(document.body, {
        childList: true,
        subtree: true
    });
})();