Webm Toggle Loop

Creates a button which toggles looping on or off

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name        Webm Toggle Loop
// @namespace   com.jeddunk.webmtoggleloop
// @author      Jeddunk
// @description Creates a button which toggles looping on or off
// @match       *://*/*.webm*
// @match       *://*/*.mp4*
// @run-at      document-start
// @version     1.0.2.1
// @grant       none
// @locale      english
// ==/UserScript==
(function () {
  var toggleValue = 'ON';
  var vids = document.getElementsByTagName('video');
  for (i = 0; i < vids.length; i++) vids[i].setAttribute('style','z-index: 9999');
  if (document.body.children.length != 1) return;
  var q = document.body.children[0];
  if (q.tagName != 'VIDEO') return;
  var o = q.cloneNode();
  var vidCont = document.createElement('div');
  vidCont.className = 'btnContainer';
  q.parentNode.appendChild(vidCont);
  var bt = document.createElement('input');
  bt.className = 'btnToggle';
  bt.type = 'button';
  bt.value = 'TOGGLE';
  bt.style.width = '100px';
  bt.addEventListener('click', function (e) {
    if (toggleValue == 'ON') {
      loopOff();
    } else {
      loopOn();
    }
  }, true);
  vidCont.appendChild(bt);
  function loopOn() {
    for (i = 0; i < vids.length; i++) {
      vids[i].setAttribute('loop', '');
      vids[i].play();
    }
    toggleValue = 'ON';
    bt.value = 'LOOP: ' + toggleValue;
  }
  function loopOff() {
    for (i = 0; i < vids.length; i++) vids[i].removeAttribute('loop');
    toggleValue = 'OFF';
    bt.value = 'LOOP: ' + toggleValue;
  }
  loopOff();
})();