#author("2026-03-12T01:00:45+09:00","","")
#author("2026-03-12T01:01:16+09:00","","")
* Twitterの検索結果から表示名にキーワードを含んでくる奴と違う結果を除外するやつ [#FuckElon0001]

** はじめに [#qbf39ce4]

- Twitterで完全一致検索が出来ないのは以下ツイートでもある通り、『%22』で囲ってあげると機能するようになるらしい。
-- https://twitter.com/thisiskogatti/status/2028742150175990155
<pre>
明らか脆弱性か何かを突いてそうなやり方なんですが、「”」じゃなくて「%22」で文字列を囲むと完全一致検索できることに気がついた
</pre>

- 元々の検索結果がカス過ぎると、すぐにレートリミットに達して検索が機能しなくなるので、~
上記方法での完全結果検索も活かして検索するように心がけてください。


** コード本体 [#b8300c77]

<pre>
// ==UserScript==
// @name         Twitter Search Query Filter
// @namespace    https://junkyard.shirotsume.ch/
// @version      1.0.1a
// @description  Twitter検索結果からユーザーの表示名に検索ワードを含んでくる馬鹿を除外します。また、イーロン便器マスクの改悪による違う検索結果も除外します。
// @author       shirotsume
// @match        https://x.com/search*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // 検索ワードを取得する関数
    function getSearchQuery() {
        const urlParams = new URLSearchParams(window.location.search);
        return urlParams.get("q") || "";
    }

    // 検索結果を監視し、条件を満たす要素を非表示にする
    function filterSearchResults() {
        const query = getSearchQuery();
        if (!query) return;

        const searchWords = query
            .split(/\s+/)
            .map(word => word.replace(/%22/g, '')) // ★ %22(")を削除
            .map(word => word.replace(/^[^\p{L}\p{N}]+|[^\p{L}\p{N}]+$/gu, '')) //両端の記号を削除
            .filter(word => word.length > 0); // ★ 除去後に空文字になった要素を削除
            .map(word => word.replace(/%22/g, '')) // %22(")を削除
            .map(word => word.replace(/^[^\p{L}\p{N}]+|[^\p{L}\p{N}]+$/gu, '')) // 両端の記号を削除
            .filter(word => word.length > 0); // 除去後に空文字になった要素を削除

        // 検索結果のリストを取得
        const results = document.querySelectorAll("article");
        results.forEach(result => {
            const tweetTextElement = result.querySelector("div[data-testid='tweetText']");

            if (tweetTextElement) {
                const tweetText = tweetTextElement.textContent;

                // ツイート本文に検索ワードが含まれているかチェック
                // someならOR、everyならAND。ANDにしてしまうと各フィルターが面倒な感じなのでORで。
                if (!searchWords.some(word => tweetText.toLowerCase().includes(word.toLowerCase()))) {
                    result.style.display = "none";
                }
            } else {
                result.style.display = "none";
            }
        });
    }

    // URL変化の検知
    let lastUrl = location.href;
    function onUrlChange() {
        const currentUrl = location.href;
        if (currentUrl !== lastUrl) {
            lastUrl = currentUrl;
            // URL変化後、DOMの描画を少し待ってからフィルター実行
            setTimeout(filterSearchResults, 500);
        }
    }

    const observer = new MutationObserver(() => {
        onUrlChange();
        filterSearchResults();
    });

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

    filterSearchResults();
})();
</pre>

トップ   編集 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
This site is protected by Turnstile and the Cloudflare Privacy Policy and Terms of Service apply.