Created
February 3, 2026 02:37
-
-
Save eai04191/12e0975933e6d7edced3dbd4bd220717 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name Gemini Auto Switch to Pro (Optimized) | |
| // @namespace http://tampermonkey.net/ | |
| // @version 2.0 | |
| // @description Geminiの新規チャット時にdata-test-idを使用してProモードへ自動切り替え | |
| // @author You | |
| // @match https://gemini.google.com/* | |
| // @grant none | |
| // @run-at document-idle | |
| // ==/UserScript== | |
| (function() { | |
| 'use strict'; | |
| // 切り替えたいモデル名のテキスト(画面表示に合わせる) | |
| const TARGET_MODEL_TEXT = "Pro"; | |
| // セレクタ定義(ご提示いただいたHTMLに基づく) | |
| const TRIGGER_SELECTOR = '[data-test-id="bard-mode-menu-button"]'; | |
| let isProcessing = false; | |
| function attemptSwitch() { | |
| if (isProcessing) return; | |
| // 1. トリガーとなるボタンコンテナを探す | |
| const triggerContainer = document.querySelector(TRIGGER_SELECTOR); | |
| if (!triggerContainer) return; | |
| // 2. 現在の表示テキストを確認 | |
| // 既に "Pro" が含まれていれば何もしない | |
| if (triggerContainer.textContent.includes(TARGET_MODEL_TEXT)) { | |
| return; | |
| } | |
| // 3. 切り替え処理開始 | |
| isProcessing = true; | |
| console.log(`[Gemini Auto Switch] Switching to ${TARGET_MODEL_TEXT}...`); | |
| // コンテナ内のbutton要素をクリック(またはコンテナ自体をクリック) | |
| const buttonToClick = triggerContainer.querySelector('button') || triggerContainer; | |
| buttonToClick.click(); | |
| // 4. メニューが開くのを待って選択 | |
| setTimeout(() => { | |
| // メニュー項目を探す (role="menuitem" または role="option") | |
| const menuItems = document.querySelectorAll('[role="menuitem"], [role="option"], .mat-mdc-menu-item'); | |
| let targetFound = false; | |
| for (const item of menuItems) { | |
| // 余計な空白を除去して比較 | |
| if (item.textContent.trim().includes(TARGET_MODEL_TEXT)) { | |
| item.click(); | |
| targetFound = true; | |
| console.log(`[Gemini Auto Switch] Switched to ${TARGET_MODEL_TEXT}`); | |
| break; | |
| } | |
| } | |
| if (!targetFound) { | |
| // 見つからなかった場合はメニューを閉じるために背景などをクリックするか、もう一度ボタンを押す | |
| // ここでは再度ボタンを押して閉じる | |
| buttonToClick.click(); | |
| } | |
| // 処理完了後のクールダウン(連続実行防止) | |
| setTimeout(() => { isProcessing = false; }, 1000); | |
| }, 300); // メニューのアニメーション待ち時間 | |
| } | |
| // SPA遷移の監視 (MutationObserver) | |
| const observer = new MutationObserver((mutations) => { | |
| // 新規チャット画面 (/app または /) の場合のみ実行 | |
| // URLチェックを厳密にしたい場合は調整してください | |
| const isNewChat = window.location.pathname === "/app" || window.location.pathname === "/"; | |
| if (isNewChat) { | |
| attemptSwitch(); | |
| } | |
| }); | |
| observer.observe(document.body, { childList: true, subtree: true }); | |
| // 初回実行 | |
| setTimeout(attemptSwitch, 1000); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment