Greasy Fork is available in English.

屏蔽V2EX无聊的AI讨论

屏蔽V2EX无聊的AI讨论内容

// ==UserScript==
// @name         屏蔽V2EX无聊的AI讨论
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  屏蔽V2EX无聊的AI讨论内容
// @author       DebuggerX
// @match        https://www.v2ex.com/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// ==/UserScript==

(function () {
  'use strict';
  const defaultKeywords = ['openai', 'chatgpt'];
  let keywords = localStorage.getItem('key_ai_keywords');
  if (!!keywords) {
    keywords = JSON.parse(keywords);
  }
  else {
    localStorage.setItem('key_ai_keywords', JSON.stringify(defaultKeywords));
    keywords = defaultKeywords;
  }

  let count = 0;

  document.querySelectorAll('.cell.item').forEach((post) => {
    let content = post.querySelector('.item_title').innerHTML.toLowerCase();
    for (const keyword of keywords) {
      if (content.includes(keyword)) {
        post.style.display = 'none';
        count++;
        break;
      }
    }
  });

  const comment = document.createElement('span');
  comment.className = 'fade';
  comment.innerText = `${count} 条已屏蔽`;
  comment.style.marginRight = '16px';
  comment.style.cursor = 'pointer';
  comment.addEventListener('click', () => {
    document.querySelectorAll('.cell.item').forEach((post) => {
      post.style.display = '';
    });
    comment.innerText = '0 条已屏蔽';
  });
  document.querySelector('#SecondaryTabs').prepend(comment);
})();