HTML5 video controls

show video controls

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         HTML5 video controls
// @namespace    http://tampermonkey.net/
// @version      0.1
// @include      http://*
// @include      https://*
// @grant        none
// @license      MIT
// @description  show video controls 
// ==/UserScript==

(function() {
  'use strict';

  function addVideoControls(videoNode) {
    videoNode.setAttribute("controls", "");
    console.log("*** Enabled HTML 5 video controls for", videoNode);
  }

  for (let el of document.getElementsByTagName("video")) {
    addVideoControls(el);
  }

  const observer = new MutationObserver(mutations => {
    for (let i = 0, mLen = mutations.length; i < mLen; ++i) {
      let mutation = mutations[i];
      if (mutation.type === "childList") {
        for (let j = 0, aLen = mutation.addedNodes.length; j < aLen; ++j) {
          let addedNode = mutation.addedNodes[j];
          if (addedNode.nodeType === 1 && addedNode.tagName === "VIDEO") {
            addVideoControls(addedNode);
          }
        }
      }
    }
  });

  observer.observe(document.body, {childList: true, subtree: true});
})();