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 για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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