Unpauses the video when changing tabs on Acellus ;)
当前为
// ==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
});
})();