Auto enable grounding with Google search in Aistudio

Enable "Grounding with Google Search" once on page load

// ==UserScript==
// @name         Auto enable grounding with Google search in Aistudio
// @namespace    Violentmonkey Scripts
// @version      1.0
// @description  Enable "Grounding with Google Search" once on page load
// @author       Bui Quoc Dung
// @match        https://aistudio.google.com/*
// @grant        none
// @run-at       document-idle
// ==/UserScript==

(function () {
  'use strict';

  // Function to wait for the toggle button to appear
  function waitForElement(selector, timeout = 10000) {
    return new Promise((resolve, reject) => {
      const interval = 100;
      let elapsed = 0;

      const timer = setInterval(() => {
        const el = document.querySelector(selector);
        if (el) {
          clearInterval(timer);
          resolve(el);
        } else if (elapsed >= timeout) {
          clearInterval(timer);
          reject();
        }
        elapsed += interval;
      }, interval);
    });
  }

  // Only enable the switch once when the page loads
  async function enableSwitchOnce() {
    try {
      const button = await waitForElement('button[aria-label="Grounding with Google Search"]');
      if (button.getAttribute('aria-checked') === 'false') {
        button.click();
      }
    } catch (err) {
    }
  }

  // Run once after page is ready
  enableSwitchOnce();
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址