Last active
24 minutes agoAugust 1, 2026 22:11
Disable YouTube Mobile Autoplay (Supports Desktop View)
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 Disable YouTube Mobile Autoplay (Supports Desktop View) | |
| // @namespace http://tampermonkey.net/ | |
| // @version 1.3 | |
| // @description Automatically turn off autoplay on YouTube (PC & Mobile) | |
| // @match https://www.youtube.com/* | |
| // @match https://m.youtube.com/* | |
| // @grant none | |
| // @run-at document-start | |
| // @license MIT | |
| // ==/UserScript== | |
| (() => { | |
| 'use strict'; | |
| const turnOffAutoplay = () => { | |
| // Mobile | |
| const mobileBtn = document.querySelector('.ytwAutonavToggleButtonHost'); | |
| if (mobileBtn && mobileBtn.getAttribute('aria-pressed') === 'true') { | |
| mobileBtn.click(); | |
| } | |
| // PC | |
| const pcBtn = document.querySelector('.ytp-autonav-toggle-button'); | |
| if (pcBtn && pcBtn.getAttribute('aria-checked') === 'true') { | |
| pcBtn.click(); | |
| } | |
| }; | |
| // Run when page is loaded | |
| window.addEventListener('load', turnOffAutoplay); | |
| // Run on SPA navigation events | |
| window.addEventListener('yt-navigate-finish', turnOffAutoplay); | |
| // Debounce to prevent MutationObserver from firing excessively | |
| let debounceTimer; | |
| const observer = new MutationObserver(() => { | |
| clearTimeout(debounceTimer); | |
| debounceTimer = setTimeout(turnOffAutoplay, 500); | |
| }); | |
| // Observe DOM changes (e.g., video replacement) and attribute | |
| // changes (the toggle's real state may be set asynchronously, | |
| // after the button element already exists in the DOM) | |
| observer.observe(document.documentElement, { | |
| childList: true, | |
| subtree: true, | |
| attributes: true, | |
| attributeFilter: ['aria-pressed', 'aria-checked'] | |
| }); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment