Skip to content

Instantly share code, notes, and snippets.

@michaelskyba
Last active October 21, 2023 01:15
Show Gist options
  • Save michaelskyba/451ce045a34a5657c871494251db295b to your computer and use it in GitHub Desktop.
Save michaelskyba/451ce045a34a5657c871494251db295b to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name YouTube Unpause
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Disable the programmatic pausing of YouTube videos in response to detecting adblock
// @author Michael
// @match https://www.youtube.com/watch?v=*
// @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @grant none
// ==/UserScript==
const inputDelay = 250
let userPaused = false
let video
const userInput = () => {
userPaused = true
setTimeout(() => {
if (video && !video.paused)
userPaused = false
}, inputDelay)
}
document.addEventListener("click", userInput)
document.addEventListener("keydown", userInput)
const setVideo = setInterval(() => {
video = document.getElementsByTagName("video")[0]
if (video) {
clearInterval(setVideo)
video.addEventListener("pause", () => {
if (!userPaused && video.currentTime < video.duration)
video.play()
})
}
}, 10)
@michaelskyba
Copy link
Author

michaelskyba commented Oct 21, 2023

YouTube Unpause

Everyone knows you can hide YouTube's adblock popup using uBlock Origin, but that still requires you to often unpause the video after the hidden popup shows up. This userscript hopefully fixes that, by automatically unpausing the video whenever it gets paused more than inputDelay ms after keyboard input or a mouse click. Occasionally there is some lag when pausing a video, which is why inputDelay isn't something particularly low like 15 ms.

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