Auto Confirm New Chat for Gemini

Google Geminiで「新しいチャットを作成」ダイアログを自動で確認し、通知を表示します。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Auto Confirm New Chat for Gemini
// @namespace    https://qestir.hatenablog.com/
// @version      1.1
// @description  Google Geminiで「新しいチャットを作成」ダイアログを自動で確認し、通知を表示します。
// @match        https://gemini.google.com/*
// @grant        none
// @license GPL-3.0-or-later
// ==/UserScript==

(function() {
    'use strict';

    // 通知を表示する関数
    function showNotification(message, success = true) {
        const notification = document.createElement('div');
        notification.style.position = 'fixed';
        notification.style.bottom = '20px';
        notification.style.right = '20px';
        notification.style.padding = '10px 20px';
        notification.style.backgroundColor = success ? 'green' : 'red';
        notification.style.color = 'white';
        notification.style.fontSize = '14px';
        notification.style.borderRadius = '5px';
        notification.style.zIndex = '1000';
        notification.textContent = message;
        document.body.appendChild(notification);
        setTimeout(() => {
            notification.remove();
        }, 5000); // 5秒後に自動で消える
    }

    // ポップアップ内の「チャットを新規作成」ボタンを探しクリックする関数
    function clickConfirmButton() {
        try {
            const confirmButton = document.querySelector('button[data-test-id="confirm-button"]');
            if (confirmButton) {
                confirmButton.click();
                showNotification('自動クリックに成功しました');
                return true; // ボタンがクリックされたらtrueを返す
            }
        } catch (error) {
            console.error('エラーが発生しました:', error);
            showNotification('自動クリックに失敗しました。詳細はコンソールを確認してください。', false);
        }
        return false; // ボタンが見つからないかエラーが発生した場合はfalseを返す
    }

    // ページの読み込み完了時にボタンの存在をチェック
    window.addEventListener('load', () => {
        clickConfirmButton();
    });

    // 一定間隔でボタンをチェック
    setInterval(() => {
        clickConfirmButton();
    }, 1000); // 1秒ごとにチェック

})();