// ==UserScript== // @name 豆包网页版 深色模式优化版 // @namespace http://tampermonkey.net/ // @version 1.2 // @description 强制豆包网页深色主题,优化性能避免页面卡死 // @author You // @match *://www.doubao.com/* // @match *://doubao.com/* // @grant none // @run-at document-start // @tag 豆包 // @tag 深色模式 // @tag 页面美化 // ==/UserScript== (function() { 'use strict'; // 1. 强制开启官方深色模式(增加判断,避免重复触发) function setOfficialDark() { const root = document.documentElement; if (root.getAttribute('data-theme') !== 'dark') { root.setAttribute('data-theme', 'dark'); } } // 2. 注入精准CSS,移除全局通配符,只覆盖核心区域 const style = document.createElement('style'); style.textContent = ` /* 根容器与页面主体背景 */ html, body, #root, .layout-wrapper, .main-container { background-color: #1e1e1e !important; color: #ffffff !important; } /* 侧边栏、聊天列表、输入区背景 */ .sidebar, .chat-container, .chat-input-wrapper, .conversation-list { background-color: #1e1e1e !important; } /* 核心文本元素统一白色(仅针对内容标签,不全局通配) */ p, span, div, label, h1, h2, h3, h4, h5, h6, li { color: #ffffff; } /* 输入框深色适配 */ textarea, input, .input-box { background-color: #2d2d2d !important; color: #ffffff !important; border-color: #444444 !important; } /* 代码块深色适配 */ pre, code, .code-block { background-color: #2d2d2d !important; color: #e0e0e0 !important; border-color: #444444 !important; } /* 按钮与卡片边框适配 */ button, .btn, .border-line, .card { background-color: #333333 !important; color: #ffffff !important; border-color: #555555 !important; } /* 滚动条深色适配 */ ::-webkit-scrollbar { width: 8px; height: 8px; background: #1e1e1e !important; } ::-webkit-scrollbar-thumb { background: #444444 !important; border-radius: 4px; } ::-webkit-scrollbar-thumb:hover { background: #555555 !important; } `; // 尽早注入样式,避免白屏闪烁 if (document.head) { document.head.appendChild(style); } else { document.addEventListener('DOMContentLoaded', () => { document.head.appendChild(style); }); } // 3. 优化监听逻辑,防止重复设置和死循环 setOfficialDark(); const observer = new MutationObserver(() => { // 仅当主题被改为非dark时才重新设置,大幅减少触发次数 if (document.documentElement.getAttribute('data-theme') !== 'dark') { setOfficialDark(); } }); observer.observe(document.documentElement, { attributes: true, attributeFilter: ['data-theme'] }); // 4. 适配单页应用路由切换 window.addEventListener('popstate', setOfficialDark); })();