Make any Acellus Video Unpaused (Flawed)

Unpauses the video when changing tabs on Acellus ;)

当前为 2024-04-26 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Make any Acellus Video Unpaused (Flawed)
  3. // @namespace https://greasyfork.org/en/users/1291009
  4. // @version 1.6
  5. // @description Unpauses the video when changing tabs on Acellus ;)
  6. // @author BadOrBest
  7. // @license MIT
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=acellus.com
  9. // @match https://admin192c.acellus.com/student/*
  10. // @grant none
  11. // @grant GM_addStyle
  12. // @grant GM_setValue
  13. // @grant GM_getValue
  14. // @grant GM_deleteValue
  15. // @run-at document-end
  16. // ==/UserScript==
  17.  
  18. (function() {
  19. 'use strict';
  20.  
  21. // Toggle for the library
  22. var libraryEnabled = true;
  23.  
  24. // Function to enable or disable the library
  25. function toggleLibrary(enable) {
  26. libraryEnabled = enable;
  27. if (enable) {
  28. // If enabled, load the library
  29. loadLibrary();
  30. } else {
  31. // If disabled, remove the library if it's already loaded
  32. removeLibrary();
  33. }
  34. }
  35.  
  36. // Function to load the library
  37. function loadLibrary() {
  38. var script = document.createElement('script');
  39. script.src = 'https://update.greasyfork.org/scripts/493520/1366528/Mute%20Option.js';
  40. document.head.appendChild(script);
  41. }
  42.  
  43. // Function to remove the library
  44. function removeLibrary() {
  45. var libraryScript = document.querySelector('script[src="https://update.greasyfork.org/scripts/493520/1366528/Mute%20Option.js"]');
  46. if (libraryScript) {
  47. libraryScript.remove();
  48. }
  49. }
  50.  
  51. // Enable the library initially
  52. toggleLibrary(true);
  53.  
  54. // Function to unpause media elements
  55. function unpauseMedia() {
  56. // Select all video, audio, and Plyr elements
  57. var mediaElements = document.querySelectorAll('video, audio, .plyr');
  58.  
  59. // Loop through each media element and unpause it
  60. mediaElements.forEach(function(mediaElement) {
  61. // Check if the media is paused
  62. if (mediaElement.paused) {
  63. // Unpause the media
  64. mediaElement.play();
  65. }
  66. });
  67. }
  68.  
  69. // Function to set aggressive unpause interval
  70. function setUnpauseInterval() {
  71. // Clear any existing interval
  72. clearInterval(window.unpauseInterval);
  73.  
  74. // Set new interval
  75. window.unpauseInterval = setInterval(unpauseMedia, 1000); // Change the interval as needed
  76. }
  77.  
  78. // Set aggressive unpause interval initially
  79. setUnpauseInterval();
  80.  
  81. // Function to mute media elements using the mediaMuter library
  82. function muteMedia() {
  83. if (window.mediaMuter) {
  84. window.mediaMuter.muteMedia();
  85. }
  86. }
  87.  
  88. // Function to unmute media elements using the mediaMuter library
  89. function unmuteMedia() {
  90. if (window.mediaMuter) {
  91. window.mediaMuter.unmuteMedia();
  92. }
  93. }
  94.  
  95. // Event listener for tab visibility change
  96. document.addEventListener('visibilitychange', function() {
  97. if (libraryEnabled) {
  98. if (document.hidden) {
  99. muteMedia();
  100. } else {
  101. unmuteMedia();
  102. setUnpauseInterval();
  103. }
  104. }
  105. });
  106.  
  107. // Function to handle mutations in the DOM
  108. var observer = new MutationObserver(function(mutations) {
  109. mutations.forEach(function(mutation) {
  110. // Check if new nodes were added
  111. if (mutation.type === 'childList') {
  112. // Check each added node
  113. mutation.addedNodes.forEach(function(node) {
  114. // If the added node is a media element, mute it
  115. if (node instanceof HTMLVideoElement || node instanceof HTMLAudioElement) {
  116. node.muted = true;
  117. }
  118. });
  119. }
  120. });
  121. });
  122.  
  123. // Start observing mutations in the document body
  124. observer.observe(document.body, {
  125. childList: true,
  126. subtree: true
  127. });
  128.  
  129. })();
  130.