YouTube Auto Loop

Force loop YouTube videos

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 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.

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

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 Auto Loop
// @version      1.0
// @description  Force loop YouTube videos
// @match        https://m.youtube.com/watch*
// @grant        none
// @license     MIT
// @namespace https://greasyfork.org/users/1443366
// ==/UserScript==

(function() {
    'use strict';

    const loopVideo = () => {
        const video = document.querySelector('video');
        if (video && !video.loop) {
            video.loop = true;
        }
    };

    const observer = new MutationObserver(loopVideo);
    observer.observe(document.body, { childList: true, subtree: true });

    loopVideo();
})();