SHARE
TWEET

[userscript] HTML5 video controls

a guest Mar 21st, 2018 1,142 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         HTML5 video controls
  3. // @namespace    http://tampermonkey.net/
  4. // @version      0.1
  5. // @include      http://*
  6. // @include      https://*
  7. // @grant        none
  8. // ==/UserScript==
  9.  
  10. (function() {
  11.   'use strict';
  12.  
  13.   function addVideoControls(videoNode) {
  14.     videoNode.setAttribute("controls", "");
  15.     console.log("*** Enabled HTML 5 video controls for", videoNode);
  16.   }
  17.  
  18.   for (let el of document.getElementsByTagName("video")) {
  19.     addVideoControls(el);
  20.   }
  21.  
  22.   const observer = new MutationObserver(mutations => {
  23.     for (let i = 0, mLen = mutations.length; i < mLen; ++i) {
  24.       let mutation = mutations[i];
  25.       if (mutation.type === "childList") {
  26.         for (let j = 0, aLen = mutation.addedNodes.length; j < aLen; ++j) {
  27.           let addedNode = mutation.addedNodes[j];
  28.           if (addedNode.nodeType === 1 && addedNode.tagName === "VIDEO") {
  29.             addVideoControls(addedNode);
  30.           }
  31.         }
  32.       }
  33.     }
  34.   });
  35.  
  36.   observer.observe(document.body, {childList: true, subtree: true});
  37. })();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top