您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Prevents YouTube from automatically playing the next video in a playlist by using the player's own API.
// ==UserScript== // @name YouTube Playlist Autoplay Stopper // @namespace http://tampermonkey.net/ // @version 1.0.0 // @description Prevents YouTube from automatically playing the next video in a playlist by using the player's own API. // @author Gemini // @match *://www.youtube.com/* // @grant none // @license Apache 2.0 // @run-at document-idle // ==/UserScript== (function() { 'use strict'; let isListenerAttached = false; let player; window.onPlayerStateChangeHook = function(state) { if (state === 0 && window.location.href.includes('list=')) { console.log('Playlist Stopper: Video ended in a playlist. Intervening.'); setTimeout(() => { if (player && typeof player.pauseVideo === 'function') { player.pauseVideo(); } }, 50); } }; function initializePlayerHook() { player = document.getElementById('movie_player'); if (player && typeof player.addEventListener === 'function' && !isListenerAttached) { console.log('Playlist Stopper: Player object found. Attaching API listener.'); player.addEventListener('onStateChange', 'onPlayerStateChangeHook'); isListenerAttached = true; } } const observer = new MutationObserver(() => { if (!document.getElementById('movie_player')?.contains(player)) { isListenerAttached = false; } initializePlayerHook(); }); observer.observe(document.body, { childList: true, subtree: true }); initializePlayerHook(); })();