Defaults Google searches to AI Mode and selects the "2.5 Pro" model.
当前为
// ==UserScript==
// @name Google AI - Default to AI Mode & 2.5 Pro (Gemini)
// @namespace http://tampermonkey.net/
// @version 3.1
// @description Defaults Google searches to AI Mode and selects the "2.5 Pro" model.
// @author JP - Discord: @Organism
// @match https://www.google.com/search*
// @grant none
// @run-at document-start
// ==/UserScript==
(function() {
'use strict';
// --- Part 1: Redirect to AI Mode ---
// This part runs immediately to check if the URL needs to be changed.
const url = new URL(window.location.href);
// If the URL is a search (has a 'q=' parameter) but is not already AI Mode ('udm=50'),
// this will add the correct parameter and reload the page.
if (url.searchParams.has('q') && url.searchParams.get('udm') !== '50') {
url.searchParams.set('udm', '50');
window.location.href = url.toString();
return; // Stop the script here, as the page will be reloaded.
}
// --- Part 2: Select 2.5 Pro Model ---
// This part only runs on the AI Mode page to select the model.
// It must wait for the page content to load.
function setupModelSelector() {
const TOGGLE_BUTTON_XPATH = "//div[contains(@class, 'tk4Ybd') and .//span[text()='AI Mode']]";
const PRO_MODEL_ITEM_XPATH = "//g-menu-item[.//span[text()='2.5 Pro']]";
function findElement(xpath) {
return document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
}
const observer = new MutationObserver((mutations, obs) => {
const proMenuItem = findElement(PRO_MODEL_ITEM_XPATH);
if (proMenuItem) {
if (proMenuItem.getAttribute('aria-checked') === 'true') {
obs.disconnect(); // Already selected
} else {
proMenuItem.click(); // Select it
obs.disconnect();
}
return;
}
const toggleButton = findElement(TOGGLE_BUTTON_XPATH);
if (toggleButton) {
toggleButton.click(); // Open the menu
}
});
observer.observe(document.body, {
childList: true,
subtree: true
});
}
// Wait for the basic page structure to be ready before trying to find elements.
document.addEventListener('DOMContentLoaded', setupModelSelector);
})();