// ==UserScript== // @name 微信读书沉浸式阅读(上下滚动模式 + 主题切换) // @namespace http://github.com/lossj // @version 1.0.3 // @description 微信读书上划隐藏头部和侧栏,下滑显示,同时自定义字体、字号、背景色、字体色、页面宽度、导航和菜单,支持通过油猴菜单切换主题 // @icon https://i.miji.bid/2025/03/08/990e81d6e8ebc90d181e091cc0c99699.jpeg // @author LossJ // @match https://weread.qq.com/web/reader/* // @require https://code.jquery.com/jquery-3.3.1.min.js // @grant GM_setValue // @grant GM_getValue // @grant GM_registerMenuCommand // @license MIT // @downloadURL none // ==/UserScript== (function() { 'use strict'; // 定义主题对象 const themes = { '极光灰': { background: '#E0E0E0', fontColor: '#222222' }, '浅咖色': { background: '#FAEBD7', fontColor: '#222222' }, '米黄色': { background: '#F5F5DC', fontColor: '#332222' }, '豆沙绿': { background: '#E6F5E6', fontColor: '#223322' }, '海天蓝': { background: '#EBF5FF', fontColor: '#222266' }, '夜间深灰色': { background: '#282828', fontColor: '#C8C8C8' } }; // 获取或设置当前主题 const currentTheme = GM_getValue('currentTheme', '豆沙绿'); // 默认主题为豆沙绿 // 自定义样式 const customStyle = ` /* 阅读区域的样式 */ .readerContent, .app_content, .readerChapterContent { font-family: "霞鹜文楷", "PingFang SC", "宋体", sans-serif !important; font-size: 18px !important; /* 字号 */ color: ${themes[currentTheme].fontColor} !important; /* 主题颜色*/ background-color: ${themes[currentTheme].background} !important; max-width: 1200px !important; margin: 0 auto !important; padding: 20px !important; } /* 正文内容的样式 */ .readerChapterContent p, .readerChapterContent div, .readerChapterContent span { font-family: inherit !important; font-size: inherit !important; color: inherit !important; /* 继承阅读内容字体颜色 */ } /* 整体页面背景 */ body, html { background-color: ${themes[currentTheme].background} !important; } /* 顶部导航区域加宽 */ .readerTopBar, .navBar { max-width: 1300px !important; width: 100% !important; margin: 0 auto !important; left: 0 !important; right: 0 !important; position: relative !important; transition: opacity 0.3s ease !important; /* 平滑过渡效果 */ } /* 右侧菜单调整 */ .readerControls, .readerCatalog { position: fixed !important; left: 1000px !important; /* right效果不行 */ bottom: 200px !important; transform: none !important; transition: opacity 0.3s ease !important; /* 平滑过渡效果 */ } /* 画线菜单字体颜色和字号 */ .reader_toolbar_container .toolbarItem { color: #ffffff !important; /* 强制按钮文字为白色 */ font-size: 14px !important; /* 字号14px */ } /* 确保字体全局生效 */ * { font-family: "霞鹜文楷", "PingFang SC", "宋体", sans-serif !important; } `; // 应用自定义样式 const styleSheet = document.createElement('style'); styleSheet.type = 'text/css'; styleSheet.innerText = customStyle; document.head.appendChild(styleSheet); // 沉浸式阅读功能:上划隐藏,下滑显示 var windowTop = 0; $(window).scroll(function() { let scrollS = $(window).scrollTop(); let selBtn = document.querySelector('.readerTopBar'); let readerControl = document.querySelector(".readerControls"); if (scrollS >= windowTop) { // 上划隐藏 if (selBtn) selBtn.style.opacity = 0; if (readerControl) readerControl.style.opacity = 0; windowTop = scrollS; } else { // 下滑显示 if (selBtn) selBtn.style.opacity = 1; if (readerControl) readerControl.style.opacity = 1; windowTop = scrollS; } }); // 注册主题切换菜单 Object.keys(themes).forEach(theme => { GM_registerMenuCommand(`切换到 ${theme}`, () => { GM_setValue('currentTheme', theme); location.reload(); // 刷新页面应用新主题 }); }); })();