Twitter Bait Filter

Blocks bait threads on Twitter/X using Unicode, media, and keyword heuristics. Replaces with placeholder.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Twitter Bait Filter
// @namespace    https://github.com/zolu647/twitter-bait-filter
// @version      2.1
// @description  Blocks bait threads on Twitter/X using Unicode, media, and keyword heuristics. Replaces with placeholder.
// @author       zolu647
// @license      MIT
// @match        https://twitter.com/*
// @match        https://x.com/*
// @grant        none
// ==/UserScript==

(function () {
  'use strict';

  const BAIT_KEYWORDS = [
    'game of thrones',
    'hot scenes',
    'nsfw',
    'nude',
    'best scenes',
    'sexiest',
    'onlyfans',
    'follow and make my day',
    'say hi',
    'my birthday',
    "i'm ugly",
    'nobody notices',
    "maybe it's because",
    'make my day',
    'fuck it',
    'porn thread',
    'porn',
    'p*rn',
    'booty thread',
  ];

  const WHITELIST_KEYWORDS = [
    'soccer',
    'football',
    'messi',
    'ronaldo',
    'arsenal',
    'man united',
    'premier league',
    'goal',
    'chelsea',
  ];

  const EMOJI_REGEX = /[\u231A-\uD83E\uDDFF]/g;
  const THREAD_REGEX = /\bthread\b/i;

  const normalizeText = (input) =>
    input
      .normalize('NFKD')
      .replace(/[\u0300-\u036f]/g, '') // remove accents
      .replace(/[^\x00-\x7F]/g, '') // remove other Unicode
      .toLowerCase();

  const isTweetBait = (rawText, tweet) => {
    const text = normalizeText(rawText);
    const hasMedia = tweet.querySelector('img, video') !== null;
    const hasThread = THREAD_REGEX.test(text);
    const hasBaitText = BAIT_KEYWORDS.some((k) => text.includes(k));
    const isWhitelisted = WHITELIST_KEYWORDS.some((k) => text.includes(k));
    const emojiCount = (text.match(EMOJI_REGEX) || []).length;
    const hasTooManyEmojis = emojiCount >= 5;

    return (
      hasThread &&
      hasMedia &&
      (hasBaitText || hasTooManyEmojis || !isWhitelisted)
    );
  };

  const processTweets = () => {
    document.querySelectorAll('article').forEach((tweet) => {
      const rawText = tweet.innerText || '';
      if (isTweetBait(rawText, tweet)) {
        console.log(
          '🛑 Blocked tweet:',
          rawText.slice(0, 150).replace(/\n/g, ' ')
        );

        tweet.innerHTML = `
                  <div style="
                      padding: 16px;
                      margin: 8px;
                      color: #ff4d4d;
                      background: #1e1e1e;
                      border: 1px solid #444;
                      border-radius: 8px;
                      font-weight: bold;
                      font-family: sans-serif;
                      text-align: center;
                      font-size: 14px;
                  ">
                      🚫 Blocked Tweet (Unicode/Media Bait Detected)
                  </div>
              `;
      }
    });
  };

  const observer = new MutationObserver(() => {
    processTweets();
  });

  window.addEventListener('load', () => {
    console.log('✅ Twitter Bait Filter v1.9 loaded');
    processTweets();
    observer.observe(document.body, { childList: true, subtree: true });
  });
})();