Claude Auto Expand Sidebar

Automatically expand Claude's sidebar when the page loads

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Claude Auto Expand Sidebar
// @namespace    https://github.com/neura-neura/userscripts
// @version      2025.11.24
// @description  Automatically expand Claude's sidebar when the page loads
// @author       neura-neura
// @match        https://claude.ai/*
// @grant        none
// @run-at       document-idle
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Function to locate and click the sidebar button
    function expandSidebar() {
        // Look for the button by its data-testid attribute
        const sidebarToggleButton = document.querySelector('[data-testid="pin-sidebar-toggle"]');

        // If the button is found and the sidebar is closed (width: 3.05rem)
        if (sidebarToggleButton) {
            const sidebar = document.querySelector('.fixed.z-sidebar');
            if (sidebar && sidebar.style.width === '3.05rem') {
                // Simulate a click on the button
                sidebarToggleButton.click();
                console.log('Sidebar expanded automatically');
            }
        } else {
            // If the button is not found, try again after a short delay
            setTimeout(expandSidebar, 1000);
        }
    }

    // Wait until the page fully loads and run with a small delay
    window.addEventListener('load', function() {
        // Small delay to ensure all elements are loaded
        setTimeout(expandSidebar, 1000);
    });

    // As a fallback, also try after the DOM is ready
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', function() {
            setTimeout(expandSidebar, 1000);
        });
    } else {
        setTimeout(expandSidebar, 1000);
    }
})();