HTML5 video controls

show video controls

  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. // @license MIT
  9. // @description show video controls
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. function addVideoControls(videoNode) {
  16. videoNode.setAttribute("controls", "");
  17. console.log("*** Enabled HTML 5 video controls for", videoNode);
  18. }
  19.  
  20. for (let el of document.getElementsByTagName("video")) {
  21. addVideoControls(el);
  22. }
  23.  
  24. const observer = new MutationObserver(mutations => {
  25. for (let i = 0, mLen = mutations.length; i < mLen; ++i) {
  26. let mutation = mutations[i];
  27. if (mutation.type === "childList") {
  28. for (let j = 0, aLen = mutation.addedNodes.length; j < aLen; ++j) {
  29. let addedNode = mutation.addedNodes[j];
  30. if (addedNode.nodeType === 1 && addedNode.tagName === "VIDEO") {
  31. addVideoControls(addedNode);
  32. }
  33. }
  34. }
  35. }
  36. });
  37.  
  38. observer.observe(document.body, {childList: true, subtree: true});
  39. })();
  40.