Google Search - Remove AI Overview

This removes the AI Overview section at the top of Google Search.

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

You will need to install an extension such as Tampermonkey to install this script.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         Google Search - Remove AI Overview
// @version      1.0.7
// @description  This removes the AI Overview section at the top of Google Search.
// @author       makewebsitesbetter
// @namespace    userscripts
// @icon         https://i.postimg.cc/3NMLffrh/greenbox.png
// @include      *://*.google.*/search?*
// @run-at       document-start
// @license      MIT
// ==/UserScript==


(function() {
    'use strict';

    // Configuration.
    const AI_OVERVIEW_TEXT = ['AI Overview']; // Text to look for in the headers.
    const AI_TAB_TEXT = 'AI Mode';
    const TARGET_TAB_TEXT = 'More';

    // Function to hide the AI Overview.
    function handleAiOverview(element) {
        // Look for H1 or H2 elements that contain the words 'AI Overview'.
        const header = element.querySelector('h1, h2');
        if (header && AI_OVERVIEW_TEXT.some(text => header.textContent.includes(text))) {
            // Find the closest main div container and hide it.
            const container = header.closest('div');
            if (container) {
                container.style.display = 'none';
                // Mark it as hidden so it doesn't get processed again, for better optimization.
                container.dataset.aiRemoved = 'true';
            }
        }
    }

    // Function to move the 'AI Mode' tab before the 'More' tab.
    function handleTabs(element) {
        // Look for the 'AI Mode' tab inside of the added element.
        // Check if the element itself is the tab, or if it contains it.
        let aiTab = null;
        if (element.role === 'listitem' && element.textContent.includes(AI_TAB_TEXT)) {
            aiTab = element;
        } else if (element.querySelector) {
            aiTab = element.querySelector(`div[role='listitem']`);
            if (aiTab && !aiTab.textContent.includes(AI_TAB_TEXT)) aiTab = null;
        }

        if (aiTab && !aiTab.dataset.aiMoved) {
            // Find the 'More' tab to insert the 'AI Mode' tab before it.
            // Search the entire document because 'More' might already be there.
            const allTabs = document.querySelectorAll("div[role='listitem']");
            let targetTab = null;

            for (const tab of allTabs) {
                if (tab.textContent.includes(TARGET_TAB_TEXT)) {
                    targetTab = tab;
                    break;
                }
            }

            if (targetTab) {
                targetTab.parentNode.insertBefore(aiTab, targetTab);
                aiTab.dataset.aiMoved = 'true';
            }
        }
    }

    // Main Observer Callback.
    const observerCallback = (mutations) => {
        for (const mutation of mutations) {
            for (const node of mutation.addedNodes) {
                if (node.nodeType === 1) { // Ensure it is an element node and not text.
                    handleAiOverview(node);
                    handleTabs(node);
                }
            }
        }
    };

    // Start the observer.
    const observer = new MutationObserver(observerCallback);
    observer.observe(document.documentElement, {
        childList: true,
        subtree: true
    });

    // Initial check in case the script runs after elements are already loaded.
    window.addEventListener('DOMContentLoaded', () => {
        document.querySelectorAll('h1, h2').forEach(h => {
             if (AI_OVERVIEW_TEXT.some(text => h.textContent.includes(text))) {
                 const container = h.closest('div');
                 if (container) container.style.display = 'none';
             }
        });
    });

})();