Acellus Auto 1.5x Speed Increase

Automatically speed up the video to 1.5x for a more comfortable experience!

// ==UserScript==
// @name         Acellus Auto 1.5x Speed Increase
// @namespace    https://greasyfork.org/en/users/1291009
// @version      1.1
// @description  Automatically speed up the video to 1.5x for a more comfortable experience!
// @match        https://admin192c.acellus.com/student/*
// @grant        GM_addStyle
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_deleteValue
// @license      MIT
// @icon         https://www.google.com/s2/favicons?sz=64&domain=acellus.com
// @author       BadOrBest
// @run-at       document-end
// ==/UserScript==

(function() {
    'use strict';

    // Define the default playback speed
    const defaultSpeed = 1.5;

    // Define the minimum and maximum allowed speeds
    const minSpeed = 0.5;
    const maxSpeed = 2.0;

    // Function to set the playback speed
    function setSpeed(speed) {
        if (speed >= minSpeed && speed <= maxSpeed) {
            const videoContainers = document.querySelectorAll('video, [class*="plyr"], [class*="media"]');
            videoContainers.forEach(container => {
                if (container.tagName.toLowerCase() === 'video') {
                    container.playbackRate = speed;
                } else {
                    const video = container.querySelector('video');
                    if (video) {
                        video.playbackRate = speed;
                    }
                }
            });
            console.log(`Playback speed set to ${speed}x`);
        } else {
            console.error(`Playback speed should be between ${minSpeed}x and ${maxSpeed}x`);
        }
    }

    // Function to continuously monitor and adjust playback speed with some randomness
    function monitorSpeed() {
        const interval = 1000 + Math.floor(Math.random() * 1000); // Random interval between 1 and 2 seconds
        setInterval(function() {
            setSpeed(defaultSpeed);
        }, interval);
    }

    // Function to check for URL changes and restart the script
    function checkURLChange() {
        var currentURL = window.location.href;

        if (checkURLChange.lastURL !== currentURL) {
            // Restart the script if the URL has changed
            clearInterval(monitorInterval);
            monitorSpeed();
            // Update the lastURL variable to the current URL
            checkURLChange.lastURL = currentURL;
        }

        // Check again after a short delay
        setTimeout(checkURLChange, 1000); // Check every second
    }

    // Initialize the lastURL variable with the current URL
    checkURLChange.lastURL = window.location.href;

    // Start checking for URL changes
    checkURLChange();

    // Check for the presence of media player
    function waitForMediaPlayer() {
        const videoContainers = document.querySelectorAll('video, [class*="plyr"], [class*="media"]');
        if (videoContainers.length === 0) {
            setTimeout(waitForMediaPlayer, 1000); // Check again after 1 second
        } else {
            // Start monitoring playback speed
            monitorSpeed();
        }
    }

    // Start waiting for media player
    waitForMediaPlayer();

})();