// ==UserScript== // @name 2012门户博客 - 增强白昼模式 // @namespace https://viayoo.com/29dgqe // @version 1.7.1 // @description 为2012门户博客添加白昼模式,白底黑字,链接蓝色 // @author DeepSeek // @match https://2012portal.blogspot.com/* // @match http://2012portal.blogspot.com/* // @grant GM_getValue // @grant GM_setValue // @grant GM_registerMenuCommand // @grant GM_unregisterMenuCommand // @grant GM_addStyle // @grant GM_notification // @run-at document-start // @license MIT // ==/UserScript== (function() { 'use strict'; // 配置 const CONFIG = { enabled: true, enabledByDefault: true, storageKey: 'enhancedDayModeEnabled', colors: { background: '#ffffff', text: '#000000', textLight: '#333333', link: '#0066cc', linkHover: '#004499', border: '#dddddd', codeBg: '#f5f5f5' } }; // 初始化 class EnhancedDayModeScript { constructor() { this.enabled = GM_getValue(CONFIG.storageKey, CONFIG.enabledByDefault); this.immediateStyleElement = null; this.fullStyleElement = null; this.menuCommandId = null; this.init(); } init() { // 立即应用基础样式(消除闪屏) if (this.enabled) { this.applyImmediateStyle(); } // 注册菜单命令 this.registerMenuCommand(); // 监听DOM变化,延迟应用完整样式 if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', () => { if (this.enabled) { setTimeout(() => this.applyFullEnhancedDayMode(), 50); } }); } else { if (this.enabled) { setTimeout(() => this.applyFullEnhancedDayMode(), 50); } } // 额外监听动态内容 this.observeDOMChanges(); } // 立即应用基础样式(消除闪屏) applyImmediateStyle() { if (this.immediateStyleElement) { this.immediateStyleElement.remove(); } const immediateCss = ` /* 立即应用的基础样式 - 消除闪屏 */ body { background-color: ${CONFIG.colors.background} !important; color: ${CONFIG.colors.text} !important; background: ${CONFIG.colors.background} none repeat scroll top left !important; } /* 立即移除深色变体 */ body.variant-dark, body.mobile.variant-dark { background-color: ${CONFIG.colors.background} !important; color: ${CONFIG.colors.text} !important; } /* 立即设置基础容器 */ .content-inner, .main-inner, .footer-inner { background-color: ${CONFIG.colors.background} !important; color: ${CONFIG.colors.text} !important; } /* 立即应用自动换行 */ body, div, p, span { word-wrap: break-word !important; overflow-wrap: break-word !important; white-space: normal !important; } /* 立即设置基础链接颜色 */ a:link, a:visited { color: ${CONFIG.colors.link} !important; text-decoration: none !important; } /* 立即覆盖最深色的内联样式 */ [style*="background-color: black"], [style*="background-color:#000"], [style*="background-color: #000"], [style*="background-color: #292929"], [style*="background-color:#292929"], [style*="color: white"], [style*="color:#fff"], [style*="color: #fff"] { background-color: ${CONFIG.colors.background} !important; color: ${CONFIG.colors.text} !important; } `; this.immediateStyleElement = document.createElement('style'); this.immediateStyleElement.id = 'day-mode-immediate-styles'; this.immediateStyleElement.textContent = immediateCss; document.head.appendChild(this.immediateStyleElement); } // 延迟应用完整样式 applyFullEnhancedDayMode() { if (this.fullStyleElement) { this.fullStyleElement.remove(); } const fullCss = ` /* 完整样式 - 在基础样式之后应用 */ /* 确保body类更新 */ body.variant-dark, body.mobile.variant-dark { background-color: ${CONFIG.colors.background} !important; color: ${CONFIG.colors.text} !important; } .body-fauxcolumns, .body-fauxcolumn-outer, .fauxcolumn-inner { background: transparent !important; } /* 内容区域 */ .content-outer, .main-outer, .main-fauxborder-left, .main-fauxborder-right, .content-fauxborder-left, .content-fauxborder-right { background-color: ${CONFIG.colors.background} !important; color: ${CONFIG.colors.text} !important; border-color: ${CONFIG.colors.border} !important; } /* 文章内容区域 */ .post-body, .mobile-index-contents .post-body { hyphens: auto !important; line-height: 1.6 !important; text-align: justify !important; max-width: 100% !important; overflow: hidden !important; } /* 移动端特定元素 */ .mobile-index-contents { color: ${CONFIG.colors.text} !important; background-color: ${CONFIG.colors.background} !important; } .mobile-index-title { color: ${CONFIG.colors.text} !important; } /* 文字颜色 */ h1, h2, h3, h4, h5, h6, .post-title, .post-body, .post-content, .date-header span, .date-header, .mobile-index-title, .entry-title, .description, .description span, .blog-posts .date-header span { color: ${CONFIG.colors.text} !important; } /* 文章页和主页的标题 */ .post-title.entry-title, h3.post-title.entry-title, .title, h1.title, h2.date-header span, h3.mobile-index-title, .blog-posts h3, .comments h4 { color: ${CONFIG.colors.text} !important; font-weight: bold !important; } /* 链接悬停效果 */ a:hover, a:focus { color: ${CONFIG.colors.linkHover} !important; text-decoration: none !important; opacity: 1 !important; } /* 评论链接 */ .comment-link, .mobile-index-comment a, .post-footer a, .post-author a { color: ${CONFIG.colors.link} !important; text-decoration: none !important; } .comment-link:hover, .mobile-index-comment a:hover, .post-footer a:hover, .post-author a:hover { color: ${CONFIG.colors.linkHover} !important; text-decoration: none !important; } /* 页脚链接 */ .profile-link, .g-profile, .profile-name-link { color: ${CONFIG.colors.link} !important; text-decoration: none !important; } .profile-link:hover, .g-profile:hover, .profile-name-link:hover { color: ${CONFIG.colors.linkHover} !important; text-decoration: none !important; } /* 按钮样式 */ .mobile-link-button { background-color: ${CONFIG.colors.link} !important; } .mobile-link-button a:link, .mobile-link-button a:visited { color: ${CONFIG.colors.background} !important; text-decoration: none !important; } .blog-pager-older-link, .home-link, .blog-pager-newer-link, .blog-pager a { color: ${CONFIG.colors.background} !important; background-color: ${CONFIG.colors.link} !important; text-decoration: none !important; } /* 标题区域 */ .Header h1, .Header h1 a, .title, .titlewrapper { color: ${CONFIG.colors.text} !important; background: transparent !important; text-shadow: none !important; } .description, .description span { color: ${CONFIG.colors.textLight} !important; } /* 日期头 */ .date-header span { background-color: ${CONFIG.colors.background} !important; color: ${CONFIG.colors.textLight} !important; padding: 0.1em 10px !important; margin: 0 -10px !important; } /* 页脚 */ .post-footer { background-color: #f8f8f8 !important; color: ${CONFIG.colors.textLight} !important; border-bottom: 1px solid ${CONFIG.colors.border} !important; } /* 图片容器 */ .Image img, .post-body img, .mobile-index-thumbnail img, .post-body .tr-caption-container, .Profile img, .BlogList .item-thumbnail img { background: ${CONFIG.colors.background} !important; border: 1px solid ${CONFIG.colors.border} !important; box-shadow: 1px 1px 5px rgba(0, 0, 0, 0.1) !important; } /* 分割线和边框 */ hr, .fauxborder-left, .fauxborder-right, .fauxcolumn-left-outer .fauxcolumn-inner, .fauxcolumn-right-outer .fauxcolumn-inner, .comments .comment-author, .comments .comments-content .loadmore a, .comments .continue { border-color: ${CONFIG.colors.border} !important; } /* 代码和引用 */ pre, code, blockquote { background-color: ${CONFIG.colors.codeBg} !important; color: ${CONFIG.colors.text} !important; border-left: 3px solid ${CONFIG.colors.border} !important; white-space: pre-wrap !important; word-wrap: break-word !important; } /* 阴影效果 */ .content-outer, .post-body img { box-shadow: 0 0 5px rgba(0, 0, 0, 0.05) !important; } /* 加载状态 */ body.loading { background-color: ${CONFIG.colors.background} !important; } /* 评论回复区域 */ .comment-replies, .comment-replies .comment-thread, .comment-thread.inline-thread, .comment-thread.inline-thread .comment-block, .comment-thread.inline-thread .comment-header, .comment-thread.inline-thread .comment-content, .comment-thread.inline-thread .comment-actions, #comments .comment-thread.inline-thread { background-color: ${CONFIG.colors.background} !important; color: ${CONFIG.colors.text} !important; border-color: ${CONFIG.colors.border} !important; } /* 评论回复框 */ .comment-replybox-single, .comment-replybox-thread { background-color: ${CONFIG.colors.background} !important; border-color: ${CONFIG.colors.border} !important; } /* 回复区域内的链接 */ .comment-thread.inline-thread a, .comment-replies a { color: ${CONFIG.colors.link} !important; text-decoration: none !important; } .comment-thread.inline-thread a:hover, .comment-replies a:hover { color: ${CONFIG.colors.linkHover} !important; text-decoration: none !important; } /* 回复区域的文本颜色 */ .comment-thread.inline-thread .comment-content, .comment-thread.inline-thread .comment-header, .comment-thread.inline-thread .datetime, .comment-thread.inline-thread .user { color: ${CONFIG.colors.text} !important; } /* 回复区域的边框和分割线 */ .comment-thread.inline-thread, .comment-thread.inline-thread .comment-block, .comment-thread.inline-thread .comment-header { border-top: 1px solid ${CONFIG.colors.border} !important; border-bottom: 1px solid ${CONFIG.colors.border} !important; } /* 响应式调整 */ @media (max-width: 768px) { body { padding: 0 5px 5px 5px !important; } .post-body, .mobile-index-contents .post-body { font-size: 16px !important; line-height: 1.8 !important; text-align: left !important; } .content-inner { padding: 5px !important; } } `; this.fullStyleElement = document.createElement('style'); this.fullStyleElement.id = 'day-mode-full-styles'; this.fullStyleElement.textContent = fullCss; document.head.appendChild(this.fullStyleElement); // 确保body类也更新 document.body.classList.remove('variant-dark'); document.body.classList.add('variant-light'); } // 移除所有样式 removeEnhancedDayMode() { if (this.immediateStyleElement) { this.immediateStyleElement.remove(); this.immediateStyleElement = null; } if (this.fullStyleElement) { this.fullStyleElement.remove(); this.fullStyleElement = null; } // 恢复原始类 document.body.classList.remove('variant-light'); document.body.classList.add('variant-dark'); } // 切换模式 toggleEnhancedDayMode() { this.enabled = !this.enabled; GM_setValue(CONFIG.storageKey, this.enabled); if (this.enabled) { this.applyImmediateStyle(); setTimeout(() => this.applyFullEnhancedDayMode(), 50); } else { this.removeEnhancedDayMode(); } this.updateMenuCommand(); this.showNotification( `增强白昼模式已 ${this.enabled ? '启用' : '禁用'}`, this.enabled ? 'success' : 'info' ); } // 注册菜单命令 registerMenuCommand() { if (this.menuCommandId) { try { GM_unregisterMenuCommand(this.menuCommandId); } catch (e) { // 忽略未注册错误 } } const commandName = this.enabled ? '禁用增强白昼模式' : '启用增强白昼模式'; this.menuCommandId = GM_registerMenuCommand(commandName, () => { this.toggleEnhancedDayMode(); }); } // 更新菜单命令文本 updateMenuCommand() { this.registerMenuCommand(); } // 显示通知 showNotification(message, type = 'info') { // 检查是否为Via浏览器 if (window.via && typeof window.via.toast === 'function') { // Via浏览器专属通知 window.via.toast(message); } else if (typeof GM_notification === 'function') { // 使用油猴API通知 GM_notification({ text: message, title: '增强白昼模式', timeout: 3000 }); } } // 监听DOM变化 observeDOMChanges() { const observer = new MutationObserver((mutations) => { if (this.enabled) { let shouldReapply = false; mutations.forEach(mutation => { // 检查是否有新节点添加 if (mutation.addedNodes.length > 0) { shouldReapply = true; } }); if (shouldReapply) { setTimeout(() => { if (this.enabled) { this.applyFullEnhancedDayMode(); } }, 100); } } }); observer.observe(document.body, { childList: true, subtree: true }); } } // 初始化脚本 - 立即执行 new EnhancedDayModeScript(); })();