AI Navigation Bar

Automatically clicks the "Try GPT-5" button and adds navigation buttons to AI chat services

当前为 2025-10-25 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         AI Navigation Bar
// @namespace    http://tampermonkey.net/
// @version      2.6
// @description  Automatically clicks the "Try GPT-5" button and adds navigation buttons to AI chat services
// @author       You
// @match        https://m365.cloud.microsoft/*
// @match        https://claude.ai/*
// @match        https://chatgpt.com/*
// @match        https://chat.deepseek.com/*
// @match        https://gemini.google.com/*
// @match        https://www.perplexity.ai/*
// @grant        none
// @homepage     https://greasyfork.org/en/scripts/550204-ai-navigation-bar
// ==/UserScript==
(function() {
    'use strict';

    // Navigation buttons configuration
    const navButtons = [
        { name: 'M365', url: 'https://m365.cloud.microsoft' },
        { name: 'Gemini', url: 'https://gemini.google.com' },
        { name: 'Anthropic', url: 'https://claude.ai' },
        { name: 'ChatGPT', url: 'https://chatgpt.com' },
        { name: 'DeepSeek', url: 'https://chat.deepseek.com' },
        { name: 'Perplexity', url: 'https://www.perplexity.ai' }
    ];

    // Create navigation bar
    function createNavigationBar() {
        // Check if nav bar already exists
        if (document.getElementById('ai-nav-bar')) return;

        const navBar = document.createElement('div');
        navBar.id = 'ai-nav-bar';
        navBar.style.cssText = `
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            background: transparent;
            padding: 6px;
            display: flex;
            gap: 6px;
            justify-content: center;
            align-items: center;
            z-index: 999999;
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            pointer-events: none;
        `;

        navButtons.forEach(btn => {
            const button = document.createElement('button');
            button.textContent = btn.name;
            button.style.cssText = `
                background: rgba(45, 45, 45, 0.9);
                color: #e0e0e0;
                border: 1px solid #404040;
                padding: 5px 12px;
                border-radius: 20px;
                cursor: pointer;
                font-weight: 600;
                font-size: 12px;
                transition: all 0.3s ease;
                box-shadow: 0 2px 4px rgba(0,0,0,0.3);
                backdrop-filter: blur(10px);
                pointer-events: auto;
            `;

            // Hover effects
            button.onmouseenter = () => {
                button.style.background = 'rgba(61, 61, 61, 0.95)';
                button.style.borderColor = '#505050';
                button.style.transform = 'translateY(-1px)';
                button.style.boxShadow = '0 3px 6px rgba(0,0,0,0.4)';
            };
            button.onmouseleave = () => {
                button.style.background = 'rgba(45, 45, 45, 0.9)';
                button.style.borderColor = '#404040';
                button.style.transform = 'translateY(0)';
                button.style.boxShadow = '0 2px 4px rgba(0,0,0,0.3)';
            };

            button.onclick = () => {
                window.open(btn.url, '_blank');
            };

            navBar.appendChild(button);
        });

        // Add to page
        document.body.insertBefore(navBar, document.body.firstChild);

        console.log('Navigation bar created successfully!');
    }

    // Original auto-click functionality
    let attempts = 0;
    const maxAttempts = 20;
    const delay = 500;
    const editorDelay = 1000;
    let buttonClicked = false;
    let editorClicked = false;

    function findAndClickButton() {
        if (buttonClicked) return;
        attempts++;
        console.log(`Attempt ${attempts}: Looking for GPT-5 button...`);
        const buttons = document.querySelectorAll('button[aria-pressed="false"]');
        let found = false;
        buttons.forEach(button => {
            if (button.textContent.includes("Try GPT-5") && !buttonClicked) {
                console.log("Found GPT-5 button, clicking...");
                button.click();
                found = true;
                buttonClicked = true;
                setTimeout(() => {
                    findAndClickEditor();
                }, editorDelay);
            }
        });
        if (found) {
            console.log("GPT-5 button clicked successfully!");
            observer.disconnect();
            return;
        }
        if (attempts < maxAttempts && !buttonClicked) {
            setTimeout(findAndClickButton, delay);
        } else if (!buttonClicked) {
            console.log("Max attempts reached, GPT-5 button not found");
        }
    }

    function findAndClickEditor() {
        if (editorClicked) return;
        console.log("Looking for chat editor element...");
        const editorElement = document.getElementById('m365-chat-editor-target-element');
        if (editorElement) {
            console.log("Found chat editor element, clicking...");
            editorElement.click();
            editorClicked = true;
            console.log("Chat editor element clicked successfully!");
        } else {
            console.log("Chat editor element not found yet");
        }
    }

    // Initialize navigation bar with delay
    function initNavigationBar() {
        // Wait for page to fully load and settle
        setTimeout(() => {
            createNavigationBar();

            // Re-check periodically in case it gets hidden or removed
            // Run checks every 2 seconds for the first 1 minute
            let checkCount = 0;
            const maxChecks = 30; // 30 checks × 2 seconds = 1 minute

            const intervalId = setInterval(() => {
                checkCount++;

                if (!document.getElementById('ai-nav-bar')) {
                    console.log('Navigation bar was removed, recreating...');
                    createNavigationBar();
                }

                // Stop checking after 2 minutes
                if (checkCount >= maxChecks) {
                    clearInterval(intervalId);
                    console.log('Navigation bar monitoring stopped after 1 minute');
                }
            }, 2000);
        }, 300); // Wait 0.3 seconds after page load
    }

    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', initNavigationBar);
    } else if (document.readyState === 'interactive') {
        initNavigationBar();
    } else {
        // Page already fully loaded
        initNavigationBar();
    }

    // Original auto-click initialization (M365 ONLY)
    const isM365 = window.location.hostname.includes('m365.cloud.microsoft');

    if (isM365) {
        if (document.readyState === 'loading') {
            document.addEventListener('DOMContentLoaded', () => {
                setTimeout(findAndClickButton, 1000);
            });
        } else {
            setTimeout(findAndClickButton, 1000);
        }

        window.addEventListener('load', () => {
            setTimeout(findAndClickButton, 2000);
        });

        const observer = new MutationObserver((mutations) => {
            if (buttonClicked) return;
            mutations.forEach((mutation) => {
                if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
                    mutation.addedNodes.forEach((node) => {
                        if (node.nodeType === 1 && (node.tagName === 'BUTTON' || node.querySelector('button'))) {
                            setTimeout(findAndClickButton, 500);
                        }
                    });
                }
            });
        });

        observer.observe(document.body, {
            childList: true,
            subtree: true
        });

        setTimeout(() => {
            observer.disconnect();
            console.log("MutationObserver disconnected");
        }, 30000);
    }
})();