keywordFilter

通过关键字过滤页面内容

Ajankohdalta 11.12.2022. Katso uusin versio.

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.

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

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         keywordFilter
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  通过关键字过滤页面内容
// @author       wasdjkl
// @match        *://*/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
  'use strict';

  const blockWords = ["测试", "当然"]

  function hasKeyword(node) {
    if (node.textContent === null) return true;
    return blockWords.find(keyword => node.textContent.includes(keyword))
  }

  function replaceContent(node) {
    if (!hasKeyword(node)) return;
    if (node.nodeName === "#text") node.remove()
    node.childNodes.forEach(replaceContent);
  }

  replaceContent(document);

  var observer = new MutationObserver(() => {
    replaceContent(document);
  });

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