Nuke Google AI Overview

Hides AI Overview by searching for text or selectors.

// ==UserScript==
// @name        Nuke Google AI Overview
// @namespace   TBlazeWarriorT
// @match       https://*.google.*/search*
// @match       https://www.google.com/*
// @icon        https://www.google.com/s2/favicons?sz=64&domain=google.com
// @grant       none
// @version     1.0
// @author      Idea by TBlazeWarriorT Adapted by xAI
// @run-at      document-start
// @license     MIT
// @description Hides AI Overview by searching for text or selectors.
// ==/UserScript==

(function() {
  let isNuked = false;
  let observer = null;
  let intervalId = null;

  function hideByText(text) {
    if (isNuked) return false;
    const walker = document.createTreeWalker(
      document.body || document.documentElement,
      NodeFilter.SHOW_TEXT,
      null,
      false
    );
    let node, found = false;
    while (node = walker.nextNode()) {
      if (node.textContent.toLowerCase() === text.toLowerCase()) {
        let parent = node.parentElement;
        while (parent && parent.tagName !== 'DIV' && !parent.hasAttribute('data-ai-section') && !parent.hasAttribute('role')) {
          parent = parent.parentElement;
        }
        if (parent) {
          parent.style.display = 'none';
          found = true;
          isNuked = true;
          stopObserving();
        }
      }
    }
    return found;
  }

  function hideBySelector(sel) {
    if (isNuked) return false;
    const elem = document.querySelector(sel);
    if (elem) {
      elem.style.display = 'none';
      isNuked = true;
      stopObserving();
      return true;
    }
    return false;
  }

  function stopObserving() {
    if (observer) observer.disconnect();
    if (intervalId) clearInterval(intervalId);
  }

  function nukeAI() {
    if (isNuked) return;
    let success = false;
    success |= hideByText('AI Overview');
    success |= hideByText('AI Summary');
    success |= hideByText('Generated by AI');
    success |= hideByText('Overview by AI');
    success |= hideByText('AI-Powered Summary');
    success |= hideBySelector('[data-omi-ai]');
    success |= hideBySelector('div[jscontroller="C7S1ed"]');
    success |= hideBySelector('div[data-rstr]');
    success |= hideBySelector('div[jsname="AIoCO"]');
    success |= hideBySelector('div.sge-overview');
    success |= hideBySelector('div[role="complementary"]');
    success |= hideBySelector('div.ai-generated-content');
    success |= hideBySelector('div[data-ai-section]');
  }

  function observeDOM() {
    if (isNuked) return;
    observer = new MutationObserver(() => {
      if (!isNuked) nukeAI();
    });
    observer.observe(document.body || document.documentElement, {
      childList: true,
      subtree: true,
      attributes: true
    });
  }

  try {
    document.createElement('div').style.display = 'none';
  } catch (e) {
    return;
  }

  let timeouts = [0, 50, 100, 200, 500, 1000, 2000, 4000];
  timeouts.forEach(delay => setTimeout(() => {
    if (!isNuked) nukeAI();
  }, delay));
  intervalId = setInterval(() => {
    if (!isNuked) nukeAI();
  }, 1500);
  if (document.body) observeDOM();
  else window.addEventListener('load', observeDOM);
})();