Skip to content

Instantly share code, notes, and snippets.

@lassekongo83
Last active March 1, 2024 05:58
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lassekongo83/bf57cd21b40846ff030eb10c26b45d6b to your computer and use it in GitHub Desktop.
Save lassekongo83/bf57cd21b40846ff030eb10c26b45d6b to your computer and use it in GitHub Desktop.
Stops channels you're not subscribed to from autoplaying the channel trailer
// ==UserScript==
// @name YouTube - Stop Channel Autoplay
// @namespace Violentmonkey Scripts
// @match https://www.youtube.com/*
// @grant none
// @version 1.0
// @author https://github.com/lassekongo83
// @description Stops channels you're not subscribed to from autoplaying the channel trailer
// ==/UserScript==
// https://stackoverflow.com/a/61511955
function waitForElm(selector) {
return new Promise(resolve => {
if (document.querySelector(selector)) {
return resolve(document.querySelector(selector));
}
const observer = new MutationObserver(mutations => {
if (document.querySelector(selector)) {
resolve(document.querySelector(selector));
observer.disconnect();
}
});
observer.observe(document.body, {
childList: true,
subtree: true
});
});
}
function stopChannelAutoplay() {
waitForElm('[role="main"][page-subtype="channels"] ytd-channel-video-player-renderer video').then(function(elm) {
if (elm !== null) {
elm.addEventListener('loadstart', (e) => e.target.pause(), { passive: true });
}
});
}
stopChannelAutoplay();
@Wohn
Copy link

Wohn commented Jan 1, 2022

Awesome, first script i found that actually works!

@Lunatic3k
Copy link

Awesome, first script i found that actually works!

Does it still work? It keeps loading new videos automatically, even though button is there. I'm looking for that feature on subscriptions page and cant find a single thing that works :(

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