Greasy Fork

来自缓存

Greasy Fork is available in English.

MiMo AI Studio - 自动隐藏侧边栏

自动隐藏 MiMo AI Studio 侧边栏,CSS 注入防止闪烁,一次点击同步 React 状态

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         MiMo AI Studio - 自动隐藏侧边栏
// @namespace    https://aistudio.xiaomimimo.com/
// @version      1.0.0
// @description  自动隐藏 MiMo AI Studio 侧边栏,CSS 注入防止闪烁,一次点击同步 React 状态
// @author       XforceRyan
// @match        https://aistudio.xiaomimimo.com/*
// @license      MIT
// @run-at       document-start
// @grant        none
// ==/UserScript==


(function () {
  'use strict';

  // ===== Phase 1: 在 React 渲染前注入 CSS,立即隐藏侧边栏 =====
  // 选择器精确匹配:主 flex 容器的第一个 z-[49] 子元素(即侧边栏)
  const style = document.createElement('style');
  style.id = 'mimo-sidebar-auto-hide';
  style.textContent = `
    /* 强制侧边栏容器宽度为 0 */
    .flex.flex-1.overflow-hidden > .relative.z-\\[49\\]:first-child {
      width: 0 !important;
      min-width: 0 !important;
      overflow: hidden !important;
    }
    /* 内容面板滑出可视区域 */
    .flex.flex-1.overflow-hidden > .relative.z-\\[49\\]:first-child > .flex {
      transform: translateX(100%) !important;
    }
  `;
  (document.head || document.documentElement).appendChild(style);

  // ===== Phase 2: React 渲染后,点击按钮同步状态,然后移除 CSS 覆盖 =====
  let done = false;

  function syncState() {
    if (done) return;
    const btn = document.querySelector('[aria-label="Hide sidebar"]');
    if (!btn) return;

    done = true;
    btn.click();
    // React 现在接管了侧边栏状态,移除 CSS 覆盖
    style.remove();
  }

  // 轮询等待 React 完成渲染
  const timer = setInterval(() => {
    syncState();
    if (done) clearInterval(timer);
  }, 300);

  // 兜底:10 秒后无论如何清理
  setTimeout(() => {
    clearInterval(timer);
    if (!done) style.remove();
  }, 10000);
})();