YouTube Exit Fullscreen on Video End

Exit YouTube fullscreen when a video finishes playing (disabled for playlists)

Verze ze dne 27. 11. 2021. Zobrazit nejnovější verzi.

// ==UserScript==
// @name         YouTube Exit Fullscreen on Video End
// @namespace    https://www.youtube.com/
// @version      1.0
// @description  Exit YouTube fullscreen when a video finishes playing (disabled for playlists)
// @author       xdpirate
// @include      /^https?://www\.youtube\.com/watch*/
// @exclude      /^https?://www\.youtube\.com/watch.*list=.*/
// @icon         https://www.google.com/s2/favicons?domain=youtube.com
// @grant        none
// ==/UserScript==

window.setTimeout(function() {
    var e = document.getElementById('movie_player')
    var observer = new MutationObserver(function(event) {
        if(e.classList.contains("ended-mode")) {
            console.log("Video ended!");

            if(document.fullscreenElement) {
                document.exitFullscreen();
            }

            observer.disconnect();
        }
    });

    observer.observe(e, {
        attributes: true,
        attributeFilter: ['class'],
        childList: false,
        characterData: false
    })
}, 3000);