Twitter Politics/Keyword Hider

Self censorship and removing news on twitter. Removes the explore buttons, trending side bar, and filters certain words.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Twitter Politics/Keyword Hider
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  Self censorship and removing news on twitter. Removes the explore buttons, trending side bar, and filters certain words.
// @author       me lol
// @match        https://twitter.com/*
// @grant        none
// @run-at document-end
// ==/UserScript==

(function() {
    'use strict';

    //CONFIGURE
    const filterWords =[
      "word1",
      "word2",
      "word3",
    ];
    const filterWordReplacement = "";
    //END CONFIGURE



    const filterRegex = new RegExp(new RegExp(filterWords.reduce((result, fw) => (result + "|" + fw ))), 'i');

    const targetNode = document.querySelector("[id='react-root']");
    const observer = new MutationObserver(function(mutations) {
          mutations.forEach(function(mutation) {

              //Remove Trending
              mutation.target.querySelectorAll('[aria-label="Timeline: Trending now"]').forEach(e => e.parentNode.removeChild(e));
              //Remove Explore
              mutation.target.querySelectorAll('[href="/explore"]').forEach(e => e.parentNode.removeChild(e));
              //Only remove tweets in which the content of the tweet contains a filteredword, not the username. If the username contains a filtered word, replace it.
              mutation.target.querySelectorAll('[role="article"]').forEach(e => {
                //
              const listoftweetlinks = e.querySelectorAll("a");
                  if(listoftweetlinks[1].innerHTML.match(filterRegex)){
                     listoftweetlinks[1].innerHTML = listoftweetlinks[1].innerHTML.replace(filterRegex, filterWordReplacement);
                  }



                if(e.innerText.match(filterRegex)){
                    e.parentNode.remove()
                }

            });
          });
        });
const observerOptions = {
  childList: true,
  attributes: true,
  subtree: true //Omit or set to false to observe only changes to the parent node.
}
observer.observe(targetNode, observerOptions);
})();