HackerNews_AI_Comment_Replace

Replaces Hacker News comment text with "AI" if it contains the word "AI"

当前为 2025-10-03 提交的版本,查看 最新版本

// ==UserScript==
// @name        HackerNews_AI_Comment_Replace
// @match       https://news.ycombinator.com/item*
// @description Replaces Hacker News comment text with "AI" if it contains the word "AI"
// @version 0.0.1.20251003165023
// @namespace https://greasyfork.org/users/1435046
// ==/UserScript==

const observeComments = () => {
  const observer = new MutationObserver((mutations) => {
    mutations.forEach((mutation) => {
      mutation.addedNodes.forEach((node) => {
        if (node.nodeType === Node.ELEMENT_NODE) {
          const commentElements = node.querySelectorAll('div.commtext.c00');
          commentElements.forEach((commentElement) => {
            const commentText = commentElement.textContent;
            if (commentText.includes('AI')) {
              commentElement.textContent = 'AI';
            }
          });
        }
      });
    });
  });

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

observeComments();