Greasy Fork

来自缓存

Greasy Fork is available in English.

Threads 搜尋結果 ‑ 隱藏已追蹤帳號

在 Threads 搜尋頁,只顯示「尚未追蹤」的帳號 (卡片內會出現「追蹤 / Follow」按鈕)。

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Threads 搜尋結果 ‑ 隱藏已追蹤帳號
// @namespace    https://threads.com
// @version      0.2
// @description  在 Threads 搜尋頁,只顯示「尚未追蹤」的帳號 (卡片內會出現「追蹤 / Follow」按鈕)。
// @match        https://www.threads.com/search*
// @grant        none
// @license MIT
// ==/UserScript==

(() => {
  'use strict';

  /** 判斷要不要保留這張搜尋結果卡片 */
  const shouldKeep = (card) => {
    // 依需求增減關鍵字 (多語系)
    const keywords = ['追蹤', 'Follow', 'フォロー'];
    return keywords.some(kw => card.textContent.includes(kw));
  };

  /** 處理(新增的)卡片節點 */
  const processCard = (card) => {
    if (!shouldKeep(card)) {
      card.style.display = 'none';
    }
  };

  /** 一開始就先跑一次,處理已渲染好的卡片 */
  const initialScan = () => {
    document.querySelectorAll('div[data-pressable-container="true"]').forEach(processCard);
  };

  /** 監聽接下來動態載入的搜尋結果 */
  const observer = new MutationObserver((mutations) => {
    for (const m of mutations) {
      m.addedNodes.forEach(node => {
        if (node.nodeType !== 1) return;          // 只處理 element
        if (node.matches?.('div[data-pressable-container="true"]')) {
          processCard(node);
        }
        node.querySelectorAll?.('div[data-pressable-container="true"]').forEach(processCard);
      });
    }
  });

  observer.observe(document.body, { childList: true, subtree: true });
  initialScan();   // 首次執行
})();