Last active
July 15, 2022 22:24
-
-
Save etshy/325d00b7487cae4ad45569f4f6b1bdb8 to your computer and use it in GitHub Desktop.
Twitch pause autoplay video
This file contains hidden or 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 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; | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.