Automatically Close Google AI Studio Settings Panel

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.

目前為 2025-04-13 提交的版本,檢視 最新版本

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 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;
    }`);
})();