Last active
June 4, 2019 06:36
-
-
Save vsubhash/d211ab73ca68b8bf8233fc9198c827d3 to your computer and use it in GitHub Desktop.
AutoPlayVideoAutoStopper - Pauses auto-playing videos. Excludes YouTube (has its own autostopper script com.vsubhash.js.youtube-annoyances-remover); Supports Firefox-based browser up to Version 36. Newer versions should use a UserAgent (UA) spoofer add-on. YouTube loads a lighter version of the YouTube page for older browsers. This script will r…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name AutoPlayVideoAutoStopper | |
// @namespace com.vsubhash.js.autoplay-video-auto-stopper | |
// @description Pauses auto-playing videos. Excludes YouTube (has its own autostopper script com.vsubhash.js.youtube-annoyances-remover); Supports Firefox-based browser up to Version 36. Newer versions should use a UserAgent (UA) spoofer add-on. YouTube loads a lighter version of the YouTube page for older browsers. This script will require the GreaseMonkey add-on to run the script inside a browser. | |
// @exclude https://www.youtube.com/* | |
// @version 2019.02 | |
// @grant none | |
// ==/UserScript== | |
document.addEventListener("readystatechange", handle_DOMLoad, false); | |
function handle_DOMLoad() { | |
console.log("VideoAutoStopper: Readystatechange."); | |
if ((document.readyState == "interactive") || (document.readyState == "complete")) { | |
console.log("VideoAutoStopper: Document iteractive/complete."); | |
window.setTimeout(pauseAllVideos, 1*1000); | |
window.setTimeout(pauseAllVideos, 5*1000); | |
window.setTimeout(pauseAllVideos, 20*1000); | |
window.setTimeout(pauseAllVideos, 30*1000); | |
} | |
} | |
function pauseAllVideos() { | |
console.log("VideoAutoStopper: Parsing video tags..."); | |
try { | |
var arVideos = document.getElementsByTagName("video"); | |
for (var i = 0; i < arVideos.length; i++) { | |
arVideos[i].pause(); | |
console.log("VideoAutoStopper: Paused a video - " + (i+1)); | |
arVideos[i].muted = true; // custom controls may not update | |
arVideos[i].removeAttribute("autoplay"); | |
arVideos[i].removeAttribute("loop"); | |
arVideos[i].setAttribute("preload", "none"); | |
} | |
} catch(e) { | |
console.error("VideoAutoStopper: Error - " + e); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment