AI Conversation Navigator

Floating navigator for your prompts in conversations. Applied for ChatGPT, Gemini, Aistudio, NotebookLM, Grok, Claude, Mistral, Perplexity, Meta, Poe, Deepai, Huggingface, Deepseek, Kimi, Qwen, Manus, Z.ai, Longcat, Chatglm, Chatboxai, Lmarena, Spacefrontiers, Scienceos, Evidencehunt, Playground (allen), Paperfigureqa (allen), Scira, Scispace, Exa.ai, Consensus, Openevidence, Pathway, Math-gpt.

Чтобы установить этот скрипт, вы сначала должны установить расширение браузера, например Tampermonkey, Greasemonkey или Violentmonkey.

Для установки этого скрипта вам необходимо установить расширение, такое как Tampermonkey.

Чтобы установить этот скрипт, вы сначала должны установить расширение браузера, например Tampermonkey или Violentmonkey.

Чтобы установить этот скрипт, вы сначала должны установить расширение браузера, например Tampermonkey или Userscripts.

Чтобы установить этот скрипт, сначала вы должны установить расширение браузера, например Tampermonkey.

Чтобы установить этот скрипт, вы должны установить расширение — менеджер скриптов.

(у меня уже есть менеджер скриптов, дайте мне установить скрипт!)

Чтобы установить этот стиль, сначала вы должны установить расширение браузера, например Stylus.

Чтобы установить этот стиль, сначала вы должны установить расширение браузера, например Stylus.

Чтобы установить этот стиль, сначала вы должны установить расширение браузера, например Stylus.

Чтобы установить этот стиль, сначала вы должны установить расширение — менеджер стилей.

Чтобы установить этот стиль, сначала вы должны установить расширение — менеджер стилей.

Чтобы установить этот стиль, сначала вы должны установить расширение — менеджер стилей.

(у меня уже есть менеджер стилей, дайте мне установить скрипт!)

// ==UserScript==
// @name         AI Conversation Navigator
// @namespace    https://greasyfork.org
// @version      6.0
// @description  Floating navigator for your prompts in conversations. Applied for ChatGPT, Gemini, Aistudio, NotebookLM, Grok, Claude, Mistral, Perplexity, Meta, Poe, Deepai, Huggingface, Deepseek, Kimi, Qwen, Manus, Z.ai, Longcat, Chatglm, Chatboxai, Lmarena, Spacefrontiers, Scienceos, Evidencehunt, Playground (allen), Paperfigureqa (allen), Scira, Scispace, Exa.ai, Consensus, Openevidence, Pathway, Math-gpt.
// @author       Bui Quoc Dung
// @match        https://chatgpt.com/*
// @match        https://gemini.google.com/*
// @match        https://aistudio.google.com/*
// @match        https://notebooklm.google.com/*
// @match        https://grok.com/*
// @match        https://claude.ai/*
// @match        https://www.kimi.com/*
// @match        https://chat.mistral.ai/*
// @match        https://www.perplexity.ai/*
// @match        https://www.meta.ai/*
// @match        https://poe.com/*
// @match        https://deepai.org/*
// @match        https://huggingface.co/chat/*
// @match        https://chat.deepseek.com/*
// @match        https://chat.qwen.ai/*
// @match        https://manus.im/*
// @match        https://chat.z.ai/*
// @match        https://longcat.chat/*
// @match        https://chatglm.cn/*
// @match        https://web.chatboxai.app/*
// @match        https://lmarena.ai/*
// @match        https://spacefrontiers.org/*
// @match        https://app.scienceos.ai/*
// @match        https://evidencehunt.com/*
// @match        https://playground.allenai.org/*
// @match        https://paperfigureqa.allen.ai/*
// @match        https://scira.ai/*
// @match        https://scispace.com/*
// @match        https://exa.ai/*
// @match        https://consensus.app/*
// @match        https://www.openevidence.com/*
// @match        https://www.pathway.md/*
// @match        https://math-gpt.org/*
// @grant        GM_addStyle
// @license      MIT
// ==/UserScript==

(function () {
    'use strict';

    // --- 1. SETTINGS & CONSTANTS ---
    const NAV_WIDTH = 250;
    const NAV_COLLAPSED_WIDTH = 80;
    let activeMessageIndex = -1;

    // --- 2. HELPER FUNCTIONS FOR SPECIFIC SITES ---
    function getAIStudioData() {
        const prompts = [];
        const scrollButtons = document.querySelectorAll('ms-prompt-scrollbar button[id^="scrollbar-item-"]');
        scrollButtons.forEach(btn => {
            const isUser = btn.querySelector('.prompt-scrollbar-dot');
            if (isUser) {
                const text = btn.getAttribute('aria-label');
                if (text) {
                    prompts.push({
                        element: btn,
                        text: text.trim()
                    });
                }
            }
        });
        return prompts;
    }

    // --- 3. SITE CONFIGURATION REPOSITORY ---
    const SITE_CONFIGS = {
        chatgpt: {
            domain: 'chatgpt.com',
            promptSelector: 'div[data-message-author-role="user"]',
            top: '55px',
            shiftTarget: 'div[data-scroll-root="true"]'
        },
        gemini: {
            domain: 'gemini.google.com',
            promptSelector: '.query-text',
            top: '55px',
            shiftTarget: 'chat-app, .boqOnegoogleliteOgbOneGoogleBar, top-bar-actions'
        },
        aistudio: {
            domain: 'aistudio.google.com',
            customFinder: getAIStudioData,
            top: '55px',
            useClick: true,
            shiftTarget: '.layout-wrapper'
        },
        notebooklm: {
            domain: 'notebooklm.google.com',
            promptSelector: 'chat-message .from-user-container',
            top: '55px',
            shiftTarget: 'notebook, .boqOnegoogleliteOgbOneGoogleBar'
        },
        grok: {
            domain: 'grok.com',
            promptSelector: '.relative.group.flex.flex-col.justify-center.items-end',
            top: '55px'
        },
        claude: {
            domain: 'claude.ai',
            promptSelector: 'div.group.relative.inline-flex',
            top: '55px'
        },
        mistral: {
            domain: 'chat.mistral.ai',
            promptSelector: 'div[data-message-author-role="user"]',
            top: '55px',
            shiftTarget: 'main.bg-sidebar-subtle'
        },
        perplexity: {
            domain: 'perplexity.ai',
            promptSelector: 'div.group\\/title',
            top: '55px'
        },
        meta: {
            domain: 'meta.ai',
            promptSelector: '.x78zum5.x15zctf7',
            top: '55px'
        },
        poe: {
            domain: 'poe.com',
            promptSelector: '[class*="ChatMessagesView_tupleGroupContainer"] > div > div:first-child',
            top: '55px',
            shiftTarget: '[class*="CanvasSidebarLayout_chat-column"]'
        },
        deepai: {
            domain: 'deepai.org',
            promptSelector: '.chatbox',
            top: '55px',
            shiftTarget: '.chat-layout-container, .new-chat-button-container, .persistent-compose-area'
        },
        huggingface: {
            domain: 'huggingface.co',
            promptSelector: '.disabled.w-full.appearance-none',
            top: '55px',
            shiftTarget: '.relative.min-h-0.min-w-0'
        },
        deepseek: {
            domain: 'chat.deepseek.com',
            promptSelector: '#root > div > div > div:nth-child(2) > div:nth-child(3) > div > div:nth-child(2) > div > div:nth-child(2) > div:nth-child(1) > div:nth-child(odd)',
            top: '55px',
            shiftTarget: '#root > div > div > div:nth-child(2) > div:nth-child(3) > div > div:nth-child(2) > div'
        },
        kimi: {
            domain: 'www.kimi.com',
            promptSelector: '.user-content',
            top: '55px'
        },
        glm: {
            domain: 'chat.z.ai',
            promptSelector: '.chat-user',
            top: '55px'
        },
        qwen: {
            domain: 'chat.qwen.ai',
            promptSelector: '.chat-user-message',
            top: '55px',
            shiftTarget: '.desktop-layout-content'
        },
        manus: {
            domain: 'manus.im',
            promptSelector: '.flex.relative.flex-col.gap-2.items-end',
            top: '55px'
        },
        longcat: {
            domain: 'longcat.chat',
            promptSelector: '.user-message',
            top: '55px',
            shiftTarget: '.page-container'
        },
        chatglm: {
            domain: 'chatglm.cn',
            promptSelector: '.question-txt.dots',
            top: '55px'
        },
        chatboxai: {
            domain: 'web.chatboxai.app',
            promptSelector: '.user-msg',
            top: '55px'
        },
        lmarena: {
            domain: 'lmarena.ai',
            promptSelector: '.justify-end.gap-2',
            top: '55px'
        },
        spacefrontiers: {
            domain: 'spacefrontiers.org',
            promptSelector: '.inline.whitespace-pre-line',
            top: '55px'
        },
        scienceos: {
            domain: 'app.scienceos.ai',
            promptSelector: 'div[data-prompt]',
            top: '55px',
            shiftTarget: 'div[data-strategy]'
        },
        evidencehunt: {
            domain: 'evidencehunt.com',
            promptSelector: '.chat__message:has(.message__user-image) .message__content p',
            top: '55px',
            shiftTarget: '.v-main'
        },
        playground: {
            domain: 'playground.allenai.org',
            promptSelector: 'div[class*="chat-message"]:nth-of-type(even)',
            top: '55px',
            shiftTarget: '.MuiPaper-outlined'
        },
        paperfigure: {
            domain: 'paperfigureqa.allen.ai',
            promptSelector: '#chat-scroll-container > div > div:nth-of-type(odd) .MuiPaper-root',
            top: '55px'
        },
        scira: {
            domain: 'scira.ai',
            promptSelector: '.max-w-full .relative',
            top: '55px',
            shiftTarget: '.sm\\:max-w-2xl'
        },
        scispace: {
            domain: 'scispace.com',
            promptSelector: '.max-w-lg',
            top: '55px'
        },
        exa: {
            domain: 'exa.ai',
            promptSelector: 'div[data-test-id="UserMessage"]',
            top: '55px',
            shiftTarget: 'div[data-test-id="ChatPresentation"]'
        },
        consensus: {
            domain: 'consensus.app',
            promptSelector: '.flex.flex-col.pt-6.w-full.max-w-page h2',
            top: '55px'
        },
        openevidence: {
            domain: 'openevidence.com',
            promptSelector: '.brandable--query-bar--container form',
            top: '55px',
            shiftTarget: '#__next, .brandable--query-bar--container.hide-on-print.follow-up'
        },
        pathway: {
            domain: 'pathway.md',
            promptSelector: '[id] > div > div > div .chakra-text',
            top: '55px'
        },
        mathgpt: {
            domain: 'math-gpt.org',
            promptSelector: '.w-full.flex.items-end.flex-col.pb-8.relative',
            top: '55px',
            shiftTarget: '.overflow-x-hidden, .px-2.flex.flex-col.gap-1'
        }
    };

    // --- 4. CONFIG DETECTION LOGIC ---
    function getCurrentConfig() {
        const hostname = window.location.hostname;
        for (const key in SITE_CONFIGS) {
            if (hostname.includes(SITE_CONFIGS[key].domain)) {
                console.log(`[AI Navigator] Detected site: ${key}`);
                return SITE_CONFIGS[key];
            }
        }
        return null;
    }

    const CURRENT_SITE = getCurrentConfig();
    if (!CURRENT_SITE) {
        console.log('[AI Navigator] Site not supported or configured.');
        return;
    }

    // --- 5. STYLE & CSS GENERATION ---
    const BASE_CONTAINER_CSS = `
        right: 0px; width: ${NAV_WIDTH}px; max-height: 90vh; overflow-y: auto;
        z-index: 9999;
        transition: width 0.3s, padding 0.3s, opacity 0.3s, transform 0.3s;
        font-family: Calibri, sans-serif; font-size: 17px; color: CanvasText; position: fixed;text-align: left;
    `;

    const getShiftStyle = (width, selector = '') => {
        if (!selector) return '';
        const selectors = selector.split(',');
        const prefixedSelector = selectors.map(s => `body.navigator-expanded ${s.trim()}`).join(', ');
        return `
            ${selector} {
                transition: margin-right 0.3s ease, max-width 0.3s ease, margin-left 0.3s ease;
            }
            ${prefixedSelector} {
                margin-left: 0 !important;
                margin-right: ${width}px !important;
                max-width: calc(100% - ${width}px) !important;
            }
        `;
    };

    GM_addStyle(`
        .nav-list-item { font-weight: normal; transition: font-weight 0.1s ease; }
        .nav-list-item.active { font-weight: bold !important; background-color: rgba(0, 0, 0, 0.05); }
    `);

    const currentWidth = CURRENT_SITE.width || NAV_WIDTH;
    GM_addStyle(getShiftStyle(currentWidth, CURRENT_SITE.shiftTarget || ''));

    // --- 6. CORE LOGIC ---
    let conversationObserver = null;
    let isCollapsed = false;
    window.navigatorUpdateTimeout = null;

    function updateBodyClassForLayout() {
        const container = document.getElementById('message-nav');
        const content = document.getElementById('message-nav-content');
        if (container && content && content.style.display !== 'none') {
            document.body.classList.add('navigator-expanded');
        } else {
            document.body.classList.remove('navigator-expanded');
        }
    }

    function createContainer() {
        let container = document.getElementById('message-nav');
        if (!container) {
            container = document.createElement('div');
            container.id = 'message-nav';
            container.style.cssText = `top: ${CURRENT_SITE.top}; ${BASE_CONTAINER_CSS}`;
            const header = document.createElement('div');
            Object.assign(header.style, {
                display: 'flex', alignItems: 'center', justifyContent: 'center',
                cursor: 'pointer', fontWeight: 'bold'
            });

            const toggleBtn = document.createElement('button');
            Object.assign(toggleBtn.style, {
                background: 'none', border: 'none', cursor: 'pointer',
                fontSize: '18px', color: 'inherit'
            });
            toggleBtn.textContent = 'Close';
            header.appendChild(toggleBtn);

            const content = document.createElement('div');
            content.id = 'message-nav-content';
            content.style.padding = '5px';

            container.appendChild(header);
            container.appendChild(content);
            document.body.appendChild(container);

            const toggleHandler = (e) => {
                e.stopPropagation();
                isCollapsed = !isCollapsed;
                if (!isCollapsed) {
                    content.style.display = 'block';
                    container.style.width = `${currentWidth}px`;
                    toggleBtn.textContent = 'Close';
                } else {
                    content.style.display = 'none';
                    container.style.width = `${NAV_COLLAPSED_WIDTH}px`;
                    toggleBtn.textContent = 'Open';
                }
                updateBodyClassForLayout();
            };

            toggleBtn.addEventListener('click', toggleHandler);
            updateBodyClassForLayout();
        }
        return container;
    }

    function findUserPrompts() {
        if (CURRENT_SITE.customFinder) {
            return CURRENT_SITE.customFinder();
        }

        const prompts = [];
        if (!CURRENT_SITE.promptSelector) return prompts;

        const elements = document.querySelectorAll(CURRENT_SITE.promptSelector);
        elements.forEach((element) => {
            const text = element.textContent.trim();
            if (text) prompts.push({ element, text });
        });

        return prompts;
    }

    function createListItem(prompt, index) {
        const listItem = document.createElement('li');
        const preview = prompt.text.length > 80 ? prompt.text.slice(0, 80) + '...' : prompt.text;
        listItem.textContent = `${index}. ${preview}`;

        Object.assign(listItem.style, {
            cursor: 'pointer', padding: '5px 0px 5px 5px'
        });
        listItem.classList.add('nav-list-item');
        if (index === activeMessageIndex) {
            listItem.classList.add('active');
        }

        listItem.addEventListener('click', () => {
            listItem.parentElement.querySelectorAll('.nav-list-item').forEach(li => li.classList.remove('active'));
            listItem.classList.add('active');
            activeMessageIndex = index;

            if (CURRENT_SITE.useClick) {
                prompt.element.click();
            } else {
                prompt.element.scrollIntoView({ behavior: 'smooth', block: 'start' });
            }
        });

        return listItem;
    }

    function updateMessageList() {
        const container = createContainer();
        const content = document.getElementById('message-nav-content');
        if (!content) return;

        let list = content.querySelector('ul');
        if (!list) {
            list = document.createElement('ul');
            list.style.cssText = 'padding: 0; margin: 0; list-style: none;';
            content.appendChild(list);
        }


        const prompts = findUserPrompts();
        while (list.firstChild) {
            list.removeChild(list.firstChild);
        }

        if (prompts.length === 0) {
            activeMessageIndex = -1;
            const noContent = document.createElement('div');
            noContent.textContent = 'Loading...';
            noContent.style.cssText = 'color: #999; font-style: italic; text-align: center; padding: 15px 0;';
            list.appendChild(noContent);
            return;
        }

        prompts.forEach((prompt, index) => {
            const listItem = createListItem(prompt, index + 1);
            list.appendChild(listItem);
        });
    }

    function observeConversation() {
        if (conversationObserver) conversationObserver.disconnect();

        conversationObserver = new MutationObserver(() => {
            clearTimeout(window.navigatorUpdateTimeout);
            window.navigatorUpdateTimeout = setTimeout(() => {
                updateMessageList();
            }, 501);
        });

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

    // --- 7. INITIALIZATION ---
    setTimeout(() => updateMessageList(), 1000);
    observeConversation();

})();