踩蘑菇隐藏侧边栏

2025/4/21 11点49分

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        踩蘑菇隐藏侧边栏
// @namespace   Violentmonkey Scripts
// @match       https://www.caimogu.cc/*
// @grant       none
// @version   1.21
// @author      希尔薇
// @description 2025/4/21 11点49分
// @license MIT
// ==/UserScript==


(function() {
    'use strict';

    // 等待页面加载完成
    window.addEventListener('load', function() {
        // 获取具有指定 class 的 div 元素
        const sidebar = document.querySelector('.sidebar.simple');

        // 获取 search-bar 的父元素
        const searchBarParent = document.querySelector('.info.simple');
        const searchBar = searchBarParent?.querySelector('.search-bar');

        if (sidebar && searchBar) {
            // 创建按钮
            const toggleButton = document.createElement('button');
            toggleButton.textContent = '隐藏侧边栏';

            // 设置按钮样式
            toggleButton.style.marginRight = '10px';
            toggleButton.style.padding = '8px 16px';
            toggleButton.style.backgroundColor = '#007BFF';
            toggleButton.style.color = 'white';
            toggleButton.style.border = 'none';
            toggleButton.style.borderRadius = '4px';
            toggleButton.style.cursor = 'pointer';
            toggleButton.style.transition = 'background-color 0.3s ease';

            // 鼠标悬停样式
            toggleButton.addEventListener('mouseover', function() {
                toggleButton.style.backgroundColor = '#0056b3';
            });

            // 鼠标移开样式
            toggleButton.addEventListener('mouseout', function() {
                toggleButton.style.backgroundColor = '#007BFF';
            });

            // 按钮点击事件处理函数
            toggleButton.addEventListener('click', function() {
                if (sidebar.style.display === 'none') {
                    sidebar.style.display = '';
                    toggleButton.textContent = '隐藏侧边栏';
                } else {
                    sidebar.style.display = 'none';
                    toggleButton.textContent = '显示侧边栏';
                }
            });

            // 将按钮插入到 search-bar 之前
            searchBarParent.insertBefore(toggleButton, searchBar);
        }
    });
})();