Auto Loop and Autoplay for All Video Players

Enables loop and autoplay on all video players online

ของเมื่อวันที่ 11-02-2025 ดู เวอร์ชันล่าสุด

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey, Greasemonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

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         Auto Loop and Autoplay for All Video Players
// @namespace    http://tampermonkey.net/
// @version      1.5
// @description  Enables loop and autoplay on all video players online
// @author       Dj Dragkan
// @match        *://*/*
// @icon         https://upload.wikimedia.org/wikipedia/commons/4/42/YouTube_icon_%282013-2017%29.png
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    function enableLoopAndAutoplay(video) {
        if (video && !video.dataset.loopEnabled) {
            // Enable loop
            video.loop = true;
            video.dataset.loopEnabled = "true";
            console.log("Loop enabled on:", video);
        }

        // Enable autoplay after the first playback finishes
        video.addEventListener('ended', () => {
            video.autoplay = true;
            video.play();
            console.log("Autoplay enabled on:", video);
        });
    }

    function checkVideos() {
        let videos = document.querySelectorAll("video");
        videos.forEach(enableLoopAndAutoplay);
    }

    // Observer to detect new videos on the page
    const observer = new MutationObserver(checkVideos);
    observer.observe(document.body, { childList: true, subtree: true });

    // Enable loop and autoplay on videos already present
    checkVideos();
})();