8
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ScriptAutoRunner を使って Qiita ユーザー名指定して記事一覧やコメントを非表示にする

Last updated at Posted at 2021-03-03

Qiitaではユーザーブロックしても自分の記事からそのユーザーのコメントを消せなくて、運営の人にいうまでもないけど、この人のコメントは読みたくないなあ。という要望に答えられないシステムになっています。

で、それはちょっと残念なので、ChromeのScriptAutoRunner を使えば、コメント欄から特定の人の記事を消すことができましたので、記載しておきます。

相手にも知られずに自分が見る所から消えてもらえればいいという感じなので、別に迷惑かかんないかと思いますので、SNSのコミュニケーションにお悩み抱える方はどうぞです。

ScriptAutoRunnerの使い方については、素晴らしい記事がありますので、そちらどうぞ。

Amazonの商品ページから、「人気のインディーズマンガ」を消したい(chrome) - Qiita
https://qiita.com/iteyan/items/78bcad46ae43616eeb0f

コード

// console.log('ScriptAutoRunner qiita.js 2022/01/16(Sun)', location.href);
(() => {
  const targetUrls = [
    'qiita.com/',
  ];
  if (targetUrls.some(url => location.href.includes(url))) {
    console.log('qiita site !');

    const userNameArray = [
      '/standard-software',
    ];
    const deleteQiitaUserComment = () => {

      // コメント欄の処理
      const commentList = document.querySelectorAll("#comments a");
      for (const element of Array.from(commentList)) {

        if (!element) { continue; }

        // コメントで@ID指定したコメントまで削除したい場合は
        // 下記行をコメントアウトする
        // if (!element.querySelector("img")) { continue; }

        if (element.parentNode.parentNode.parentNode.style.display === 'none') { continue; }

        const linkName = element.getAttribute('href');
        let deleteFlag = false;
        for (const userName of userNameArray) {
          if (userName === linkName) {
            console.log('ScriptAutoRunner', 'Hit Comment', linkName);
            deleteFlag = true;
            break;
          }
        }
        if (deleteFlag) {
          element.parentNode.parentNode.parentNode.style.display = 'none';
          // element.parentNode.parentNode.parentNode.remove();
          continue;
        }
      }

      // 通知欄の処理
      const infoList = document.querySelectorAll(".st-NewHeader_notiIframe a");
      for (const element of Array.from(infoList)) {
        if (!element) { continue; }
        if (element.parentNode.parentNode.style.display === 'none') { continue; }
        const linkName = element.getAttribute('href');
        let deleteFlag = false;
        for (const userName of userNameArray) {
          if (userName === linkName) {
            console.log('ScriptAutoRunner', 'Hit Notice', linkName);
            deleteFlag = true;
            break;
          }
        }
        if (deleteFlag) {
          element.parentNode.parentNode.style.display = 'none';
          // element.parentNode.parentNode.remove();
          continue;
        }
      }

      // 記事フィードの処理
      const articleList = document.querySelectorAll("article a");
      for (const element of Array.from(articleList)) {
        if (!element) { continue; }
        if (element.parentNode.parentNode.parentNode.style.display === 'none') { continue; }
        const linkName = element.getAttribute('href');
        let deleteFlag = false;
        for (const userName of userNameArray) {
          if (userName === linkName) {
            console.log('ScriptAutoRunner', 'Hit Article', linkName);
            deleteFlag = true;
            break;
          }
        }
        if (deleteFlag) {
          element.parentNode.parentNode.parentNode.style.display = 'none';
          // element.parentNode.parentNode.remove();
          continue;
        }
      }

    };

    // 指定ユーザーページなら処理は行わない
    if (userNameArray.some(
      userName => {
        const result = (
          location.href.endsWith(userName) ||
          location.href.includes(userName + '/')
        )
        if (result) {
          console.log('ScriptAutoRunner', 'targetUserPage', userName);
        }
        return result;
      }
    )) {
      return
    }

    for (let i = 1; i < 20000; i += 1) {
      setTimeout(deleteQiitaUserComment, i * 50)
    }
    // 20000 * 50 = 1000000 = 1000秒 = 16分40秒
  }
})();

このようにすると、私のログイン名「@standard-software」の書いたコメントが全部消えます。

@eduidl さんに頂いた内容もコード内に取り込ませていただき、コメントで書いていた最新コードを記事に反映しました。

8
4
5

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
8
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?