Skip to content

Instantly share code, notes, and snippets.

@lassekongo83
Last active October 31, 2024 10:30
Show Gist options
  • 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();
@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 :(

@nathan60107
Copy link

It works. Thank you.

@I-Jalal
Copy link

I-Jalal commented Oct 31, 2024

Not Working anymore on chrome, installed it with tampermonkey

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