LoginSignup
2
0

Qiitaコメント欄の特定ユーザを非表示にしよう!

Last updated at Posted at 2024-02-02

0.はじめに

僕含めた新米エンジニアはQiitaのコメント欄で傷つくことも多いだろう。
だが、Qiitaにはコメント欄のきつい言葉を吐くユーザーを非表示にすることはできる機能はない..。
そこでだ!
君も僕が作ったJavaScriptをChromeにいれて快適にQiitaライフを送ろうじゃないか!

1.ScriptAutoRunnerをダウンロードしよう!

ScriptAutoRunnerとはChromeのページに特定のjsを読み込ませることのできる拡張機能だ!リンクに飛んでさっそくいれてみよう!

2.下記jsをScriptAutoRunnerにいれよう!

ここは簡単だ!
下記jsをコピーしてScriptAutoRunnerにペーストするだけだ!

(() => {
    /*------------------▼拡張機能を使う人が変更する箇所▼----------------*/

    // 適応させるドメイン
    const targetDomain = 'qiita.com';

    // 対象URLパス
    const targetPaths = [
        '/items/',
        '/questions/',
    ];

    // @ID指定されたコメントを非表示にするかどうかのフラグ
    const hideMentionedComments = true; // trueの場合、@ID指定されたコメントを非表示にする

    // ユーザー名の配列を定義
    const userNameArray = [ // '/' + 非表示にしたいユーザID(@は省略)
        '/UserID',
        '/UserID',
        '/UserID',
        '/UserID',
        '/UserID',
        '/UserID',
        '/UserID',
        '/UserID',
        '/UserID',
        '/UserID',
        '/UserID',
        '/UserID',
        '/UserID',
        '/UserID',
        '/UserID',
        '/UserID',
        '/UserID',
        '/UserID',
        '/UserID',
        '/UserID',
        '/UserID',
        '/UserID',
        '/UserID',
        '/UserID',
        '/UserID',
        '/UserID',
    ];

    /*---------------------------▲ここまで▲---------------------------*/

    const deleteQiitaUserComment = () => {
        // 全てのaタグを取得
        const userLinks = document.querySelectorAll("a");
        for (const link of Array.from(userLinks)) {
            if (!link) { continue; }

            const linkName = link.getAttribute('href');

            if (userNameArray.some(userName => linkName.endsWith(userName))) {
                console.log('Hit User', linkName);
                // 親セクションを非表示にする
                const section = link.closest("section");
                if (section) {
                    section.style.display = 'none';
                }
            }
        }

        // 件の回答を非表示にする
        const replyCounts = document.querySelectorAll("span");
        for (const count of Array.from(replyCounts)) {
            if (count.textContent.trim() === "件の回答") {
                const parentHeader = count.parentElement.closest("h2");
                if (parentHeader) {
                    parentHeader.style.display = 'none';
                }
            }
        }
    };

    if (location.href.includes(targetDomain) && targetPaths.some(path => location.pathname.includes(path))) {
        console.log('qiita site !');

        // 指定ユーザーページなら処理は行わない
        if (userNameArray.some(userName => location.pathname.endsWith(userName))) {
            return;
        }

        // setIntervalを使用してdeleteQiitaUserCommentを定期的に実行する
        const intervalId = setInterval(deleteQiitaUserComment, 50);

        // 一定の回数が経過したら処理を停止する
        setTimeout(() => {
            clearInterval(intervalId);
        }, 20000 * 50); // 20000回 * 50ミリ秒 = 1000000ミリ秒 = 1000秒 = 16分40秒/*  */
    }
})();


3.非表示ユーザーをjsに書き込もう!

辛口コメントを吐くおじさんたちを'/UserID',の部分に入力しよう!

仮に僕を非表示にしたい場合は'/pX3uCGUg9c86802', を登録しよう!(最後は解除してね..)

4.最後に

~これのおかげで新米エンジニアたちの平和は守られたのであった~

補足

※暇な方!このjsをChromeの拡張機能化してオプションページで非表示ユーザを選択できるようにしてくれい!おそらくChatGPTに聞けば簡単にできるだろう..だがめんどくさいんだっ!

2
0
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0