Make any Acellus Video Unpaused (Flawed)

Unpauses the video when changing tabs on Acellus ;)

目前為 2024-04-26 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Make any Acellus Video Unpaused (Flawed)
// @namespace    https://greasyfork.org/en/users/1291009
// @version      1.6
// @description  Unpauses the video when changing tabs on Acellus ;)
// @author       BadOrBest
// @license      MIT
// @icon         https://www.google.com/s2/favicons?sz=64&domain=acellus.com
// @match        https://admin192c.acellus.com/student/*
// @grant        none
// @grant        GM_addStyle
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_deleteValue
// @run-at       document-end
// ==/UserScript==

(function() {
    'use strict';

    // Toggle for the library
    var libraryEnabled = true;

    // Function to enable or disable the library
    function toggleLibrary(enable) {
        libraryEnabled = enable;
        if (enable) {
            // If enabled, load the library
            loadLibrary();
        } else {
            // If disabled, remove the library if it's already loaded
            removeLibrary();
        }
    }

    // Function to load the library
    function loadLibrary() {
        var script = document.createElement('script');
        script.src = 'https://update.greasyfork.org/scripts/493520/1366528/Mute%20Option.js';
        document.head.appendChild(script);
    }

    // Function to remove the library
    function removeLibrary() {
        var libraryScript = document.querySelector('script[src="https://update.greasyfork.org/scripts/493520/1366528/Mute%20Option.js"]');
        if (libraryScript) {
            libraryScript.remove();
        }
    }

    // Enable the library initially
    toggleLibrary(true);

    // Function to unpause media elements
    function unpauseMedia() {
        // Select all video, audio, and Plyr elements
        var mediaElements = document.querySelectorAll('video, audio, .plyr');

        // Loop through each media element and unpause it
        mediaElements.forEach(function(mediaElement) {
            // Check if the media is paused
            if (mediaElement.paused) {
                // Unpause the media
                mediaElement.play();
            }
        });
    }

    // Function to set aggressive unpause interval
    function setUnpauseInterval() {
        // Clear any existing interval
        clearInterval(window.unpauseInterval);

        // Set new interval
        window.unpauseInterval = setInterval(unpauseMedia, 1000); // Change the interval as needed
    }

    // Set aggressive unpause interval initially
    setUnpauseInterval();

    // Function to mute media elements using the mediaMuter library
    function muteMedia() {
        if (window.mediaMuter) {
            window.mediaMuter.muteMedia();
        }
    }

    // Function to unmute media elements using the mediaMuter library
    function unmuteMedia() {
        if (window.mediaMuter) {
            window.mediaMuter.unmuteMedia();
        }
    }

    // Event listener for tab visibility change
    document.addEventListener('visibilitychange', function() {
        if (libraryEnabled) {
            if (document.hidden) {
                muteMedia();
            } else {
                unmuteMedia();
                setUnpauseInterval();
            }
        }
    });

    // Function to handle mutations in the DOM
    var observer = new MutationObserver(function(mutations) {
        mutations.forEach(function(mutation) {
            // Check if new nodes were added
            if (mutation.type === 'childList') {
                // Check each added node
                mutation.addedNodes.forEach(function(node) {
                    // If the added node is a media element, mute it
                    if (node instanceof HTMLVideoElement || node instanceof HTMLAudioElement) {
                        node.muted = true;
                    }
                });
            }
        });
    });

    // Start observing mutations in the document body
    observer.observe(document.body, {
        childList: true,
        subtree: true
    });

})();