Skip to content

Instantly share code, notes, and snippets.

@etshy
Last active July 15, 2022 22:24
Show Gist options
  • Save etshy/325d00b7487cae4ad45569f4f6b1bdb8 to your computer and use it in GitHub Desktop.
Save etshy/325d00b7487cae4ad45569f4f6b1bdb8 to your computer and use it in GitHub Desktop.
Twitch pause autoplay video
// ==UserScript==
// @name Twitch pause autoplay
// @namespace https://github.com/etshy
// @icon https://www.twitch.tv/favicon.ico
// @version 1.0.5
// @description Pause stream/video in the channel and video-list page
// @author Etshy
// @exclude https://www.twitch.tv/videos/*
// @match https://www.twitch.tv/*
// @downloadURL https://gist.github.com/etshy/325d00b7487cae4ad45569f4f6b1bdb8/raw/aca59a29f54623c01e6ff2f3e50977cd218daaa4/twitch-pause-video.user.js
// @updateURL https://gist.github.com/etshy/325d00b7487cae4ad45569f4f6b1bdb8/raw/aca59a29f54623c01e6ff2f3e50977cd218daaa4/twitch-pause-video.user.js
// @supportURL https://gist.github.com/etshy/325d00b7487cae4ad45569f4f6b1bdb8
// @grant none
// @license MIT
// ==/UserScript==
/* jshint esversion:6 */
window.onload = function() {
let active = 1;
let interval = setInterval(function(){
if (active === 0) {
return;
}
let liveVideo = document.querySelector('.channel-root--live')
let liveVideoHome = document.querySelector('.channel-root--home')
if (liveVideo && (!liveVideoHome || liveVideoHome === null)) {
//we are on live page video
let videoPlayer = document.querySelector('video')
if (videoPlayer.paused) {
videoPlayer.play()
active = 0;
}
return;
}
if (!window.location.href.startsWith('https://www.twitch.tv/videos/') || (liveVideoHome && liveVideoHome !== null)) {
let videoPlayer = document.querySelector('video')
if (videoPlayer.paused === false) {
videoUrlLoaded = videoPlayer.src
videoPlayer.pause();
//active = 0;
}
}
if (window.location.href.startsWith('https://www.twitch.tv/videos/')) {
let videoPlayer = document.querySelector('video')
if (videoPlayer.paused) {
videoPlayer.play()
active = 0;
}
}
}, 100);
window.addEventListener('popstate', function (event) {
active = 1;
});
};
@vycktor06
Copy link

Couldn't watch clips sometimes, it just auto paused and wouldn't let me play. It happened randomly though, couldn't tell in what conditions.
Had to add https://www.twitch.tv/*/clip/* (and https://clips.twitch.tv/* as well, just to be sure) in exclusions, now everything seems to be working fine.

Thanks for the script.

@etshy
Copy link
Author

etshy commented Jul 15, 2022

Well I didn't thought about clips when I made this script.
I was just pissed about the player at top of videos page autoplaying when I scrolled XX pages to search for a video.
btw even with this script the player is still playing, randomly, so I'll have to take a look a this script again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment