Webm Toggle Loop

Creates a button which toggles looping on or off

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

Bạn sẽ cần cài đặt một tiện ích mở rộng như Tampermonkey hoặc Violentmonkey để cài đặt kịch bản này.

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        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();
})();