Disable Google AI Search & Hide Button (for AtCoder)

Redirects Google AI search (udm=50) and hides the "AI Mode" button from the UI to comply with AtCoder rules.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Disable Google AI Search & Hide Button (for AtCoder)
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Redirects Google AI search (udm=50) and hides the "AI Mode" button from the UI to comply with AtCoder rules.
// @description:ja AtCoderのルールに準拠するため、GoogleのAI検索(udm=50)をリダイレクトし、UIから「AI モード」ボタンを非表示にします。
// @author       paruma184
// @license      MIT
// @match        *://www.google.com/search*
// @grant        GM_addStyle
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';

    // --- 機能1: AIモードのページを開いてしまった場合にリダイレクトする ---
    // この処理はページの読み込み開始時に即座に実行される
    if (window.location.href.includes('udm=50')) {
        const newUrl = window.location.href.replace('udm=50', 'udm=14');
        window.location.replace(newUrl);
        return; // リダイレクト後は以降の処理不要
    }

    // --- 機能2: 検索メニューから「AI モード」のボタンを非表示にする ---
    // ページのDOMが読み込まれた後、CSSを追加してボタンを消す
    // @grant GM_addStyle がこの機能のために必要
    const css = `
        /* hrefに "udm=50" を含むリンクを持つメニュー項目を非表示にする */
        div[role="listitem"]:has(a[href*="udm=50"]) {
            display: none !important;
        }
    `;

    // ページが読み込まれるのを待ってからCSSを適用
    // Tampermonkeyの機能であるGM_addStyleを使ってCSSを注入
    GM_addStyle(css);

})();