自动关闭 Google AI Studio 设置面板

当 AI Studio 页面加载时,自动关闭设置面板以节省页面空间。顺带一提,这个脚本是 Gemini 在 AI Studio 中编写的。

当前为 2025-04-13 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        Automatically Close Google AI Studio Settings Panel
// @name:zh-CN  自动关闭 Google AI Studio 设置面板
// @namespace   Violentmonkey Scripts
// @match       https://aistudio.google.com/*
// @grant       GM_addStyle
// @run-at      document-start
// @version     1.1
// @author      plasma-green & Gemini 2.5 Pro Preview 03-25
// @description When the AI Studio page loads, the settings panel is automatically closed to save page space. By the way, this script was written by Gemini in AI Studio.
// @description:zh-CN 当 AI Studio 页面加载时,自动关闭设置面板以节省页面空间。顺带一提,这个脚本是 Gemini 在 AI Studio 中编写的。
// @license     AGPL-3.0
// ==/UserScript==


(function() {
    'use strict';

    const buttonSelector = 'button[aria-label="Run settings"]';
    const checkInterval = 500; // 检查间隔 (毫秒),例如半秒
    const maxAttempts = 30;    // 最大尝试次数 (例如 30 * 0.5秒 = 15秒)
    let attempts = 0;

    console.log('自动点击脚本已启动,开始查找按钮...');

    // 尝试点击按钮的函数
    function tryClickButton() {
        const button = document.querySelector(buttonSelector);
        if (button) {
            try {
                console.log(`尝试 #${attempts + 1}: 找到按钮,尝试点击...`);
                button.click();
                console.log('按钮点击成功!');
                return true; // 表示成功找到并点击
            } catch (e) {
                console.error(`尝试 #${attempts + 1}: 点击按钮时出错:`, e);
                return false; // 点击失败,但按钮找到了
            }
        }
        return false; // 表示按钮未找到
    }

    // 设置定时器,定期检查按钮
    const intervalId = setInterval(() => {
        attempts++;
        console.log(`检查 #${attempts}...`);

        if (tryClickButton()) {
            clearInterval(intervalId); // 成功点击后清除定时器
            console.log('任务完成,停止检查。');
        } else if (attempts >= maxAttempts) {
            clearInterval(intervalId); // 达到最大尝试次数后清除定时器
            console.log(`达到最大尝试次数 (${maxAttempts}),未找到或未成功点击按钮,停止检查。`);
        }
        // 如果按钮未找到且未超时,则继续下一次检查
    }, checkInterval);

    GM_addStyle(`
      /* 隐藏不需要的元素 */
      .header-container, .placeholder-overlay.ng-star-inserted {
          display: none !important;
    }`);
})();