Loop HTML5 Videos Toggle

Enables loop functionality for HTML5 videos with context menu toggle

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         Loop HTML5 Videos Toggle
// @namespace   StephenP
// @version      1.0
// @description  Enables loop functionality for HTML5 videos with context menu toggle
// @author      StephenP
// @match        *://*/*
// @grant        GM_registerMenuCommand
// @grant        GM_unregisterMenuCommand
// ==/UserScript==

(function() {
    'use strict';
    let isLoopingEnabled = false;
    GM_registerMenuCommand('▶️ Enable Loop',setLooping);
    // Variables to track the state of looping

    const videoElements = document.getElementsByTagName('VIDEO');

    function toggleVideoLoop(video) {
        if (!video.loop) {
            video.loop = true;
            video.removeEventListener('ended',vPause);
            video.addEventListener('ended',vPlay);
        } else {
            video.loop = false;
            video.removeEventListener('ended',vPlay);
            video.addEventListener('ended',vPause);
        }
    }

    // Toggle loop when clicking on videos
    function setLooping(){
      if(!isLoopingEnabled){
        GM_unregisterMenuCommand('▶️ Enable Loop')
        GM_registerMenuCommand('⏹️ Disable Loop',setLooping)
        isLoopingEnabled=true;
      }
      else{
        GM_unregisterMenuCommand('⏹️ Disable Loop')
        GM_registerMenuCommand('▶️ Enable Loop',setLooping)
        isLoopingEnabled=false;
      }
      for(let video of videoElements){
        toggleVideoLoop(video);
      }
    }

    function vPause(e){
      e.target.pause();
    }
    function vPlay(e){
      e.target.play();
    }
})();