Page Filter

Removes links, images, and text which refer to specific keywords. When a keyword is found in an URL of a link or image, the link/image will be removed. When a keyword is found in a text, the whole text in its container element, will be removed.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension 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.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Page Filter
// @namespace    http://tampermonkey.net/
// @version      1.0.1
// @license      GNU AGPLv3
// @description  Removes links, images, and text which refer to specific keywords. When a keyword is found in an URL of a link or image, the link/image will be removed. When a keyword is found in a text, the whole text in its container element, will be removed.
// @author       jcunews
// @match        *://*/*
// @grant        none
// ==/UserScript==

(function() {

  //*** CONFIGURATION BEGIN ***

  //Below regular expression will be compared against URLs and text.
  //Put anything there to remove them from the page.
  var rx = /\b(removeme|deleteme)\b/gi;

  //*** CONFIGURATION END ***

  function processElement(node, url, nextNode, styles) {
    if (rx.test(node.href || node.src) || ((styles = getComputedStyle(node)) && rx.test(styles.backgroundImage))) {
      if (rx.test(node.parentNode.textContent)) {
        node.parentNode.innerHTML = "";
      } else node.remove();
    } else {
      for (node = node.childNodes[0]; node; node = nextNode) {
        nextNode = node.nextSibling;
        processNode(node);
      }
    }
  }

  function processNode(node) {
    switch (node.nodeType) {
      case Node.ELEMENT_NODE:
        processElement(node);
        break;
      case Node.TEXT_NODE:
        if (rx.test(node.nodeValue)) node.nodeValue = "";
        break;
    }
  }

  processNode(document.body);

  (new MutationObserver(function(records) {
    records.forEach(function(record) {
      if (record.type === "characterData") {
        if (rx.test(record.target.nodeValue)) record.target.nodeValue = "";
      } else record.addedNodes.forEach(processNode);
    });
  })).observe(document.body, {childList: true, characterData: true, subtree: true});
})();