Skip to content

Instantly share code, notes, and snippets.

@bhughes339
Last active November 21, 2023 21:40
Show Gist options
  • Save bhughes339/24262ad737d35778db69bf9f778e595e to your computer and use it in GitHub Desktop.
Save bhughes339/24262ad737d35778db69bf9f778e595e to your computer and use it in GitHub Desktop.
Automatically pause Twitch VODs when window not visible
// ==UserScript==
// @name Twitch VOD Autopause
// @namespace http://tampermonkey.net/
// @version 0.2
// @description Automatically pause Twitch VODs when window not visible
// @author bhughes339
// @match https://*.twitch.tv/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=twitch.tv
// ==/UserScript==
var intervalMs = 100;
(function() {
'use strict';
setInterval(function() {
var vid = document.getElementsByTagName("video")[0];
// Pause videos when not in focus
if (document.hidden && document.URL.includes("/videos/")) {
vid.pause();
};
// Pause autoplay bullshit
if (document.URL.match(/videos($|\?)/) || !document.URL.includes("/videos")) {
vid.pause();
vid.muted = false;
};
}, intervalMs);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment