Remove HTML5 Audio/Video and Flash

Remove HTML5 Video (and optionally Audio too) and Flash from any web page. This is somewhat an aggresive measure to disable audio, video and Flash when there's no other option is available.

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

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

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name        Remove HTML5 Audio/Video and Flash
// @namespace   https://greasyfork.org/en/users/85671-jcunews
// @description Remove HTML5 Video (and optionally Audio too) and Flash from any web page. This is somewhat an aggresive measure to disable audio, video and Flash when there's no other option is available.
// @version     1.0.1
// @license     AGPL v3
// @author      jcunews
// @include     *://*/*
// @grant       none
// @run-at      document-start
// ==/UserScript==

(function(tagNamesArray, tagNamesStr, rx, observer) {

  //===== CONFIGURATION BEGIN =====

  //if removeAudio is enabled, HTML5 Audio is removed also.
  var removeAudio = true;
  //if tryToRemoveContainer is enabled, any relevant container elements are removed also.
  var tryToRemoveContainer = true;

  //===== CONFIGURATION BEGIN =====

  tagNamesArray = ["EMBED", "IFRAME", "VIDEO"];
  rx = /embed|flash|player|media|video/i;
  if (removeAudio) {
    tagNamesArray.push("AUDIO");
    rx.source += "|audio";
  }
  tagNamesStr = tagNamesArray.join(",");

  function removeContainer(ele, last) {
    last = ele;
    while (ele.parentNode) {
      ele = ele.parentNode;
      if (rx.test(ele.id) || rx.test(ele.className)) last = ele;
    }
    if (last) last.remove();
  }

  function removeEle(ele) {
    if (tryToRemoveContainer) {
      removeContainer(ele);
    } else ele.remove();
  }

  function processNode(node) {
    if ((tagNamesArray.indexOf(node.tagName) >= 0) && (node.tagName !== "IFRAME")) {
      removeEle(node);
    } else if ((node.tagName === "IFRAME") && (rx.test(node.id) || rx.test(node.className))) {
      removeEle(node);
    } else if (node.tagName === "IFRAME") {
      if (node.parentNode && (rx.test(node.parentNode.id) || rx.test(node.parentNode.className))) {
        removeEle(node.parentNode);
      } else if (node.parentNode.parentNode && (rx.test(node.parentNode.parentNode.id) || rx.test(node.parentNode.parentNode.className))) {
        removeEle(node.parentNode.parentNode);
      }
    } else {
      node.querySelectorAll(tagNamesStr).forEach(function(ele) {
        removeEle(ele);
      });
    }
  }

  function processPage() {
    document.body.querySelectorAll(tagNamesStr).forEach(function(ele) {
      processNode(ele);
    });
  }

  observer = new MutationObserver(function(records) {
    records.forEach(function(record) {
      Array.prototype.slice.call(record.addedNodes).forEach(function(node) {
        if (node.nodeType === 1) processNode(node);
      });
    });
  });

  addEventListener("spfprocess", processPage);
  addEventListener("spfdone", processPage);
  addEventListener("DOMContentLoaded", function() {
    processPage();
    observer.observe(document.body, {
      childList: true,
      subtree: true
    });
  });
  addEventListener("load", processPage);
})();