Greasy Fork

Greasy Fork is available in English.

YouTube Playlist AutoPlay

AutoPlay next Playlist item in YouTube

当前为 2023-11-24 提交的版本,查看 最新版本

// ==UserScript==
// @name         YouTube Playlist AutoPlay
// @namespace    https://github.com/crazyrabbit0
// @version      1.0
// @description  AutoPlay next Playlist item in YouTube
// @author       CrazyRabbit
// @homepage     https://github.com/crazyrabbit0/UserScripts/raw/main/YouTube%20Playlist%20AutoPlay.user.js
// @match        https://www.youtube.com/watch?v=*&list=*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    new MutationObserver(mutations => {
        for (const mutation of mutations)
        {
            let has_finished	= mutation.addedNodes.length > 0 && mutation.addedNodes[0].data === document.querySelector('span[class="ytp-time-duration"]').textContent;
			let has_next_item	= document.querySelector('ytd-playlist-panel-video-renderer[selected] + ytd-playlist-panel-video-renderer') !== null;

            if (has_finished && has_next_item)
            {
                document.querySelector('a.ytp-next-button').click();
            }
        }
    }).observe(
        document.querySelector('span[class="ytp-time-current"]'),
        {
			childList: true
		}
    );

})();