YouTube Exit Fullscreen on Video End

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

As of 27.11.2021. See ბოლო ვერსია.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==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);