YouTube Autoplay Off

Automatically disables autoplay on YouTube videos for a better viewing experience.

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         YouTube Autoplay Off
// @name:tr      YouTube Otomatik Oynatma Kapat
// @version      1.6
// @author       Alyssa B. Morton
// @license      MIT
// @icon         https://www.youtube.com/favicon.ico
// @namespace    https://violentmonkey.github.io/
// @match        *://www.youtube.com/*
// @grant        none
// @description  Automatically disables autoplay on YouTube videos for a better viewing experience.
// @description:tr  YouTube videolarında otomatik oynatmayı devre dışı bırakır ve daha iyi bir izleme deneyimi sunar.
// ==/UserScript==

(function() {
    'use strict';

    // Function to turn off autoplay
    function turnOffAutoplay() {
        const autoplayButton = document.querySelector('.ytp-autonav-toggle-button[aria-checked="true"]');
        if (autoplayButton) {
            autoplayButton.click(); // Turn off autoplay
        }
    }

    // Function to check if autoplay is on and turn it off
    function checkAutoplay() {
        const autoplayButton = document.querySelector('.ytp-autonav-toggle-button');
        if (autoplayButton && autoplayButton.getAttribute('aria-checked') === 'true') {
            turnOffAutoplay(); // Turn off autoplay if it is on
        }
    }

    // Function to observe changes in the DOM
    function observeDOMChanges() {
        const observer = new MutationObserver(() => {
            checkAutoplay(); // Check if autoplay is on
        });

        // Start observing the body for child list changes
        observer.observe(document.body, { childList: true, subtree: true });
    }

    // Wait for the YouTube page to load
    window.addEventListener('load', () => {
        // Wait for an additional 60 seconds before turning off autoplay
        setTimeout(() => {
            turnOffAutoplay(); // Turn off autoplay after 60 seconds
            observeDOMChanges(); // Start observing for changes
        }, 60000); // 60000 milliseconds = 60 seconds
    });

    // Listen for the 'play' event on the video element
    document.addEventListener('play', (event) => {
        if (event.target.tagName === 'VIDEO') {
            checkAutoplay(); // Check if autoplay is on when a video starts playing
        }
    }, true);
})();