Claude Auto Expand Sidebar

Automatically expand Claude's sidebar when the page loads

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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);
    }
})();