Last active
June 14, 2026 06:05
-
-
Save hushin/43888eed98d8c45d0ba400e8718fd147 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 Submit from URL Query | |
| // @namespace http://tampermonkey.net/ | |
| // @version 1.1 | |
| // @description Automatically submit prompt from URL query parameter 'q' to Gemini (Handles delayed send button) | |
| // @author hushin | |
| // @match https://gemini.google.com/app* | |
| // @grant none | |
| // ==/UserScript== | |
| (function () { | |
| 'use strict'; | |
| function injectPromptAndSubmit(promptText) { | |
| try { | |
| const editor = document.querySelector('.ql-editor.textarea'); | |
| if (!editor) { | |
| console.error('テキストエリアが見つかりません。'); | |
| return; | |
| } | |
| // プロンプトを入力(TrustedHTML対応) | |
| editor.focus(); | |
| editor.textContent = ''; | |
| const lines = promptText.split('\n'); | |
| lines.forEach((line, index) => { | |
| const p = document.createElement('p'); | |
| p.textContent = line; | |
| editor.appendChild(p); | |
| }); | |
| // 入力イベントをシミュレート(Gemini側に文字が入力されたことを認識させるため) | |
| editor.dispatchEvent(new Event('input', { bubbles: true })); | |
| // 送信ボタンが表示・有効化されるのを待ってからクリック | |
| const checkSendButton = setInterval(() => { | |
| const sendButton = document.querySelector( | |
| 'button[aria-label="プロンプトを送信"], button[aria-label="Send"], button[aria-label="送信"]' | |
| ); | |
| // ボタンが存在し、かつ非表示(hidden)や無効化(disabled)されていないかチェック | |
| if (sendButton && !sendButton.disabled && sendButton.getAttribute('aria-disabled') !== 'true') { | |
| clearInterval(checkSendButton); | |
| setTimeout(() => { | |
| sendButton.click(); | |
| // ページ遷移を監視してクエリを削除 | |
| waitForPageTransition(); | |
| }, 100); | |
| } | |
| }, 200); // 200msごとにボタンをチェック | |
| // ボタン待機を10秒でタイムアウト | |
| setTimeout(() => { | |
| clearInterval(checkSendButton); | |
| }, 10000); | |
| } catch (error) { | |
| console.error('Geminiへの入力中にエラーが発生しました:', error); | |
| } | |
| } | |
| function waitForPageTransition() { | |
| const checkTransition = setInterval(() => { | |
| const currentUrl = window.location.href; | |
| // /app/(hash値)?q=... のパターンにマッチするか確認 | |
| if (/\/app\/[a-f0-9]+\?.*q=/.test(currentUrl)) { | |
| clearInterval(checkTransition); | |
| // 少し待ってからクエリを削除 | |
| setTimeout(() => { | |
| removeQueryFromURL(); | |
| }, 10_000); | |
| } | |
| }, 100); | |
| // 1分後にタイムアウト | |
| setTimeout(() => { | |
| clearInterval(checkTransition); | |
| }, 60000); | |
| } | |
| function removeQueryFromURL() { | |
| const url = new URL(window.location.href); | |
| url.searchParams.delete('q'); | |
| window.history.replaceState({}, '', url); | |
| } | |
| function init() { | |
| const urlParams = new URLSearchParams(window.location.search); | |
| const query = urlParams.get('q'); | |
| if (query) { | |
| const decodedQuery = decodeURIComponent(query); | |
| // Gemini のエディタが読み込まれるまで待機 | |
| const checkEditor = setInterval(() => { | |
| const editor = document.querySelector('.ql-editor.textarea'); | |
| if (editor) { | |
| clearInterval(checkEditor); | |
| injectPromptAndSubmit(decodedQuery); | |
| } | |
| }, 500); | |
| // 10秒後にタイムアウト | |
| setTimeout(() => { | |
| clearInterval(checkEditor); | |
| }, 10000); | |
| } | |
| } | |
| // ページ読み込み後に実行 | |
| if (document.readyState === 'loading') { | |
| document.addEventListener('DOMContentLoaded', init); | |
| } else { | |
| init(); | |
| } | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment