// ==UserScript== // @name 夜间护眼助手 // @namespace Local // @version 5.5.2 // @description 全网通用夜间护眼助手,支持夜间模式、墨黑模式和滤镜模式,传统设置版(仅特殊网站使用专门规则) // @match *://*/* // @run-at document-start // @grant GM_getValue // @grant GM_setValue // @grant GM_registerMenuCommand // @grant GM_unregisterMenuCommand // @icon data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMjggMTI4Ij48cGF0aCBkPSJNOTMuNSA5NC1WjEwLjYgMCAyMC4zLTMuMyAyOC4yLTktOC4zIDIyLjUtMzAuMiAzOC6LTU2IDM4LjYtMzIuNyAwLTU5LjMtMjUuOC01OS4zLTU3LjdTMzIuOSA4LjcgNjUuNyA4LjdoMi4yQzU0LjYgMTcgNDUuNyAzMS41IDQ1LjcgNDhjMCAyNS43IDI1LjcgNDYuNiA1Mi4xIDQ2LjZ6IiBmaWxsPSIjZmZiNTc4Ii8+PHBhdGggZD0iTTEyMS42IDgxLjhjLS44IDAtMS42LjItMi4zLjctNy41IDUuMy0xNi41IDguMS0yNS44IDguMS0yNC4yIDAtNDMuOS0xOS4lLTQzLUtI9mmgxMy43YzEuNiAwIDIuOSAxLjMgMi45IDIuOXMtMS4zIDIuOS0yLjkgMi45em0xMy4yLTMxLjFoLTE0LjRjLTEuNiAwLTIuOS0xLjMtMi45LTIuOSAwLTEgLjQtMS45IDEuMi0yLjRsNi4yLTQuMWgtNC43YzEuNiAwIDIuOSAxLjMgMi45IDIuOXMtMS4yIDIuOS0yLjggMi45eiIgZmlsbD0iIzQ0NCIvPjwvc3ZnPg== // ==/UserScript== ;(function () { 'use strict'; // 存储所有菜单命令ID let menuCommands = []; let EyeProtect = { // 当前模式存储 currentMode: null, // 默认配置 defaults: { globalEnable: false, // 全局开关 enableList: [], // 启用列表(白名单) blacklist: [], // 禁用列表(黑名单) autoExclude: true, // 智能排除 forcedEnableList: [], // 强制启用列表 originThemeColor: '#ffffff', // 原始主题色 runDuringDay: true, // 白天保持开启 darkAuto: false, // 跟随浏览器暗色模式 customDayNight: '6:00|18:00', // 自定义昼夜时间 autoSwitch: '', // 自动切换模式 customDark1: '60|50', // 亮度模式设置 customDark2: '60|40|50|50', // 暖色模式设置 customDark3: '90', // 反色模式设置 dark3Exclude: 'img, .img, video, [style*="background"][style*="url"], svg, .video-player, .player, [class*="player"], [class*="Player"], [id*="player"], [id*="Player"], .plyr, .jw-player, .video-js', // 排除元素 inkModeConfig: '#343c3e|#ffffff|#4a5457|#5d696c|#009688|#26a69a', filterExcludeList: ['youku.com', 'v.youku.com', 'www.douyu.com', 'www.iqiyi.com', 'vip.iqiyi.com', 'mail.qq.com', 'live.kuaishou.com'], // 滤镜模式排除列表 siteSpecificModes: '{}' // 网站专用模式 }, // 初始化 init() { this.initConfig(); // 获取当前模式,修复可能的模式错误 this.fixModeIssue(); // 立即应用基础样式(不等待DOM加载) this.applyImmediateMode(); // 延迟保存原始主题色 setTimeout(() => this.saveOriginThemeColor(), 1000); this.initMenu(); // 监听系统主题变化 if (window.matchMedia) { window.matchMedia('(prefers-color-scheme: dark)').addListener(() => { this.applyMode(); this.refreshMenu(); }); } // 监听全屏变化(用于滤镜模式) document.addEventListener("fullscreenchange", () => this.handleFullscreenChange()); document.addEventListener("webkitfullscreenchange", () => this.handleFullscreenChange()); document.addEventListener("mozfullscreenchange", () => this.handleFullscreenChange()); // 等待DOM加载完成后应用完整模式 if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', () => { setTimeout(() => { this.applyMode(); // 监听页面动态加载 this.observeDOMChanges(); }, 100); }); } else { setTimeout(() => { this.applyMode(); this.observeDOMChanges(); }, 100); } }, // 处理全屏变化 handleFullscreenChange() { if (this.isFullscreen()) { // 进入全屏时禁用滤镜模式 if (this.currentMode === 'filter') { this.disableFilterMode(); } } else { // 退出全屏时恢复滤镜模式 if (this.currentMode === 'filter' && this.shouldApplyMode()) { setTimeout(() => this.applyFilterMode(), 100); } } }, // 判断是否全屏 isFullscreen() { return document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement; }, // 立即应用基础模式(在DOM加载前执行) applyImmediateMode() { // 检查是否为123云盘域名 let hostname = window.location.hostname; let is123Pan = hostname.includes('123pan.com') || hostname.includes('123865.com') || hostname.includes('123pan.cn'); // 检查是否应该应用模式 if (is123Pan && this.shouldApplyMode()) { // 为123云盘立即应用基础墨黑样式 this.apply123PanImmediateMode(); } }, // 为123云盘立即应用基础墨黑模式(在DOM加载前) apply123PanImmediateMode() { // 使用墨黑模式的背景色 let config = this.getConfig('inkModeConfig').split('|'); let backgroundColor = config[0] || '#343c3e'; let textColor = config[1] || '#ffffff'; // 创建立即执行的样式 let style = document.createElement('style'); style.id = 'eye-protect-immediate-123pan'; style.innerHTML = ` /* 123云盘立即模式 - 墨黑背景 */ html, body { background-color: ${backgroundColor} !important; color: ${textColor} !important; } /* 确保所有基础元素都有背景色 */ div, section, main, article, nav, header, footer, aside, .app, #app, #root, .root, .container, .wrapper { background-color: ${backgroundColor} !important; color: ${textColor} !important; } /* 防止闪烁的过渡效果 */ * { transition: none !important; } `; // 立即插入到head中 if (document.head) { document.head.appendChild(style); } else { // 如果head不存在,直接插入到document document.documentElement.appendChild(style); } // 标记body以便后续处理 setTimeout(() => { if (document.body) { document.body.setAttribute('data-eye-protect-immediate', 'enabled'); } }, 50); // 等待DOM加载完成后再移除立即样式,应用完整样式 const waitForDOM = () => { if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', () => { setTimeout(() => { this.removeImmediateStyle(); }, 300); }); } else { setTimeout(() => { this.removeImmediateStyle(); }, 300); } }; waitForDOM(); }, // 移除立即样式 removeImmediateStyle() { let immediateStyle = document.querySelector('#eye-protect-immediate-123pan'); if (immediateStyle) { immediateStyle.remove(); } }, // 修复模式问题:确保模式正确 fixModeIssue() { let storedMode = this.getConfig('currentMode'); // 全局切换中只包含light, dark, ink三种模式 const validGlobalModes = ['light', 'dark', 'ink']; // 如果存储的模式不是有效模式,重置为light if (!validGlobalModes.includes(storedMode)) { this.setConfig('currentMode', 'light'); this.currentMode = 'light'; } else { this.currentMode = storedMode; } }, // 初始化配置 initConfig() { for (let key in this.defaults) { let value = GM_getValue(key); if (value === undefined) { GM_setValue(key, this.defaults[key]); } } // 初始化当前模式 if (GM_getValue('currentMode') === undefined) { GM_setValue('currentMode', 'light'); this.currentMode = 'light'; } }, // 获取配置值 getConfig(key) { return GM_getValue(key); }, // 设置配置值 setConfig(key, value) { GM_setValue(key, value); }, // 保存原始主题色 saveOriginThemeColor() { let meta = document.querySelector('meta[name="theme-color"]'); if (meta && meta.content) { this.setConfig('originThemeColor', meta.content); } }, // 监听DOM变化(用于动态加载的页面) observeDOMChanges() { const observer = new MutationObserver((mutations) => { // 检查是否需要重新应用模式 let style = document.querySelector('style[id^="eye-protect-"]'); if (!style && this.shouldApplyMode()) { setTimeout(() => this.applyMode(), 100); } // 对特定网站特别处理 let hostname = window.location.hostname; if (hostname.includes('123pan.com') || hostname.includes('123865.com') || hostname.includes('123pan.cn') || hostname.includes('github.com') || hostname.includes('hemudu.cc') || hostname.includes('bilivod.com') || hostname.includes('lanzou') || hostname.includes('scriptcat.org')) { // 检查是否已有样式 let hasStyle = document.querySelector('style[id^="eye-protect-"]'); if (!hasStyle && this.shouldApplyMode()) { setTimeout(() => this.applyMode(), 300); } } }); // 监听整个文档树的变化 observer.observe(document.documentElement, { childList: true, subtree: true, attributes: true, attributeFilter: ['class', 'style', 'id'] }); }, // 判断是否为白天 isDaytime() { let time = this.getConfig('customDayNight').split('|'); let now = new Date(); let currentTime = now.getHours() * 60 + now.getMinutes(); let dayStart = this.timeToMinutes(time[0]); let dayEnd = this.timeToMinutes(time[1]); if (dayStart < dayEnd) { return currentTime >= dayStart && currentTime < dayEnd; } else { return currentTime >= dayStart || currentTime < dayEnd; } }, timeToMinutes(timeStr) { let parts = timeStr.split(':'); return parseInt(parts[0]) * 60 + parseInt(parts[1] || 0); }, // 获取当前应该应用的模式 getCurrentMode() { // 首先检查网站专用模式(最高优先级) let siteSpecificMode = this.getSiteSpecificMode(); if (siteSpecificMode && siteSpecificMode !== 'default') { return siteSpecificMode; } // 确保只有有效模式 let mode = this.currentMode || this.getConfig('currentMode'); // 全局切换中只包含light, dark, ink三种模式 const validGlobalModes = ['light', 'dark', 'ink']; if (!validGlobalModes.includes(mode)) { mode = 'light'; this.setConfig('currentMode', 'light'); } // 如果启用了自动切换 if (this.getConfig('autoSwitch')) { let modes = this.getConfig('autoSwitch').split('|'); if (modes.length === 2) { if (this.isDaytime()) { mode = modes[0] === '1' ? 'dark' : modes[0] === '2' ? 'ink' : 'light'; } else { mode = modes[1] === '1' ? 'dark' : modes[1] === '2' ? 'ink' : 'light'; } } } // 如果跟随浏览器暗色模式 if (this.getConfig('darkAuto') && window.matchMedia) { let prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches; if (prefersDark && mode === 'light') { mode = 'dark'; } } return mode; }, // 彻底清理所有样式和修改 cleanupAllStyles() { // 1. 移除所有样式标签(除了立即样式) let styles = document.querySelectorAll('style[id^="eye-protect-"]'); styles.forEach(style => { if (!style.id.includes('immediate')) { style.remove(); } }); // 2. 移除滤镜模式的SVG let svg = document.getElementById('eye-protect-filter-svg'); if (svg) svg.remove(); // 3. 恢复原始主题色 let meta = document.querySelector('meta[name="theme-color"]'); if (meta) { meta.content = this.getConfig('originThemeColor'); } // 4. 移除动态添加的内联样式 let elements = document.querySelectorAll('[data-eye-protect]'); elements.forEach(element => { element.removeAttribute('data-eye-protect'); element.removeAttribute('style'); }); // 5. 移除滤镜模式特定样式 let filterStyle = document.getElementById('eye-protect-filter-style'); if (filterStyle) filterStyle.remove(); }, // 应用样式(带模式标识) applyStyle(css, modeId) { // 移除所有之前可能存在的样式(除了立即样式) this.cleanupAllStyles(); let style = document.createElement('style'); style.id = 'eye-protect-' + modeId; style.setAttribute('data-eye-protect-mode', modeId); style.innerHTML = css; // 确保文档已准备好 if (document.head) { document.head.appendChild(style); } else { // 如果head不存在,等待它加载 const waitForHead = () => { if (document.head) { document.head.appendChild(style); } else { requestAnimationFrame(waitForHead); } }; waitForHead(); } // 标记body,方便调试 if (document.body) { document.body.setAttribute('data-eye-protect', 'enabled'); document.body.setAttribute('data-eye-mode', modeId); } }, // 获取网站专用模式 getSiteSpecificMode() { try { let host = location.host; let siteModesStr = this.getConfig('siteSpecificModes') || '{}'; let siteModes = {}; siteModes = JSON.parse(siteModesStr); return siteModes[host] || null; } catch (e) { return null; } }, // 设置网站专用模式 setSiteSpecificMode(mode) { try { let host = location.host; let siteModesStr = this.getConfig('siteSpecificModes') || '{}'; let siteModes = {}; siteModes = JSON.parse(siteModesStr); if (mode === 'default' || mode === null) { delete siteModes[host]; } else { siteModes[host] = mode; } this.setConfig('siteSpecificModes', JSON.stringify(siteModes)); } catch (e) { console.error('设置网站专用模式出错:', e); } }, // 应用通用夜间模式(从第一个脚本移植) applyOriginalDarkMode() { let style_30 = this.getConfig('customDark3') || '90'; let dark3Exclude = this.getConfig('dark3Exclude'); let style_31 = ` html { filter: invert(${style_30}%) !important; text-shadow: 0 0 0 !important; } ${dark3Exclude} { filter: invert(1) !important; } img[alt="[公式]"] { filter: none !important; } /* 滚动条样式 */ ::-webkit-scrollbar { height: 12px !important; width: 12px !important; } ::-webkit-scrollbar-thumb { border-radius: 0; border-color: transparent; border-style: dashed; background-color: #3f4752 !important; background-clip: padding-box; transition: background-color .32s ease-in-out; } ::-webkit-scrollbar-corner { background: #202020 !important; } ::-webkit-scrollbar-track { background-color: #22272e !important; } ::-webkit-scrollbar-thumb:hover { background: #3f4752 !important; } `; if (navigator.userAgent.toLowerCase().indexOf('firefox') > -1) { style_31 = ` html { filter: invert(${style_30}%) !important; background-image: url(); text-shadow: 0 0 0 !important; } ${dark3Exclude} { filter: invert(1) !important; } img[alt="[公式]"] { filter: none !important; } `; } this.applyStyle(style_31, 'dark-mode-original'); }, // 判断是否为Firefox浏览器 isFirefox() { return /Firefox/i.test(navigator.userAgent); }, // 应用滤镜模式(从第二个脚本移植) applyFilterMode() { // 首先检查是否应该排除当前网站 let filterExcludeList = this.getConfig('filterExcludeList'); let host = location.host; if (filterExcludeList.includes(host)) { this.cleanupAllStyles(); return; } // 彻底清理所有样式 this.cleanupAllStyles(); // 创建SVG滤镜(非Firefox浏览器) if (!this.isFirefox() && !document.getElementById('eye-protect-filter-svg')) { this.createFilterSvg(); } // 创建滤镜样式 this.createFilterStyle(); // 设置深色主题色 this.applyThemeColor('#131313'); }, // 创建SVG滤镜 createFilterSvg() { let svgDom = ''; let div = document.createElementNS('http://www.w3.org/1999/xhtml', 'div'); div.innerHTML = svgDom; let frag = document.createDocumentFragment(); while (div.firstChild) frag.appendChild(div.firstChild); document.head.appendChild(frag); }, // 创建滤镜样式 createFilterStyle() { let filter = this.isFirefox() ? `filter: url('data:image/svg+xml;utf8,#eye-protect-filter') !important;` : '-webkit-filter: url(#eye-protect-filter) !important; filter: url(#eye-protect-filter) !important;'; let reverseFilter = this.isFirefox() ? `filter: url('data:image/svg+xml;utf8,#eye-protect-filter-reverse') !important;` : '-webkit-filter: url(#eye-protect-filter-reverse) !important; filter: url(#eye-protect-filter-reverse) !important;'; let css = ` @media screen { html { ${filter} scrollbar-color: #454a4d #202324; } /* Default Reverse rule */ img, video, iframe, canvas, :not(object):not(body) > embed, object, svg image, [style*="background:url"], [style*="background-image:url"], [style*="background: url"], [style*="background-image: url"], [background], twitterwidget, .sr-reader, .no-dark-mode, .sr-backdrop { ${reverseFilter} } [style*="background:url"] *, [style*="background-image:url"] *, [style*="background: url"] *, [style*="background-image: url"] *, input, [background] *, img[src^="https://s0.wp.com/latex.php"], twitterwidget .NaturalImage-image { -webkit-filter: none !important; filter: none !important; } /* Text contrast */ html { text-shadow: 0 0 0 !important; } /* Full screen */ .no-filter, :-webkit-full-screen, :-webkit-full-screen *, :-moz-full-screen, :-moz-full-screen *, :fullscreen, :fullscreen * { -webkit-filter: none !important; filter: none !important; } ::-webkit-scrollbar { background-color: #202324; color: #aba499; } ::-webkit-scrollbar-thumb { background-color: #454a4d; } ::-webkit-scrollbar-thumb:hover { background-color: #575e62; } ::-webkit-scrollbar-thumb:active { background-color: #484e51; } ::-webkit-scrollbar-corner { background-color: #181a1b; } /* Page background */ html { background: #fff !important; } } `; let style = document.createElement('style'); style.id = 'eye-protect-filter-style'; style.innerHTML = css; document.head.appendChild(style); }, // 禁用滤镜模式 disableFilterMode() { let style = document.getElementById('eye-protect-filter-style'); if (style) style.remove(); let svg = document.getElementById('eye-protect-filter-svg'); if (svg) svg.remove(); // 恢复原始主题色 this.applyThemeColor(this.getConfig('originThemeColor') || '#ffffff'); }, // 应用夜间模式 applyDarkMode() { // 彻底清理所有样式 this.cleanupAllStyles(); // 根据域名使用不同的处理逻辑 let hostname = window.location.hostname; let pathname = window.location.pathname; // 检查网站专用模式 let siteSpecificMode = this.getSiteSpecificMode(); if (siteSpecificMode === 'light') { // 如果网站专用模式是白天模式,清理样式 this.cleanupAllStyles(); return; } else if (hostname.includes('123pan.com') || hostname.includes('123865.com') || hostname.includes('123pan.cn')) { this.apply123PanInvertMode(); } else if (hostname.includes('bilivod.com')) { this.applyBilivodDarkMode(); } else if (hostname.includes('lanzou')) { this.applyLanzouDarkMode(); } else if (hostname.includes('scriptcat.org') && pathname.includes('/code/')) { this.applyScriptCatCodeMode(); } else { // 对于所有其他网站,包括zzoc.cc,都使用移植的通用夜间模式 this.applyOriginalDarkMode(); } // 设置主题色为深色 this.applyThemeColor('#131313'); }, // 应用主题色 applyThemeColor(color) { setTimeout(() => { let meta = document.querySelector('meta[name="theme-color"]'); if (meta) { meta.content = color; } else { let metaEle = document.createElement('meta'); metaEle.name = 'theme-color'; metaEle.content = color; if (document.head) { document.head.appendChild(metaEle); } } }, 100); }, // 应用简单的反色模式(恢复旧版效果) applySimpleInvertMode() { // 这个现在调用通用的原始夜间模式 this.applyOriginalDarkMode(); }, // ScriptCat脚本代码页面专用夜间模式 applyScriptCatCodeMode() { let style_30 = this.getConfig('customDark3') || '90'; let css = ` /* ScriptCat脚本代码页面专用夜间模式 */ html { filter: invert(${style_30}%) hue-rotate(180deg) !important; background-color: #0d1117 !important; text-shadow: 0 0 0 !important; } /* 排除需要保持原始颜色的元素 */ img, svg, canvas, iframe, .icon, .logo, .avatar, [class*="icon"], [class*="Icon"], [src*=".svg"], [src*=".png"], [src*=".jpg"], [src*=".jpeg"], [src*=".gif"], [src*=".webp"], .code-preview img, .avatar img { filter: invert(1) hue-rotate(180deg) !important; } body, html { background-color: #0d1117 !important; color: #c9d1d9 !important; } /* === 代码查看器主区域 === */ .container, .main-container, .wrapper, .content, .code-container, .script-container, .page-content, .main-content { background-color: #0d1117 !important; color: #c9d1d9 !important; } /* 代码查看器头部 */ .header, .script-header, .page-header, .navbar, .nav, .top-bar, [class*="header"], [class*="Header"], .breadcrumb, .nav-bar { background-color: #161b22 !important; border-color: #30363d !important; color: #c9d1d9 !important; } /* 脚本元信息区域 */ .script-meta, .meta-info, .info-panel, .details, .description, .script-info, .card, .panel, .meta-card { background-color: #161b22 !important; border-color: #30363d !important; color: #8b949e !important; } /* 脚本标题 */ .script-title, .title, h1, h2, h3 { color: #f0f6fc !important; } /* === 代码高亮区域 === */ .code-viewer, .code-area, .editor-container, pre, code, .hljs, .prismjs, [class*="language-"], [class*="syntax-"], .CodeMirror, .cm-s-default, .code-mirror, .code-editor, .editor, .viewer { background-color: #0d1117 !important; color: #c9d1d9 !important; } /* 代码行号 */ .line-numbers, .linenums, .line-number, [class*="line-"], td[class*="line"], .CodeMirror-linenumber, .cm-number, .gutter, .gutter-background { background-color: #161b22 !important; color: #6e7681 !important; } /* 代码语法高亮颜色优化 */ .hljs-keyword, .hljs-selector-tag, .hljs-built_in, .hljs-name, .cm-keyword, .cm-def, .cm-atom { color: #ff7b72 !important; } .hljs-string, .hljs-title, .hljs-section, .hljs-attribute, .cm-string, .cm-string-2 { color: #a5d6ff !important; } .hljs-literal, .hljs-number, .cm-number, .cm-property { color: #79c0ff !important; } .hljs-comment, .hljs-quote, .cm-comment { color: #8b949e !important; } .hljs-function, .hljs-params, .cm-variable, .cm-variable-2 { color: #d2a8ff !important; } .hljs-variable, .hljs-template-variable, .cm-variable-3, .cm-type { color: #ffa657 !important; } .hljs-operator, .hljs-punctuation, .cm-operator, .cm-punctuation { color: #c9d1d9 !important; } .hljs-tag, .hljs-selector-id, .hljs-selector-class { color: #7ee787 !important; } /* === 操作按钮区域 === */ .actions, .btn-group, .button-group, .toolbar, .action-bar, .script-actions, .button-container, .button-row { background-color: #161b22 !important; border-color: #30363d !important; } /* 按钮样式 */ .btn, .button, [type="button"], [type="submit"], .btn-primary, .btn-success, .btn-info, .btn-secondary, .btn-outline { background-color: #21262d !important; color: #c9d1d9 !important; border-color: #30363d !important; } .btn:hover, .button:hover, .btn-primary:hover, .btn-success:hover { background-color: #30363d !important; border-color: #8b949e !important; } .btn-primary, .btn-success { background-color: #238636 !important; color: #ffffff !important; border-color: #238636 !important; } /* 链接样式 */ a, a:link, a:visited { color: #58a6ff !important; } a:hover, a:active { color: #79c0ff !important; } /* 滚动条优化 */ ::-webkit-scrollbar { width: 12px !important; height: 12px !important; background-color: #0d1117 !important; } ::-webkit-scrollbar-thumb { background-color: #30363d !important; border: 2px solid #0d1117 !important; } ::-webkit-scrollbar-thumb:hover { background-color: #484f58 !important; } /* Firefox兼容性 */ @-moz-document url-prefix() { html { filter: invert(${style_30}%) hue-rotate(180deg) !important; background-image: url() !important; background-color: #0d1117 !important; } } /* 确保设置面板不受影响 */ .eye-protect-settings-panel, .eye-protect-settings-panel * { filter: none !important; background: none !important; color: inherit !important; } `; this.applyStyle(css, 'dark-mode-scriptcat-code'); }, // 123云盘专用夜间模式(优化版) apply123PanInvertMode() { let style_30 = this.getConfig('customDark3') || '90'; let css = ` /* 123云盘优化反色模式 */ html { filter: invert(${style_30}%) hue-rotate(180deg) !important; background-color: #343c3e !important; text-shadow: 0 0 0 !important; } /* 立即生效的基础样式,防止闪烁 */ body { background-color: #343c3e !important; color: #ffffff !important; transition: none !important; } /* 排除需要保持原始颜色的元素 */ img, svg, video, canvas, iframe, .icon, .logo, .qrcode, .code-img, .verify-img, .captcha-img, .ad-container, [class*="icon"], [class*="Icon"], [src*=".svg"], [src*=".png"], [src*=".jpg"], [src*=".jpeg"], [src*=".gif"], [src*=".webp"], .ant-image-img, .ant-image-preview-img { filter: invert(1) hue-rotate(180deg) !important; } /* 确保基础容器背景色 */ .app, #app, #root, .root, .layout, .main-layout, .container, .wrapper, .main-wrapper { background-color: #343c3e !important; color: #ffffff !important; } /* 123云盘通用样式覆盖 */ /* 头部和导航栏 */ .header, .navbar, .nav, .top-bar, .menu, .toolbar, .bar, [class*="header"], [class*="Header"], [class*="nav"], [class*="Nav"], [class*="menu"], [class*="Menu"], .ant-layout-header { background-color: #4a5457 !important; border-color: #5d696c !important; color: #ffffff !important; } /* 侧边栏和文件列表 */ .sidebar, .side-nav, .file-list, .folder-list, .grid-view, .list-view, .container, .wrapper, .ant-layout-sider { background-color: #343c3e !important; border-color: #5d696c !important; } /* 文件项和文件夹项 */ .file-item, .folder-item, .grid-item, .list-item, .item, .entry, .card, .box, .ant-list-item, .ant-card, .file-item-wrapper, .folder-item-wrapper { background-color: #4a5457 !important; color: #ffffff !important; border-color: #5d696c !important; margin: 2px 0 !important; border-radius: 6px !important; padding: 10px !important; } .file-item:hover, .folder-item:hover, .grid-item:hover, .ant-list-item:hover, .ant-card:hover { background-color: #5d696c !important; transform: translateY(-1px) !important; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3) !important; } /* 按钮样式 */ .btn-primary, .primary, .blue, .button, .btn, [style*="background-color: #007bff"], [style*="background-color: #0066cc"], [class*="btn-primary"], [class*="btn-success"], [type="submit"], [type="button"], .ant-btn-primary { background-color: #009688 !important; border-color: #009688 !important; color: white !important; } .btn-primary:hover, .primary:hover, .blue:hover, .ant-btn-primary:hover { background-color: #26a69a !important; border-color: #26a69a !important; } /* 输入框和表单 */ input, textarea, select, .form-control, .search-input, .input, .text-input, [type="text"], [type="password"], .ant-input, .ant-select-selector { background-color: #4a5457 !important; color: #ffffff !important; border-color: #5d696c !important; } input:focus, textarea:focus, .ant-input:focus { border-color: #009688 !important; box-shadow: 0 0 0 2px rgba(0, 150, 136, 0.2) !important; } /* 链接样式 */ a, a:link, a:visited { color: #26a69a !important; } a:hover, a:active { color: #4db6ac !important; } /* 表格样式 */ table, tr, th, td { background-color: #4a5457 !important; color: #ffffff !important; border-color: #5d696c !important; } th { background-color: #5d696c !important; } tr:nth-child(even) { background-color: #3a4447 !important; } /* 弹窗和模态框 */ .modal, .popup, .dialog, .overlay, .lightbox, [role="dialog"], .ant-modal-content { background-color: rgba(0, 0, 0, 0.8) !important; } .modal-content, .popup-content, .dialog-content, .ant-modal-content .ant-modal-body { background-color: #4a5457 !important; border: 1px solid #5d696c !important; color: #ffffff !important; } /* 滚动条 */ ::-webkit-scrollbar { width: 12px !important; height: 12px !important; background-color: #4a5457 !important; } ::-webkit-scrollbar-thumb { background-color: #5d696c !important; border-radius: 6px !important; } ::-webkit-scrollbar-thumb:hover { background-color: #009688 !important; } ::-webkit-scrollbar-track { background-color: #343c3e !important; } /* === 专门适配123云盘的选中状态 === */ /* 选中状态提示区域 */ .selected-info, .selected-tip, .selected-status, [class*="selected-"], [class*="select-"], .selection-info, .selection-status, .select-count, .selected-count { background-color: #1e3a5f !important; color: #ffffff !important; border: 1px solid #2a4d7c !important; } /* 文件选中状态 */ .file-item.selected, .folder-item.selected, .grid-item.selected, .list-item.selected, .item.selected, .entry.selected, .selected, [data-selected="true"], [aria-selected="true"], .is-selected { background-color: #2a4d7c !important; border-color: #3a5d8c !important; border-left: 4px solid #009688 !important; } /* 批量操作工具栏 */ .batch-toolbar, .batch-actions, .selected-actions, .select-actions { background-color: #4a5457 !important; border-top: 2px solid #2a4d7c !important; border-bottom: 2px solid #2a4d7c !important; } /* 响应式优化 */ @media (max-width: 768px) { .header, .navbar { background-color: #4a5457 !important; } .sidebar, .side-nav { background-color: #4a5457 !important; } .file-item, .folder-item { background-color: #4a5457 !important; padding: 8px !important; } } /* Firefox兼容性 */ @-moz-document url-prefix() { html { filter: invert(${style_30}%) hue-rotate(180deg) !important; background-image: url() !important; background-color: #343c3e !important; } } /* 确保设置面板不受影响 */ .eye-protect-settings-panel, .eye-protect-settings-panel * { filter: none !important; background: none !important; color: inherit !important; } /* 立即生效的过渡优化 */ * { transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease !important; } `; this.applyStyle(css, 'dark-mode-123pan'); }, // bilivod.com专用夜间模式 applyBilivodDarkMode() { let style_30 = this.getConfig('customDark3') || '90'; let isType32Page = window.location.pathname.includes('/type/32'); let css = ` /* bilivod.com专用夜间模式 */ html { filter: invert(${style_30}%) hue-rotate(180deg) !important; background-color: #1a1a1a !important; text-shadow: 0 0 0 !important; } /* 排除不需要反色的元素 */ img, svg, video, canvas, iframe, .icon, .logo, .thumbnail, .avatar, [class*="icon"], [class*="Icon"], [src*=".svg"], [src*=".png"], [src*=".jpg"], [src*=".jpeg"], [src*=".gif"], [src*=".webp"], .video-player, .player, [class*="player"], [class*="Player"] { filter: invert(1) hue-rotate(180deg) !important; } body { background-color: #1a1a1a !important; } /* bilivod.com特定优化 */ body, div, section, main, article, nav, header, footer, aside, .container, .wrapper, .content, .main-content, .panel, .card, .box, .block, .list, .item, .entry, .video-list, .video-item, .vod-item { background-color: #1a1a1a !important; color: #d0d0d0 !important; border-color: #333 !important; } /* 强力覆盖所有内联白色背景 */ [style*="background-color: white"], [style*="background: white"], [style*="background:#fff"], [style*="background-color:#fff"], [style*="background-color: #fff"], [style*="background-color: #ffffff"] { background-color: #1a1a1a !important; } /* 导航栏和头部 */ .header, .navbar, .nav, .top-bar, .menu, .toolbar, .bar { background-color: #222 !important; } /* 按钮和表单 */ button, .btn, .button, input, textarea, select { background-color: #2a2a2a !important; color: #e0e0e0 !important; border-color: #444 !important; } /* 链接和蓝色区域 */ a, a:link, a:visited { color: #ff7700 !important; } a:hover { color: #ff9933 !important; } .btn-primary, .primary, .blue { background-color: #ff7700 !important; } /* 视频卡片和缩略图 */ .video-card, .vod-card, .movie-card, .film-card, .thumb, .thumbnail { background-color: #222 !important; border-color: #333 !important; } .video-title, .vod-title, .movie-title { color: #ffffff !important; } /* 滚动条 */ ::-webkit-scrollbar { background-color: #1a1a1a !important; } ::-webkit-scrollbar-thumb { background-color: #444 !important; } ::-webkit-scrollbar-thumb:hover { background-color: #555 !important; } ::-webkit-scrollbar-track { background-color: #222 !important; } /* Firefox兼容性 */ @-moz-document url-prefix() { html { filter: invert(${style_30}%) hue-rotate(180deg) !important; background-image: url() !important; background-color: #1a1a1a !important; } } /* 确保设置面板不受影响 */ .eye-protect-settings-panel, .eye-protect-settings-panel * { filter: none !important; background: none !important; color: inherit !important; } `; // 专门为/type/32页面添加额外优化 if (isType32Page) { css += ` /* === 专门针对 /type/32 页面的优化 === */ .type-header, .category-header, .page-header { background-color: #222 !important; border-bottom: 2px solid #333 !important; } .type-content, .category-content, .page-content { background-color: #1a1a1a !important; } .type-sidebar, .category-sidebar, .side-content { background-color: #222 !important; border-right: 1px solid #333 !important; } .video-item:hover, .vod-item:hover { background-color: #2a2a2a !important; transform: translateY(-2px) !important; } `; } this.applyStyle(css, 'dark-mode-bilivod'); }, // 蓝奏云优化的反色模式 applyLanzouDarkMode() { let style_30 = this.getConfig('customDark3') || '90'; let css = ` /* 蓝奏云夜间模式优化版 */ html { filter: invert(${style_30}%) hue-rotate(180deg) !important; background-color: #1a1a1a !important; text-shadow: 0 0 0 !important; } img, svg, video, canvas, iframe, .icon, .logo, .qrcode, .code-img { filter: invert(1) hue-rotate(180deg) !important; } body, html { background-color: #1a1a1a !important; color: #e0e0e0 !important; } div, section, main, article, nav, header, footer, aside, .container, .wrapper, .content, .main, .panel, .box { background-color: #1a1a1a !important; color: #e0e0e0 !important; } .file-list, .folder-list, .data-list, .table, .list-container, .list-box { background-color: #222 !important; border: 1px solid #333 !important; } .file-item, .folder-item, .list-item, tr, .data-item, .list-row { background-color: #2a2a2a !important; color: #e0e0e0 !important; border-color: #333 !important; } button, .btn, input[type="button"], input[type="submit"], .download-btn { background-color: #0066cc !important; color: white !important; border: 1px solid #0066cc !important; } button:hover, .btn:hover, .download-btn:hover { background-color: #0080ff !important; border-color: #0080ff !important; } input, textarea, select, .form-control { background-color: #2a2a2a !important; color: #e0e0e0 !important; border: 1px solid #444 !important; } a, a:link, a:visited { color: #66aaff !important; } a:hover, a:active { color: #88ccff !important; } ::-webkit-scrollbar { width: 12px !important; height: 12px !important; background-color: #222 !important; } ::-webkit-scrollbar-thumb { background-color: #444 !important; border-radius: 6px !important; } @-moz-document url-prefix() { html { filter: invert(${style_30}%) hue-rotate(180deg) !important; background-image: url() !important; background-color: #1a1a1a !important; } } /* 确保设置面板不受影响 */ .eye-protect-settings-panel, .eye-protect-settings-panel * { filter: none !important; background: none !important; color: inherit !important; } `; this.applyStyle(css, 'dark-mode-lanzou'); }, // 应用墨黑模式 applyInkMode() { this.cleanupAllStyles(); let config = this.getConfig('inkModeConfig').split('|'); let backgroundColor = config[0] || '#343c3e'; let textColor = config[1] || '#ffffff'; let secondaryBg = config[2] || '#4a5457'; let borderColor = config[3] || '#5d696c'; let primaryColor = config[4] || '#009688'; let hoverColor = config[5] || '#26a69a'; let css = this.generateInkModeCSS(backgroundColor, textColor, secondaryBg, borderColor, primaryColor, hoverColor); this.applyStyle(css, 'ink-mode'); this.applyThemeColor(backgroundColor); }, // 生成墨黑模式CSS generateInkModeCSS(bgColor, textColor, secondaryBg, borderColor, primaryColor, hoverColor) { return ` /* 墨黑模式 */ html, body { background-color: ${bgColor} !important; color: ${textColor} !important; } div, section, main, article, nav, header, footer, aside, .container, .wrapper, .content, .card, .box { background-color: ${bgColor} !important; color: ${textColor} !important; border-color: ${borderColor} !important; } p, span, h1, h2, h3, h4, h5, h6 { color: ${textColor} !important; } a, a:link, a:visited { color: ${primaryColor} !important; } a:hover, a:active { color: ${hoverColor} !important; } button, .btn, input[type="button"], input[type="submit"] { background-color: ${secondaryBg} !important; color: ${textColor} !important; border-color: ${borderColor} !important; } button:hover, .btn:hover { background-color: ${primaryColor} !important; border-color: ${primaryColor} !important; } input, textarea, select { background-color: ${secondaryBg} !important; color: ${textColor} !important; border-color: ${borderColor} !important; } input:focus, textarea:focus { border-color: ${primaryColor} !important; } table, tr, th, td { background-color: ${bgColor} !important; color: ${textColor} !important; border-color: ${borderColor} !important; } th { background-color: ${secondaryBg} !important; } tr:nth-child(even) { background-color: ${secondaryBg} !important; } ::-webkit-scrollbar { width: 12px !important; height: 12px !important; background-color: ${secondaryBg} !important; } ::-webkit-scrollbar-thumb { background-color: ${borderColor} !important; } ::-webkit-scrollbar-thumb:hover { background-color: ${primaryColor} !important; } /* 确保设置面板不受影响 */ .eye-protect-settings-panel, .eye-protect-settings-panel * { filter: none !important; background: none !important; color: inherit !important; } `; }, // 是否应该排除当前网站 shouldExcludeSite() { let hostname = window.location.hostname; // 对于特定网站,我们使用专门的处理逻辑 if (hostname.includes('123pan.com') || hostname.includes('123865.com') || hostname.includes('123pan.cn') || hostname.includes('github.com') || hostname.includes('hemudu.cc') || hostname.includes('bilivod.com') || hostname.includes('lanzou') || hostname.includes('scriptcat.org')) { return false; } let forcedList = this.getConfig('forcedEnableList'); if (forcedList.includes(location.host)) { return false; } // 通用排除逻辑 let html = document.documentElement; let body = document.body; if (document.querySelector('head>meta[name="color-scheme"],head>link[href^="resource:"]')) { return true; } if (html.className && (html.className.includes('dark') || body.className && body.className.includes('dark'))) { return true; } if (html.getAttribute('data-theme') && html.getAttribute('data-theme').includes('dark')) { return true; } if (html.getAttribute('data-color-mode') && html.getAttribute('data-color-mode').includes('dark')) { return true; } return false; }, // 是否应该应用模式(修改:强制启用受全局开关和白名单影响) shouldApplyMode() { let globalEnable = this.getConfig('globalEnable'); let enableList = this.getConfig('enableList'); let blacklist = this.getConfig('blacklist'); let forcedList = this.getConfig('forcedEnableList'); let host = location.host; // 第一步:检查黑名单(最高优先级) if (blacklist.includes(host)) { return false; } // 第二步:检查强制启用列表(修改:受全局开关和白名单影响) if (forcedList.includes(host)) { // 强制启用需要满足:全局开关开启 或 该网站在白名单中 if (globalEnable || enableList.includes(host)) { return true; } return false; } // 第三步:检查全局开关 if (globalEnable) { return true; } // 第四步:检查白名单 if (enableList.includes(host)) { return true; } // 都不满足,不应用模式 return false; }, // 切换黑名单状态 toggleBlacklist() { let blacklist = this.getConfig('blacklist'); let host = location.host; if (blacklist.includes(host)) { blacklist = blacklist.filter(domain => domain !== host); this.setConfig('blacklist', blacklist); this.showNotification('已将当前网站从黑名单中移除'); if (this.shouldApplyMode()) { this.applyMode(); } } else { blacklist.push(host); this.setConfig('blacklist', blacklist); this.showNotification('已将当前网站添加到黑名单'); this.cleanupAllStyles(); } this.refreshMenu(); }, // 清空黑名单 clearBlacklist() { if (confirm('确定要清空黑名单吗?这将移除所有在黑名单中的网站。')) { this.setConfig('blacklist', []); this.showNotification('已清空黑名单'); this.refreshMenu(); } }, // 清空强制启用列表 clearForcedList() { if (confirm('确定要清空强制启用列表吗?这将移除所有强制启用的网站。')) { this.setConfig('forcedEnableList', []); this.showNotification('已清空强制启用列表'); this.applyMode(); this.refreshMenu(); } }, // 应用模式 applyMode() { if (!this.shouldApplyMode()) { this.cleanupAllStyles(); return; } if (this.getConfig('autoExclude') && this.shouldExcludeSite()) { this.cleanupAllStyles(); return; } let siteSpecificMode = this.getSiteSpecificMode(); if (siteSpecificMode && siteSpecificMode !== 'default') { switch(siteSpecificMode) { case 'light': this.cleanupAllStyles(); break; case 'dark': this.applyDarkMode(); break; case 'ink': this.applyInkMode(); break; case 'filter': this.applyFilterMode(); break; } } else { let mode = this.getCurrentMode(); switch(mode) { case 'dark': this.applyDarkMode(); break; case 'ink': this.applyInkMode(); break; case 'light': default: this.cleanupAllStyles(); break; } } }, // 切换模式(不包含滤镜模式) switchMode() { let siteSpecificMode = this.getSiteSpecificMode(); if (siteSpecificMode && siteSpecificMode !== 'default') { this.showNotification('当前网站使用专用模式,请在设置面板中修改'); setTimeout(() => this.showSettings(), 100); return; } let currentMode = this.currentMode || this.getConfig('currentMode') || 'light'; // 全局切换中只包含light, dark, ink三种模式 let nextMode = currentMode === 'light' ? 'dark' : currentMode === 'dark' ? 'ink' : 'light'; this.currentMode = nextMode; this.setConfig('currentMode', nextMode); this.showNotification(`正在切换到 ${this.getModeName(nextMode)}`); setTimeout(() => { this.applyMode(); this.refreshMenu(); this.showNotification(`已切换到 ${this.getModeName(nextMode)}`); }, 100); }, // 获取模式名称 getModeName(mode) { switch(mode) { case 'light': return '白天模式'; case 'dark': return '夜间模式'; case 'ink': return '墨黑模式'; case 'filter': return '滤镜模式'; default: return '白天模式'; } }, // 获取网站模式名称 getSiteModeName(mode) { switch(mode) { case 'light': return '白天模式'; case 'dark': return '夜间模式'; case 'ink': return '墨黑模式'; case 'filter': return '滤镜模式'; default: return '默认'; } }, // 切换全局开关 toggleGlobal() { let current = this.getConfig('globalEnable'); this.setConfig('globalEnable', !current); this.applyMode(); this.refreshMenu(); this.showNotification(!current ? '已开启全局模式' : '已关闭全局模式'); }, // 切换当前网站开关(白名单管理) toggleCurrentSite() { let enableList = this.getConfig('enableList'); let host = location.host; if (enableList.includes(host)) { enableList = enableList.filter(domain => domain !== host); this.cleanupAllStyles(); this.setConfig('enableList', enableList); this.showNotification('已在当前网站禁用护眼模式'); } else { enableList.push(host); this.setConfig('enableList', enableList); this.applyMode(); this.showNotification('已在当前网站启用护眼模式'); } this.refreshMenu(); }, // 切换强制启用 toggleForceEnable() { let forcedList = this.getConfig('forcedEnableList'); let host = location.host; if (forcedList.includes(host)) { forcedList = forcedList.filter(domain => domain !== host); this.showNotification('已取消强制启用当前网站'); } else { forcedList.push(host); this.showNotification('已强制启用当前网站'); } this.setConfig('forcedEnableList', forcedList); this.applyMode(); this.refreshMenu(); }, // 显示通知 showNotification(message) { let oldNotifications = document.querySelectorAll('.eye-protect-notification'); oldNotifications.forEach(notification => { notification.remove(); }); let notification = document.createElement('div'); notification.className = 'eye-protect-notification'; notification.style.cssText = ` position: fixed; top: 20px; right: 20px; background: rgba(0, 0, 0, 0.8); color: white; padding: 10px 20px; border-radius: 5px; z-index: 999999; font-size: 14px; box-shadow: 0 2px 5px rgba(0,0,0,0.2); opacity: 1; transition: opacity 0.5s; max-width: 300px; word-wrap: break-word; `; notification.textContent = message; if (document.body) { document.body.appendChild(notification); setTimeout(() => { notification.style.opacity = '0'; setTimeout(() => notification.remove(), 500); }, 2000); } }, // 显示设置面板 showSettings() { // 移除现有的设置面板 let existingPanel = document.querySelector('.eye-protect-settings-panel'); if (existingPanel) { existingPanel.remove(); return; } // 获取当前配置 let currentMode = this.getCurrentMode(); let globalEnable = this.getConfig('globalEnable'); let enableList = this.getConfig('enableList'); let blacklist = this.getConfig('blacklist'); let autoExclude = this.getConfig('autoExclude'); let forcedList = this.getConfig('forcedEnableList'); let runDuringDay = this.getConfig('runDuringDay'); let darkAuto = this.getConfig('darkAuto'); let inkConfig = this.getConfig('inkModeConfig'); let autoSwitch = this.getConfig('autoSwitch'); let customDayNight = this.getConfig('customDayNight'); let customDark3 = this.getConfig('customDark3'); let host = location.host; let siteEnabled = enableList.includes(host); let isForced = forcedList.includes(host); let isBlacklisted = blacklist.includes(host); let blacklistCount = blacklist.length; // 获取当前网站的专用模式 let siteSpecificMode = this.getSiteSpecificMode(); // 创建设置面板 let panel = document.createElement('div'); panel.className = 'eye-protect-settings-panel'; // 使用亮色主题样式,不受当前模式影响 panel.style.cssText = ` position: fixed !important; top: 50% !important; left: 50% !important; transform: translate(-50%, -50%) !important; width: 550px !important; max-width: 90% !important; max-height: 85vh !important; background: #ffffff !important; color: #333333 !important; border-radius: 10px !important; box-shadow: 0 5px 20px rgba(0,0,0,0.2) !important; z-index: 1000000 !important; overflow: hidden !important; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif !important; border: 1px solid #e0e0e0 !important; `; // 面板内容 - 使用亮色主题 panel.innerHTML = `