Disable YouTube autoplaying everywhere.

May 8, 2026 ยท View on GitHub

// ==UserScript== // @name YouTube Disable Autoplaying // @version 1.1.2 // @description Disable YouTube autoplaying everywhere. // @author Lumynous // @license MIT // @match https://www.youtube.com/* // @noframes // @downloadURL https://gist.github.com/lumynou5/b036f405a0888bf9c3b9a3f560e36f3d/raw/youtube-disable-autoplaying.user.js // @updateURL https://gist.github.com/lumynou5/b036f405a0888bf9c3b9a3f560e36f3d/raw/~meta // ==/UserScript==

"use strict";

const querySelectorAsync = (function () { const callbacks = new Set(); const observer = new MutationObserver((mutations) => { for (const mutation of mutations) { for (const node of mutation.addedNodes) { if (node.nodeType !== Node.ELEMENT_NODE) continue; for (const {selector, callback, self} of callbacks) { if (!node.matches(selector)) continue; callback(node); callbacks.delete(self); } if (!callbacks.size) { observer.disconnect(); return; } } } });

return function (selector) {
	return new Promise((resolve) => {
		const elm = document.querySelector(selector);
		if (elm) {
			resolve(elm);
			return;
		}
		if (!callbacks.size)
			observer.observe(document, {childList: true, subtree: true});
		callbacks.add({
			selector,
			callback: resolve,
			get self() { return this; },
		});
	});
};

})();

const button = document.createElement("button"); button.classList.add("ytp-button"); button.style.width = "40px"; button.style.height = "100%"; const container = document.createElement("div"); container.classList.add("ytp-autonav-toggle-button-container"); const inner = document.createElement("div"); inner.classList.add("ytp-autonav-toggle-button"); inner.style.margin = "0 auto"; button.appendChild(container).appendChild(inner);

const manager = document.querySelector("yt-playlist-manager"); let state = false; function setState(newState) { state = newState; manager.set("canAutoAdvance_", state); inner.setAttribute("aria-checked", state.toString()); }; button.addEventListener("click", () => setState(!state));

document.addEventListener("yt-page-data-updated", (ev) => { // For miniplayer, the URL doesn't reflect it's a playlist. setState(state); if (ev.detail.pageType === "watch" && location.search.match(/?(?:.&)?list=./)) { document.querySelector("#playlist-actions #end-actions #flexible-item-buttons") .replaceChildren(button); } else if (ev.detail.pageType === "channel" && location.pathname.match(/^/[^/]+(?:/featured)?$/)) { document.querySelector("ytd-channel-video-player-renderer") ?.player .addEventListener("play", function callback(ev) { ev.currentTarget.pause(); ev.currentTarget.removeEventListener("play", callback, true); }, true); } });

document.addEventListener("yt-popup-opened", (ev) => { if (ev.target.is !== "ytd-sponsorships-offer-renderer") return; ev.target.playerElement.pause(); });

// Prevent home page videos from autoplaying. const preview = await querySelectorAsync("#video-preview"); preview.remove();

// The shorts player is lazily created until watching a shorts. const shorts = await querySelectorAsync("#shorts-player video"); const shortsObserver = new MutationObserver((mutations) => { for (const mutation of mutations) { if (mutation.removedNodes.length) continue; mutation.target.loop = false; } }); shortsObserver.observe(shorts, {attributes: true});