Autoplayer

Autoplayer for https://iwatchsouthparkonline.cc

As of 2025-08-17. See the latest version.

// ==UserScript==
// @name            Autoplayer
// @namespace       https://github.com/Bjufen
// @version         0.3
// @description     Autoplayer for https://iwatchsouthparkonline.cc
// @match           *://*.iwatchsouthparkonline.cc/*
// @match           *://vidmoly.net/*
// @match           *://*.vidmoly.net/*
// @grant           GM_registerMenuCommand
// @grant           GM_unregisterMenuCommand
// @grant           GM_setValue
// @grant           GM_getValue
// @license         MIT
// ==/UserScript==

(function() {
    'use strict';

    // This function will try to find the video player.
    // We use setInterval to repeatedly check until the player is loaded.
    const STORAGE_KEY_RANDOM  = 'isRandomEnabled';
    const STORAGE_KEY_AUTOPLAY  = 'isAutoPlayEnabled';

    let isRandomEnabled = GM_getValue(STORAGE_KEY_RANDOM, false);
    let isAutoPlayEnabled = GM_getValue(STORAGE_KEY_AUTOPLAY, true);

    const updateMenuCommand = () => {
        const commandLabelRandom = isRandomEnabled ? 'Random Episode' : 'Next Episode';
        const commandLabelAutoPlay = isAutoPlayEnabled ? '✅ Autoplay Enabled' : '❌ Autoplay Disabled';
        GM_registerMenuCommand(commandLabelRandom, toggleRandomState);
        GM_registerMenuCommand(commandLabelAutoPlay, toggleAutoPlayState);
    }

    const toggleRandomState = () => {
        isRandomEnabled = !isRandomEnabled;
        GM_setValue(STORAGE_KEY_RANDOM, isRandomEnabled)
        updateMenuCommand();
    };

    const toggleAutoPlayState = () => {
        isAutoPlayEnabled = !isAutoPlayEnabled;
        GM_setValue(STORAGE_KEY_AUTOPLAY, isAutoPlayEnabled);
        updateMenuCommand();
    };

    updateMenuCommand();

    let findVideoInterval = setInterval(() => {
        // --- 1. FIND THE VIDEO ELEMENT ---
        // The selector is correct for the JW Player.
        const videoPlayer = document.querySelector('video.jw-video');

        // If the player is found, we can set it up.
        if (videoPlayer) {
            // Stop checking for the video player once we've found it.
            console.log('Autoplayer: Video player found!', videoPlayer);
            setupVideoPlayer(videoPlayer);
            clearInterval(findVideoInterval);
            findVideoInterval = null;
        } else {
            console.log('Autoplayer: Searching for video player...');
        }
    }, 1000);

    function setupVideoPlayer(videoPlayer) {
        videoPlayer.addEventListener('ended', () => {
            console.log('Autoplayer: Video has finished playing!');
            alert('The video has ended!');
        });
    }
})();