Filter Out Rotten Tomatoes

Removes links, images, and text which refer to Rotten Tomatoes or its rottentomatoes.com website, on any website.

当前为 2018-09-14 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Filter Out Rotten Tomatoes
// @namespace    http://tampermonkey.net/
// @version      1.1.3
// @description  Removes links, images, and text which refer to Rotten Tomatoes or its rottentomatoes.com website, on any website.
// @author       jcunews
// @match        *://*/*
// @grant        none
// ==/UserScript==

(function() {
  var
    rxText   = /rotten\W?tomatoes|(?:https?:\/\/)?(?:[a-z][a-z0-9-]*?\.)?rottentomatoes\.com[^,. ]+/gi,
    rxPercent= /\d+(?:\.\d+)?%/gi,
    rxDomain = /(?:[a-z][a-z0-9-]*?\.)?rottentomatoes\.com/i;

  function processElement(node, url, nextNode) {
    if (rxDomain.test(node.href) || rxDomain.test(node.src) || rxText.test(getComputedStyle(node).backgroundImage)) {
      if (rxPercent.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 (rxText.test(node.nodeValue) && rxPercent.test(node.parentNode.textContent)) {
          node.parentNode.innerHTML = "";
        } else node.nodeValue = node.nodeValue.replace(rxText, "");
        break;
    }
  }

  processNode(document.body);

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