在您安装前,Greasy Fork 希望您知道此脚本声明其包含了一些负面功能。这些功能也许会使脚本作者获利,而不能给您带来任何直接的金钱收益。
此脚本会在您访问的网站中插入广告。
脚本作者的说明:
CSDNGreener 脚本中嵌入了可一键永久关闭的小广告,不会影响您的使用体验:) 请放心安装!
⚡️全新5.0版本!本脚本借鉴CSDNGreener!!!!!拥有数项独家功能的最强CSDN脚本,不服比一比⚡️|🕶无需登录CSDN,获得比会员更佳的体验|🖥自定义背景图,分辨率自适配,分屏不用滚动|💾超级预优化|🏷原创文章免登录展开|🔌独家推荐内容自由开关|📠免登录复制|🔗防外链重定向|📝独家论坛未登录自动展开文章、评论|🌵全面净化|📈沉浸阅读|🧴净化剪贴板|📕作者信息文章顶部展示
// ==UserScript== // @name 「CSDNGreener」更新 // @namespace https://github.com/adlered // @version 5.0.0 // @description ⚡️全新5.0版本!本脚本借鉴CSDNGreener!!!!!拥有数项独家功能的最强CSDN脚本,不服比一比⚡️|🕶无需登录CSDN,获得比会员更佳的体验|🖥自定义背景图,分辨率自适配,分屏不用滚动|💾超级预优化|🏷原创文章免登录展开|🔌独家推荐内容自由开关|📠免登录复制|🔗防外链重定向|📝独家论坛未登录自动展开文章、评论|🌵全面净化|📈沉浸阅读|🧴净化剪贴板|📕作者信息文章顶部展示 // @author Adler // @connect www.csdn.net // @include *://*.csdn.net/* // @require https://lf26-cdn-tos.bytecdntp.com/cdn/expire-1-M/jquery-cookie/1.4.1/jquery.cookie.min.js // @require https://lf26-cdn-tos.bytecdntp.com/cdn/expire-1-M/nprogress/0.2.0/nprogress.min.js // @require https://lf26-cdn-tos.bytecdntp.com/cdn/expire-1-M/clipboard.js/2.0.10/clipboard.min.js // @supportURL https://github.com/adlered/CSDNGreener/issues/new?assignees=adlered&labels=help+wanted&template=ISSUE_TEMPLATE.md&title= // @contributionURL https://doc.stackoverflow.wiki/web/#/21?page_id=138 // @grant GM_addStyle // @grant GM_setValue // @grant GM_getValue // @license AGPL-3.0-or-later // @antifeature ads CSDNGreener 脚本中嵌入了可一键永久关闭的小广告,不会影响您的使用体验:) 请放心安装! // @note 25-01-09 5.0.0 🎉 重大版本更新!全面重构复制功能、设置界面、壁纸系统;新增智能图片压缩、内存优化、性能监控;修复所有已知兼容性问题 // @note 25-01-09 4.2.5 重大修复:修复免登录复制按钮报错、设置界面无法打开、自定义壁纸卡顿等问题;新增图片智能压缩、内存优化、性能监控等功能 // @note 24-07-18 4.2.4 描述更改 // @note 24-03-28 4.2.3 标题更改 // @note 23-12-21 4.2.2 修复了一些已知问题 // @note 23-12-16 4.2.1 文章页牛皮癣优化 // @note 23-12-15 4.2.0 优化顶栏显示内容,修复了若干由于CSDN前端变化导致优化失效的问题 // @note 23-05-25 4.1.9 再次修复免登录复制无法使用的问题 // @note 23-05-11 4.1.8 强杀变异型登录框弹出(不影响自己点击登录使用) // @note 23-05-10 4.1.7 增强免登录复制功能 // @note 23-04-11 4.1.6 去广告更新 // @note 23-04-06 4.1.5 新增: 跳过 CSDN 的 link 页面 // @note 23-04-04 4.1.4 增加ads标识 // @note 23-03-30 4.1.3 移除统计代码,登录问题相关优化(只屏蔽一次) // @note 23-02-03 4.1.2 修复了无法登录的问题(评论不登录无法加载暂无解决方案,我们在持续努力中) // @note 22-05-30 4.1.1 功能修复,广告屏蔽 // @note 22-01-18 4.1.0 代码折叠适配 // @note 22-01-05 4.0.9 更新广告 // @note 21-12-12 4.0.8 屏蔽学生认证 // @note 21-10-21 4.0.7 屏蔽红包雨 // @note 21-09-24 4.0.6 修复登录弹窗无法彻底去除的问题 // @note 21-09-20 4.0.5 增加自定义背景功能 // @note 21-09-13 4.0.4 增加一个没有收钱的广告(在设置里,不影响体验) // @note 21-09-01 4.0.3 增加用户使用情况统计模块 // @note 21-08-25 4.0.2 修复右侧置顶栏按钮消失的问题 // @note 21-08-21 4.0.1 去除右侧悬浮栏,优化脚本 // @note 21-08-20 4.0.0 全新4.0发布!UI美化,代码优化,兼容Firefox,更多排版模式 // @note 21-08-20 3.5.7 修复无法完整复制、保存csdn的网页会跳转首页的问题 // @note 21-08-19 3.5.6 自动隐藏底栏功能改为始终隐藏底栏 // @note 21-08-18 3.5.5 修复无法选择复制的问题 // @note 21-06-17 3.5.4 去除右侧红包悬浮窗 // @note 21-04-18 3.5.3 增加显示小店的设定 // @note 21-03-13 3.5.2 去主页广告,去文章页面推荐内容Title // @note 21-03-01 3.5.1 修改文案 // @note 21-02-06 3.5.0 修复上传资源界面标签选择消失的问题 // @note 21-01-17 3.4.9 删除文章页和论坛广告,暂时停用右侧栏滚动功能(CSDN限制) // @note 21-01-15 3.4.8 保存按钮优化,修复显示创作中心按钮功能失效的问题 // @note 21-01-15 3.4.7 改进脚本细节,增加广告屏蔽能力,修复绿化按钮错位的问题 // @note 20-12-25 3.4.6 主页部分嵌嵌入式广告删除 // @note 20-12-18 3.4.5 修复绿化设定按钮排版不正确的问题 // @note 20-12-15 3.4.4 修复了某些子页显示不正常的问题 // @note 20-10-23 3.4.3 适应新版CSDN,去除主页和登录页广告,以及登录提示,并移除底部信息 // @note 20-10-20 3.4.2 删除右侧广告 // @note 20-09-26 3.4.1 修改排版设定,修复登录框弹出的问题 // @note 20-09-24 3.4.0 紧急修复由于CSDN前端样式修改导致设定开关丢失的问题 // @note 20-08-27 3.3.9 紧急修复由于CSDN前端样式修改导致脚本失效的问题 // @note 20-08-26 3.3.8 合法脚本提示 // @note 20-07-20 3.3.7 修复菜单栏在创作中心显示异常的问题 // @note 20-07-18 3.3.6 工具箱按钮优化 // @note 20-07-05 3.3.5 评论复制功能交互优化 // @note 20-07-04 3.3.4 修复右侧栏消失的问题 // @note 20-07-03 3.3.3 新增复制评论功能!删除顶部广告 // @note 20-06-28 3.3.2 提示修改 // @note 20-06-27 3.3.1 弹窗提示逻辑修改为仅提示一次。 // @note 20-06-27 3.3.0 网站标题新消息提醒去除 // @note 20-06-26 3.2.9 恢复GreasyFork平台脚本支持 // @note 20-06-21 3.2.0 脚本迁移通知 // @note 20-06-21 3.1.9 增加自动隐藏底栏功能 // @note 20-06-21 3.1.8 增加自动隐藏顶栏功能,修复选项窗口被点赞长条挡住的Bug,选项窗口布局修改 // @note 20-06-20 3.1.7 设置窗口大小固定,增加打赏入口 // @note 20-06-19 3.1.6 显示推荐内容按钮回归,新布局紧急修复 // @note 20-06-18 3.1.5 自定义功能更新 // @note 20-06-16 3.1.4 支持大部分功能模块化显示 // @note 20-06-14 3.1.3 绿化设定优化 // @note 20-06-14 3.1.2 ISSUE模板调整Support URL // @note 20-06-14 3.1.1 增加搜博主文章模块 // @note 20-06-13 3.1.0 修复设置过期的问题 // @note 20-06-12 3.0.9 标题回滚 // @note 20-06-12 3.0.8 主页广告删除,绿化设置仅显示在文章页面,删除页脚,顶部优化,若干细节优化 // @note 20-06-11 3.0.7 增加官方QQ交流群,增加关闭强制白色主题功能 // @note 20-06-11 3.0.6 用户名片功能优化 // @note 20-06-11 3.0.5 优化加载速度 // @note 20-06-10 3.0.4 修复设置界面遮挡的问题,显示博主头像 // @note 20-06-09 3.0.3 默认设定修改 // @note 20-06-09 3.0.2 修复推荐内容按钮刷新不生效的问题,增加工具箱提示框 // @note 20-06-08 3.0.1 设置中心推出!增加浏览效果选项 && Green Book Icon Update // @note 20-06-08 3.0.0 设置中心推出!增加浏览效果选项 // @note 20-06-07 2.4.2 设置解耦,下个版本搞配置中心 // @note 20-06-06 2.4.1 修复文章内容消失的问题 // @note 20-06-04 2.4.0 修复推荐按钮错位的问题 // @note 20-06-04 2.3.9 窄屏适配优化 // @note 20-06-04 2.3.8 黑夜模式出现问题,紧急回档到 2.3.6 // @note 20-06-03 2.3.7 感谢 @AlexLWT 增加黑暗模式 // @note 20-06-02 2.3.6 AdsByGoogle 删除 // @note 20-05-25 2.3.5 感谢 @RyanIPO 修复 Cannot read property 'replace' of undefined 报错的问题 // @note 20-05-24 2.3.4 修复免登录复制功能 // @note 20-05-22 2.3.3 Logo与背景同步 // @note 20-05-22 2.3.2 深度删除背景 // @note 20-05-20 2.3.1 通过require使用NProgress // @note 20-05-20 2.3.0 显示推荐内容按钮样式内置,剔除CDN // @note 20-05-17 2.2.9 进度条样式更新,时间延时优化 // @note 20-05-17 2.2.8 更新脚本描述,展开评论的所有回复,删除创作中心按钮,加载进度条 // @note 20-05-17 2.2.7 更新脚本描述 // @note 20-05-16 2.2.6 修复第一次点击显示推荐内容无反应的问题 // @note 20-05-16 2.2.5 删除抢沙发角标,修改显示推荐内容按钮样式 // @note 20-05-16 2.2.4 感谢来自GitHub的朋友“HeronZhang”的Issue建议,删除所有博客花里胡哨的背景,主页分类中广告清除,CSS样式控制宽度适配代码优化 // @note 20-05-16 2.2.3 感谢来自GitHub的朋友“RetiredWorld”的代码贡献,使用CSS来控制样式,而不是JS,增大灵活性。 // @note 20-05-13 2.2.2 屏蔽您的缩放不是100%的提示 // @note 20-04-29 2.2.1 感谢大家的支持,增加目录显示,自动判断是否存在目录调整页面宽度,屏蔽新增广告,欢迎大家体验并提出意见! // @note 20-04-15 2.2.0 一些广告被其他插件屏蔽导致的异常无视之 // @note 20-03-30 2.1.9 干掉“记录你的创作历程”,干掉未登录情况下的角标提醒 // @note 20-03-13 2.1.8 窄屏适配加强 // @note 20-03-13 2.1.7 更新简介 // @note 20-03-12 2.1.6 宽度自适应(感谢来自GitHub的朋友LeonG7的建议)!修复剪贴板净化无效的问题。 // @note 20-03-04 2.1.5 适配AdGuard // @note 20-02-27 2.1.4 优化免登录复制 // @note 20-02-25 2.1.3 免登录复制更新,现已可用 // @note 20-02-24 2.1.2 By Github@JalinWang 更改去除剪贴板劫持的方式,使得原文格式在复制时能够保留 // @note 20-02-22 2.1.1 紧急修复由于 CSDN 修改前端结构导致的文章错位 // @note 20-02-11 2.1.0 若干动画优化,视觉体验更流畅 // @note 20-02-06 2.0.9 武汉加油!修改推荐内容切换开关位置,减少违和感 // @note 20-01-17 2.0.8 去除右侧广告 // @note 20-01-17 2.0.7 感谢来自GitHub的朋友“gleans”的建议,去掉页头广告 // @note 19-12-12 2.0.6 感谢来自GitHub的朋友“yexuesong”的建议,将作者信息在文章顶部展示 // @note 19-10-30 2.0.5 美化隐藏按钮,增加点击动画 // @note 19-10-30 2.0.4 删除CSDN官方在主页推送的文章(大多是广告) // @note 19-10-30 2.0.3 添加更多屏蔽脚本 // @note 19-10-30 2.0.0 祝自己生日快乐~完全重写CSDNGreener,统一使用JQuery,效率更高 // @note 19-10-27 1.5.2 删除分享海报提示&&感谢GitHub的朋友“CHN-STUDENT”的反馈,去除底部课程推荐 // @note 19-10-27 1.5.1 感谢来自GitHub的朋友“CHN-STUDENT”的细致复现反馈,去除了底部的课程推荐广告 // @note 19-10-04 1.5.0 移除了底部主题信息和打赏 // @note 19-09-10 1.4.9 感谢来自GitHub的朋友“programmerZe”的细致复现反馈,修复了评论区点击查看回复后,已经展开的评论会收起的问题 // @note 19-09-04 1.4.8 感谢来自GitHub的朋友“dwdcth”的细致复现反馈,现在查看原创文章不会无限弹登录窗口了,且加强了自动展开功能 // @note 19-08-20 1.4.7 感谢油叉用户“SupremeSir”的反馈,修复了右侧悬浮栏遮挡文章的问题 // @note 19-08-14 1.4.6 无语。刚更新的免登录复制,又改了。修复! // @note 19-08-13 1.4.5 更新了独家功能:免登录复制 // @note 19-08-13 1.4.4 感谢来自GitHub的朋友“iamsunxing”的反馈,修复了顶部不贴边的问题 // @note 19-08-01 1.4.3 感谢油叉用户“ddddy”的反馈,去除了更多推广广告 // @note 19-07-30 1.4.2 感谢油叉用户“周义杰”的反馈,增加了防CSDN外链重定向的功能(CSDN臭流氓) // @note 19-07-20 1.4.1 修复了推荐内容开关跨文章无效问题(忘了配置Cookie作用域) // @note 19-07-19 1.4.0 1. 构架大更新 2. 感谢来自GitHub的朋友"lukemin"的反馈,加入了下方推荐内容是否隐藏开关(实用) // @note 19-07-13 1.3.0 感谢来自GitHub的朋友“Holaplace”的反馈,修复了文章无法自动展开的问题(CSDN总改这个,令人头疼) // @note 19-06-08 1.2.6 感谢油叉用户“DeskyAki”的反馈,修复了文章无法自动展开的问题 // @note 19-06-07 1.2.4 修复了登录后评论无法正常打开的问题 // @note 19-06-07 1.2.3 感谢油叉用户"永远的殿下"的反馈,在一上午的努力攻克下,终于实现了未登录展开评论的语句 // @note 19-06-05 1.2.0 修复了评论无法自动展开的BUG // @note 19-06-04 1.1.9 修复了无法自动展开的BUG(自闭了) // @note 19-06-04 1.1.6 CSDN太坏了,把“消息”按钮的Class设置成了“GitChat”,所以修复了“消息”按钮消失的问题 // @note 19-06-04 1.1.5 1. 优化了论坛体验 2.美化、优化代码结构 // @note 19-06-04 1.1.4 感谢来自GitHub的朋友“iamsunxing”的反馈,增加了论坛广告匹配规则 // @note 19-06-03 1.1.3 感谢来自GitHub的朋友“wangwei135”的反馈,去除了评论区上方的广告 // @note 19-05-27 1.1.2 感谢油叉用户“夏伟杰”的反馈,修复了富文本编辑器无法使用的问题 // @note 19-05-25 1.1.0 1. 修复了主页广告的问题 2. 论坛自动展开 3. 论坛广告消除 // @note 19-05-25 1.0.9 感谢油叉用户“渣渣不准说话”的反馈,修复了收藏按钮消失的问题 // @note 19-03-01 1.0.3 添加页面选择性过滤规则 // @note 19-03-01 1.0.2 增加了净化剪贴板功能 // @note 19-03-01 1.0.1 修复了排版问题, 优化了代码结构 // @note 19-02-26 1.0.0 初版发布 // ==/UserScript== var version = "5.0.0"; // 浏览器类型判断 function isFirefox() { return typeof navigator !== 'undefined' && /firefox/i.test(navigator.userAgent); } function isChrome() { return typeof navigator !== 'undefined' && /chrome/i.test(navigator.userAgent) && !isFirefox(); } // 立即定义 hljs 和 mdcp 对象,确保在任何时候都可以访问 (function() { 'use strict'; // Element.closest() polyfill for older browsers if (!Element.prototype.closest) { Element.prototype.closest = function(selector) { var element = this; while (element && element.nodeType === 1) { if (element.matches && element.matches(selector)) { return element; } element = element.parentElement || element.parentNode; } return null; }; } // Element.matches() polyfill for older browsers if (!Element.prototype.matches) { Element.prototype.matches = Element.prototype.msMatchesSelector || Element.prototype.mozMatchesSelector || function(selector) { var element = this; var matches = (element.document || element.ownerDocument).querySelectorAll(selector); var i = matches.length; while (--i >= 0 && matches.item(i) !== element) {} return i > -1; }; } // 强制定义全局函数,立即可用 window.hljs = window.hljs || {}; window.hljs.copyCode = function(event) { console.log('[CSDNGreener] hljs.copyCode 函数被调用'); try { event = event || window.event; var target = event.target || event.srcElement; console.log('[CSDNGreener] 按钮目标元素:', target); console.log('[CSDNGreener] 按钮类名:', target.className); // 查找代码块的多种策略,根据CSDN实际DOM结构优化 var codeElement = null; // 策略1:直接查找同级pre元素下的code(CSDN标准结构) // 按钮在 pre > div.opt-box > div.hljs-button,代码在 pre > code var preElement = target.closest ? target.closest('pre') : findParentByTag(target, 'PRE'); if (preElement) { console.log('[CSDNGreener] 找到父级pre元素:', preElement); // 查找直接子级code元素 codeElement = preElement.querySelector('code.hljs'); if (!codeElement) { codeElement = preElement.querySelector('code'); } console.log('[CSDNGreener] 在pre中找到的code:', codeElement); } // 策略2:如果按钮在opt-box内,查找同级code if (!codeElement && target.closest) { var optBox = target.closest('.opt-box'); if (optBox && optBox.parentElement) { codeElement = optBox.parentElement.querySelector('code'); console.log('[CSDNGreener] 通过opt-box找到的code:', codeElement); } } // 策略3:向上遍历,查找包含code的容器 if (!codeElement) { var parent = target.parentElement; while (parent && parent !== document.body) { var codes = parent.querySelectorAll('code'); if (codes.length > 0) { // 优先选择有hljs类名的 for (var i = 0; i < codes.length; i++) { if (codes[i].className.indexOf('hljs') !== -1) { codeElement = codes[i]; break; } } if (!codeElement) { codeElement = codes[0]; } break; } parent = parent.parentElement; } console.log('[CSDNGreener] 通过向上遍历找到的code:', codeElement); } // 策略4:查找距离按钮最近的可见代码块 if (!codeElement) { var allCodes = document.querySelectorAll('code'); var minDistance = Infinity; var targetRect = target.getBoundingClientRect(); for (var i = 0; i < allCodes.length; i++) { if (isElementVisible(allCodes[i])) { var codeRect = allCodes[i].getBoundingClientRect(); var distance = Math.abs(targetRect.top - codeRect.top) + Math.abs(targetRect.left - codeRect.left); if (distance < minDistance) { minDistance = distance; codeElement = allCodes[i]; } } } console.log('[CSDNGreener] 通过距离查找到的code:', codeElement); } if (codeElement) { var codeText = getTextContent(codeElement); console.log('[CSDNGreener] 找到代码块,文本长度: ' + codeText.length); console.log('[CSDNGreener] 代码内容预览:', codeText.substring(0, 100)); if (codeText && codeText.trim()) { copyToClipboard(codeText, target); } else { console.error('[CSDNGreener] 代码块为空'); updateButtonText(target, '代码为空'); } } else { console.error('[CSDNGreener] 未找到代码块'); updateButtonText(target, '未找到代码'); } } catch (error) { console.error('[CSDNGreener] hljs.copyCode 错误:', error); updateButtonText(target, '复制失败'); } }; window.mdcp = window.mdcp || {}; window.mdcp.copyCode = function(event) { console.log('[CSDNGreener] mdcp.copyCode 函数被调用'); try { event = event || window.event; var target = event.target || event.srcElement; console.log('[CSDNGreener] mdcp 目标元素:', target); console.log('[CSDNGreener] mdcp 目标类名:', target.className); // 直接从点击的code元素获取文本 var text = getTextContent(target); if (text && text.trim()) { console.log('[CSDNGreener] mdcp 获取到文本长度:', text.length); copyToClipboard(text, target); } else { console.error('[CSDNGreener] mdcp 没有找到文本内容'); // 尝试从父级元素查找 if (target.parentElement) { text = getTextContent(target.parentElement); if (text && text.trim()) { console.log('[CSDNGreener] mdcp 从父级获取到文本'); copyToClipboard(text, target); } else { console.error('[CSDNGreener] mdcp 父级也没有文本'); } } } } catch (error) { console.error('[CSDNGreener] mdcp.copyCode 错误:', error); } }; // 辅助函数:获取文本内容,专门针对CSDN代码块优化 function getTextContent(element) { if (!element) return ''; try { // 对于CSDN的代码块,需要特殊处理 if (element.tagName === 'CODE' && element.className.indexOf('hljs') !== -1) { // 先尝试克隆元素,移除不需要的子元素 var clone = element.cloneNode(true); // 移除行号、按钮等无关元素 var removeSelectors = [ '.pre-numbering', '.hljs-button', '.opt-box', '.btn-code-notes', 'ul.pre-numbering' ]; removeSelectors.forEach(function(selector) { var elements = clone.querySelectorAll(selector); for (var i = 0; i < elements.length; i++) { elements[i].remove(); } }); // 获取纯文本 var text = clone.innerText || clone.textContent || ''; // 清理可能的多余空白和行号 text = text.replace(/^\d+\s*/gm, ''); // 移除行首的数字(行号) text = text.replace(/\n\s*\n/g, '\n'); // 合并多个空行 text = text.trim(); if (text) { console.log('[CSDNGreener] 从hljs code提取的文本:', text.substring(0, 100) + '...'); return text; } } // 标准文本提取 var text = element.innerText || element.textContent || ''; // 基础清理 if (text) { text = text.replace(/^\d+\s*/gm, ''); // 移除可能的行号 text = text.trim(); } return text; } catch (error) { console.error('[CSDNGreener] getTextContent 错误:', error); // 降级方案 return element.innerText || element.textContent || ''; } } // 辅助函数:检查元素是否可见 function isElementVisible(element) { if (!element) return false; var style = window.getComputedStyle ? window.getComputedStyle(element) : element.currentStyle; return style && style.display !== 'none' && style.visibility !== 'hidden'; } // 辅助函数:通过标签名查找父元素(兼容各种浏览器) function findParentByTag(element, tagName) { if (!element) return null; var parent = element.parentElement || element.parentNode; tagName = tagName.toUpperCase(); while (parent && parent.nodeType === 1 && parent !== document.body) { if (parent.tagName === tagName) { return parent; } parent = parent.parentElement || parent.parentNode; } return null; } // 辅助函数:复制到剪贴板,增强版 function copyToClipboard(text, target) { if (!text || !text.trim()) { console.error('[CSDNGreener] 复制文本为空'); if (target) updateButtonText(target, '文本为空'); return; } console.log('[CSDNGreener] 准备复制文本长度:', text.length); console.log('[CSDNGreener] 复制文本预览:', text.substring(0, 50) + '...'); try { // 方法1:现代浏览器 Clipboard API if (navigator.clipboard && window.isSecureContext) { navigator.clipboard.writeText(text).then(function() { console.log('[CSDNGreener] Clipboard API 复制成功'); if (target) updateButtonText(target, '复制成功'); }).catch(function(err) { console.log('[CSDNGreener] Clipboard API 失败,尝试备用方案:', err); fallbackCopy(text, target); }); } else { console.log('[CSDNGreener] Clipboard API 不可用,使用备用方案'); // 方法2:备用方案 fallbackCopy(text, target); } } catch (error) { console.error('[CSDNGreener] 复制失败:', error); fallbackCopy(text, target); } } // 辅助函数:备用复制方法,增强版 function fallbackCopy(text, target) { console.log('[CSDNGreener] 使用备用复制方法'); try { // 方法1:使用 textarea var textarea = document.createElement('textarea'); textarea.value = text; textarea.style.position = 'fixed'; textarea.style.left = '-999999px'; textarea.style.top = '-999999px'; textarea.style.opacity = '0'; textarea.style.zIndex = '-1'; textarea.setAttribute('readonly', ''); textarea.setAttribute('tabindex', '-1'); document.body.appendChild(textarea); // 确保元素可以被选择 textarea.focus(); textarea.select(); // 对于移动设备,可能需要设置 selectionRange if (textarea.setSelectionRange) { textarea.setSelectionRange(0, text.length); } var successful = false; try { successful = document.execCommand('copy'); } catch (execError) { console.error('[CSDNGreener] execCommand 错误:', execError); } document.body.removeChild(textarea); if (successful) { console.log('[CSDNGreener] 备用复制成功'); if (target) updateButtonText(target, '复制成功'); } else { console.error('[CSDNGreener] 备用复制失败,尝试最后手段'); lastResortCopy(text, target); } } catch (error) { console.error('[CSDNGreener] 备用复制错误:', error); lastResortCopy(text, target); } } // 辅助函数:最后的复制手段 function lastResortCopy(text, target) { try { // 尝试使用 ClipboardJS(如果已加载) if (typeof ClipboardJS !== 'undefined') { console.log('[CSDNGreener] 尝试使用 ClipboardJS'); var tempBtn = document.createElement('button'); tempBtn.setAttribute('data-clipboard-text', text); tempBtn.style.display = 'none'; document.body.appendChild(tempBtn); var clipboard = new ClipboardJS(tempBtn); clipboard.on('success', function() { console.log('[CSDNGreener] ClipboardJS 复制成功'); if (target) updateButtonText(target, '复制成功'); clipboard.destroy(); document.body.removeChild(tempBtn); }); clipboard.on('error', function() { console.error('[CSDNGreener] ClipboardJS 复制失败'); if (target) updateButtonText(target, '复制失败'); clipboard.destroy(); document.body.removeChild(tempBtn); }); tempBtn.click(); } else { console.error('[CSDNGreener] 所有复制方法都失败了'); if (target) updateButtonText(target, '复制失败'); // 作为最后手段,显示文本让用户手动复制 if (confirm('自动复制失败,是否显示代码让您手动复制?')) { prompt('请手动复制以下代码:', text); } } } catch (error) { console.error('[CSDNGreener] 最后复制手段失败:', error); if (target) updateButtonText(target, '复制失败'); } } // 辅助函数:更新按钮文本 function updateButtonText(target, text) { if (target && target.setAttribute) { target.setAttribute('data-title', text); setTimeout(function() { target.setAttribute('data-title', '免登录复制'); }, 2000); } } console.log('[CSDNGreener] 复制函数已定义完成'); // 验证函数是否正确定义 if (typeof window.hljs.copyCode === 'function') { console.log('[CSDNGreener] ✓ hljs.copyCode 函数定义成功'); } else { console.error('[CSDNGreener] ✗ hljs.copyCode 函数定义失败'); } if (typeof window.mdcp.copyCode === 'function') { console.log('[CSDNGreener] ✓ mdcp.copyCode 函数定义成功'); } else { console.error('[CSDNGreener] ✗ mdcp.copyCode 函数定义失败'); } // 添加到全局作用域,确保兼容性 if (typeof unsafeWindow !== 'undefined') { unsafeWindow.hljs = unsafeWindow.hljs || {}; unsafeWindow.hljs.copyCode = window.hljs.copyCode; unsafeWindow.mdcp = unsafeWindow.mdcp || {}; unsafeWindow.mdcp.copyCode = window.mdcp.copyCode; console.log('[CSDNGreener] 函数已添加到 unsafeWindow'); } })(); var currentURL = window.location.href; if (currentURL.indexOf("?") !== -1) { currentURL = currentURL.substring(0, currentURL.indexOf("?")); } var list; var windowTop = 0; var startTimeMilli = Date.now(); var stopTimeMilli = 0; // 配置控制类 class Config { get(key, value) { var cookie = $.cookie(key); if (cookie == undefined) { new Config().set(key, value); console.debug("Renew key: " + key + " : " + value); return value; } console.debug("Read key: " + key + " : " + cookie); if (cookie === "true") { return true; } if (cookie === "false") { return false; } return cookie; } getS(key, value) { var cookie = $.cookie(key); if (cookie == undefined) { new Config().set(key, value); console.debug("Renew key: " + key + " : " + value); return value; } console.debug("Read key: " + key + " : " + cookie); return cookie; } set(setKey, setValue) { $.cookie(setKey, setValue, { path: '/', expires: 365 }); console.debug("Key set: " + setKey + " : " + setValue); } listenButton(element, listenKey, trueAction, falseAction) { $(element).click(function () { let status = new Config().get(listenKey, true); console.debug("Status: " + status); if (status === "true" || status) { console.debug("Key set: " + listenKey + " :: " + false); new Config().set(listenKey, false); } else { console.debug("Key set: " + listenKey + " :: " + true); new Config().set(listenKey, true); } }); } listenButtonAndAction(element, listenKey, trueAction, falseAction) { $(element).click(function () { let status = new Config().get(listenKey, true); console.debug("Status: " + status); if (status === "true" || status) { console.debug("Key set: " + listenKey + " :: " + false); new Config().set(listenKey, false); falseAction(); } else { console.debug("Key set: " + listenKey + " :: " + true); new Config().set(listenKey, true); trueAction(); } }); } } var config = new Config(); var progress = 0; class Progress { init() { progress = 0; NProgress.start(); $("#greenerProgress").text("绿化中..."); $(".toolbar-search").hide(); } setProgress(p) { progress = p; $("#greenerProgress").text(progress + "%"); NProgress.set(progress / 100); console.log(progress + "%"); } incProgress(p) { progress = progress + p; progress = progress > 100 ? 100 : progress; $("#greenerProgress").text(progress + "%"); NProgress.set(progress / 100); console.log(progress + "%"); } done() { progress = 100; NProgress.done(); $("#greenerProgress").html(protect_svg + ' CSDNGreener 正在守护您的浏览体验'); setTimeout(function() { $("#greenerProgress").fadeOut(500); setTimeout(function() { $(".toolbar-search").fadeIn(500); if (!isFirefox()) { // 提示 let tipsCookie = config.get("showTip", true); if (tipsCookie) { showTips(); } config.set("showTip", false); } }, 500); }, 1500); } } var progressor = new Progress(); // 自定义 CSS // 进度条 $('head').append("<style>#nprogress{pointer-events:none}#nprogress .bar{background:#f44444;position:fixed;z-index:1031;top:0;left:0;width:100%;height:2px}#nprogress .peg{display:block;position:absolute;right:0;width:100px;height:100%;box-shadow:0 0 10px #f44444,0 0 5px #f44444;opacity:1;-webkit-transform:rotate(3deg) translate(0,-4px);-ms-transform:rotate(3deg) translate(0,-4px);transform:rotate(3deg) translate(0,-4px)}#nprogress .spinner{display:block;position:fixed;z-index:1031;top:15px;right:15px}#nprogress .spinner-icon{width:18px;height:18px;box-sizing:border-box;border:solid 2px transparent;border-top-color:#f44444;border-left-color:#f44444;border-radius:50%;-webkit-animation:nprogress-spinner .4s linear infinite;animation:nprogress-spinner .4s linear infinite}.nprogress-custom-parent{overflow:hidden;position:relative}.nprogress-custom-parent #nprogress .bar,.nprogress-custom-parent #nprogress .spinner{position:absolute}@-webkit-keyframes nprogress-spinner{0%{-webkit-transform:rotate(0)}100%{-webkit-transform:rotate(360deg)}}@keyframes nprogress-spinner{0%{transform:rotate(0)}100%{transform:rotate(360deg)}}</style>"); // 设置窗口 $('head').append("<style>.black_overlay{top:0%;left:0%;width:100%;height:100%;background-color:#000;z-index:1001;-moz-opacity:0.8;opacity:.10;filter:alpha(opacity=88)}.black_overlay,.white_content{display:none;position:absolute}.white_content{z-index:9999!important;top:5%;left:50%;transform:translateX(-50%);width:700px;max-width:90vw;height:80vh;max-height:600px;padding:0;border:0px;background-color:rgba(255,255,255,0.98);border-radius:12px;box-shadow:0 10px 40px rgba(0,0,0,0.3);overflow:hidden;will-change:transform;backface-visibility:hidden}.config-header{background:linear-gradient(135deg,#667eea 0%,#764ba2 100%);color:white;padding:20px 25px;position:relative;border-radius:12px 12px 0 0}.config-header h2{margin:0;font-size:24px;font-weight:600}.config-content{padding:25px;height:calc(100% - 140px);overflow-y:auto;scrollbar-width:thin;scrollbar-color:#667eea #f1f1f1;contain:layout style paint}.config-content::-webkit-scrollbar{width:8px}.config-content::-webkit-scrollbar-track{background:#f1f1f1;border-radius:4px}.config-content::-webkit-scrollbar-thumb{background:#667eea;border-radius:4px}.config-content::-webkit-scrollbar-thumb:hover{background:#5a67d8}.config-footer{position:absolute;bottom:0;left:0;right:0;background:#f8f9fa;padding:15px 25px;border-top:1px solid #e2e8f0;border-radius:0 0 12px 12px;display:flex;justify-content:space-between;align-items:center}.config-close-btn{position:absolute;top:15px;right:20px;background:rgba(255,255,255,0.2);border:none;color:white;width:35px;height:35px;border-radius:50%;cursor:pointer;font-size:20px;display:flex;align-items:center;justify-content:center;transition:all 0.3s ease}.config-close-btn:hover{background:rgba(255,255,255,0.3);transform:scale(1.1)}.saveButton{background:linear-gradient(135deg,#667eea 0%,#764ba2 100%);color:white;border:none;padding:12px 24px;border-radius:8px;cursor:pointer;font-size:14px;font-weight:500;transition:all 0.3s ease;display:flex;align-items:center;gap:8px}.saveButton:hover{transform:translateY(-2px);box-shadow:0 5px 15px rgba(102,126,234,0.4)}.saveButton:disabled{opacity:0.6;cursor:not-allowed;transform:none;box-shadow:none}.cancelButton{background:#6c757d;color:white;border:none;padding:12px 24px;border-radius:8px;cursor:pointer;font-size:14px;font-weight:500;transition:all 0.3s ease}.cancelButton:hover{background:#5a6268;transform:translateY(-2px)}</style>"); // 提示条 $('head').append("<style>.tripscon{padding:10px}</style>"); // 按钮(旧) $('head').append("<style>#toggle-button{display:none}.button-label{position:relative;display:inline-block;width:82px;background-color:#ccc;border:1px solid #ccc;border-radius:30px;cursor:pointer}.circle{position:absolute;top:0;left:0;width:30px;height:30px;border-radius:50%;background-color:#fff}.button-label .text{line-height:30px;font-size:18px;-webkit-user-select:none;user-select:none}.on{color:#fff;display:none;text-indent:10px}.off{color:#fff;display:inline-block;text-indent:53px}.button-label .circle{left:0;transition:all .3s}#toggle-button:checked+label.button-label .circle{left:50px}#toggle-button:checked+label.button-label .on{display:inline-block}#toggle-button:checked+label.button-label .off{display:none}#toggle-button:checked+label.button-label{background-color:#78d690}</style>"); // 保存按钮 $('head').append("<style>.saveButton{background-color:#19a4ed;border:none;color:#fff;padding:5px 15px;text-align:center;text-decoration:none;display:inline-block;font-size:14px;cursor:pointer}</style>"); // Star 样式 $('head').append("<style>.giveMeOneStar:hover{color:#FF69B4;}</style>"); // 设置窗口文字效果和现代化配置选项样式 if (isFirefox()) { $('head').append("<style>.configContainer label{font-size:15px}.configContainer p{font-size:15px}.giveMeOneStar{font-size:15px}.configContainer .title{font-size:20px}.configContainer .bold{font-weight:bold;margin-bottom:5px}</style>"); } else { $('head').append("<style>.configContainer label{font-size:12px}.configContainer p{font-size:12px}.giveMeOneStar{font-size:15px}.configContainer .title{font-size:20px}.configContainer .bold{font-weight:bold;margin-bottom:5px}</style>"); } // 现代化配置选项样式 $('head').append(`<style> .config-option { background: #fff; border: 1px solid #e2e8f0; border-radius: 8px; padding: 16px; margin-bottom: 12px; transition: all 0.3s ease; } .config-option:hover { border-color: #667eea; box-shadow: 0 2px 8px rgba(102,126,234,0.1); } .config-option-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; } .config-option-title { font-weight: 600; color: #2d3748; font-size: 14px; margin: 0; } .config-option-desc { color: #718096; font-size: 12px; margin: 0; line-height: 1.4; } .toggle-switch { position: relative; display: inline-block; width: 48px; height: 24px; } .toggle-switch input { opacity: 0; width: 0; height: 0; } .slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #cbd5e0; transition: .3s; border-radius: 24px; } .slider:before { position: absolute; content: ""; height: 18px; width: 18px; left: 3px; bottom: 3px; background-color: white; transition: .3s; border-radius: 50%; box-shadow: 0 2px 4px rgba(0,0,0,0.2); } input:checked + .slider { background-color: #667eea; } input:checked + .slider:before { transform: translateX(24px); } .config-section { margin-bottom: 24px; } .config-section-title { font-size: 16px; font-weight: 600; color: #2d3748; margin-bottom: 16px; padding-bottom: 8px; border-bottom: 2px solid #667eea; display: flex; align-items: center; gap: 8px; } .giveMeOneStar { display: inline-block; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white !important; text-decoration: none !important; padding: 12px 20px; border-radius: 8px; margin: 8px 0; transition: all 0.3s ease; font-weight: 500; } .giveMeOneStar:hover { transform: translateY(-2px); box-shadow: 0 5px 15px rgba(102,126,234,0.4); color: white !important; } /* 单选按钮样式 */ input[type="radio"] { appearance: none; width: 16px; height: 16px; border: 2px solid #cbd5e0; border-radius: 50%; position: relative; cursor: pointer; transition: all 0.3s ease; } input[type="radio"]:checked { border-color: #667eea; background-color: #667eea; } input[type="radio"]:checked::before { content: ''; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 6px; height: 6px; border-radius: 50%; background-color: white; } /* 单选按钮标签悬停效果 */ label:has(input[type="radio"]):hover { border-color: #667eea !important; background-color: #f7fafc !important; } label:has(input[type="radio"]:checked) { border-color: #667eea !important; background-color: #edf2f7 !important; } /* 背景图片处理相关样式 */ .background-loading { color: #667eea; font-weight: 500; } .background-success { color: #10b981; font-weight: 500; } .background-error { color: #ef4444; font-weight: 500; } .background-warning { color: #f59e0b; font-weight: 500; } #backgroundPreview img { transition: all 0.3s ease; } #backgroundPreview:hover img { transform: scale(1.05); } /* 性能优化相关样式 */ .config-content * { will-change: auto; } .config-option { contain: layout style; } /* 防止大图片导致的性能问题 */ #backgroundPreview { contain: strict; transform: translateZ(0); /* 添加加载状态样式 */ } #backgroundPreview.loading { background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%); background-size: 200% 100%; animation: loading-shimmer 1.5s infinite; } @keyframes loading-shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } } /* 设置窗口性能优化 */ .white_content { transform: translate3d(-50%, 0, 0); backface-visibility: hidden; perspective: 1000px; /* GPU加速 */ will-change: transform, opacity; } .config-content { /* 虚拟滚动优化 */ contain: layout style paint; /* GPU加速滚动 */ transform: translateZ(0); -webkit-overflow-scrolling: touch; } /* 图片相关优化 */ #backgroundPreview img { transition: all 0.3s ease; /* 图片渲染优化 */ image-rendering: -webkit-optimize-contrast; image-rendering: crisp-edges; contain: layout style size; } #backgroundPreview:hover img { transform: scale(1.05); } /* 输入框优化 */ #backgroundImgUrl { contain: layout style; will-change: contents; } /* 按钮动画优化 */ .saveButton, .cancelButton, .config-close-btn { contain: layout style; will-change: transform, background-color; } /* 状态指示器优化 */ #backgroundStatus { contain: layout style; transform: translateZ(0); } </style>`); // SVG //var save_svg = '<svg t="1595082650173" class="icon" viewBox="0 0 1075 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2078" width="140" height="140"><path d="M753.763902 685.830244a48.952195 48.952195 0 0 1 49.152-48.702439c81.420488 0 141.162146-65.386146 141.162147-146.057366 0-43.507512-13.037268-82.419512-43.457561-109.243317a142.360976 142.360976 0 0 0-20.280195-14.935415 158.045659 158.045659 0 0 0-11.239025-6.243902l-2.747317-1.298732a155.847805 155.847805 0 0 0-9.191024-3.996097c-1.348683-0.549463-2.697366-0.999024-4.096-1.498537a152.35122 152.35122 0 0 0-8.491707-2.847219c-1.948098-0.599415-3.896195-0.999024-5.844293-1.498537-2.497561-0.599415-4.945171-1.24878-7.492683-1.748293-2.597463-0.499512-5.34478-0.899122-8.042146-1.24878-1.948098-0.249756-3.846244-0.599415-5.844293-0.79922a153.150439 153.150439 0 0 0-14.435903-0.749268c-1.498537 0-2.997073 0.199805-4.545561 0.249756a265.390829 265.390829 0 0 0-5.594536-24.526049c-0.499512-1.998049-1.298732-3.846244-1.898146-5.844292a267.438829 267.438829 0 0 0-5.944196-17.982439c-0.649366-1.798244-1.498537-3.496585-2.197853-5.29483a283.123512 283.123512 0 0 0-7.742439-17.732683L772.745366 269.736585a282.973659 282.973659 0 0 0-9.790439-17.832585C714.302439 171.582439 625.88878 124.878049 524.487805 124.878049c-101.400976 0-189.914537 46.654439-238.517073 126.976-3.496585 5.794341-6.693463 11.788488-9.790439 17.832585l-2.197854 4.096a283.523122 283.523122 0 0 0-7.742439 17.732683l-2.197854 5.244878c-2.247805 5.894244-4.145951 11.988293-5.994146 18.03239-0.549463 1.998049-1.298732 3.846244-1.848195 5.844293a266.739512 266.739512 0 0 0-5.594537 24.476098c-1.498537 0-2.997073-0.199805-4.545561-0.199805-4.89522 0-9.690537 0.299707-14.485853 0.749268-1.998049 0.199805-3.846244 0.499512-5.794342 0.79922-2.697366 0.349659-5.444683 0.699317-8.092097 1.24878-2.497561 0.499512-4.995122 1.148878-7.492683 1.748293-1.898146 0.499512-3.846244 0.899122-5.794342 1.498536a153.649951 153.649951 0 0 0-8.491707 2.797269l-4.096 1.498536a164.289561 164.289561 0 0 0-9.240976 3.996098l-2.697366 1.348683a145.557854 145.557854 0 0 0-31.469268 21.179317C117.884878 408.600976 104.897561 447.562927 104.897561 491.070439c0 80.67122 59.741659 146.057366 141.162146 146.057366a48.952195 48.952195 0 0 1 49.152 48.702439 48.952195 48.952195 0 0 1-49.152 48.702439c-135.717463 0-245.710049-108.993561-245.710048-243.462244 0-109.692878 73.228488-202.402341 173.830243-232.872585A375.832976 375.832976 0 0 1 524.487805 20.330146a375.882927 375.882927 0 0 1 350.307902 237.867708c100.601756 30.470244 173.830244 123.179707 173.830244 232.872585 0 134.468683-109.992585 243.462244-245.710049 243.462244a48.952195 48.952195 0 0 1-49.102048-48.702439z" p-id="2079"></path><path d="M487.973463 386.122927a49.102049 49.102049 0 0 1 72.928781 0.099902l147.356097 162.041756c6.993171 7.742439 11.48878 19.431024 12.537757 30.120586l0.249756 12.937366c0 19.480976-20.48 39.661268-39.211708 39.661268h-104.897561v262.993171a52.44878 52.44878 0 1 1-104.897561 0v-262.993171h-104.897561c-13.886439 0-39.211707-21.72878-39.211707-39.661268v-12.987317c0-12.487805 4.795317-21.27922 12.637659-29.920781l147.356097-162.291512z" p-id="2080"></path></svg>'; var star_svg_1 = '<svg t="1595083631685" class="icon" viewBox="0 0 1051 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2173" width="140" height="140"><path d="M525.837838 852.410811L199.264865 1001.859459l41.513513-357.016216L0 381.924324l351.481081-69.189189L525.837838 0l174.356757 312.735135L1051.675676 381.924324l-240.778379 262.918919 41.513514 357.016216z" fill="#FFD566" p-id="2174"></path></svg>'; var star_svg_2 = ' <svg t="1595083715312" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="7848" width="140" height="140"><path d="M1014.001347 866.090236L810.23569 662.324579l145.497643-84.126599c11.377778-6.550842 17.92862-18.962963 16.894276-32.064647-1.034343-13.101684-9.309091-24.479461-21.376431-29.306397l-648.188552-258.585859c-12.756902-5.171717-27.23771-2.068687-36.891582 7.585186-9.653872 9.653872-12.756902 24.13468-7.585185 36.891582l258.585858 648.533333c4.826936 12.06734 16.204714 20.686869 29.306397 21.376431 13.101684 1.034343 25.513805-5.516498 32.064647-16.894276l84.126599-145.497643 203.765657 203.765657c6.550842 6.550842 15.17037 9.998653 24.13468 9.998653 8.96431 0 17.92862-3.447811 24.13468-9.998653l99.29697-99.29697c13.446465-13.446465 13.446465-35.167677 0-48.614141zM150.324579 102.055219c-13.446465-13.446465-35.167677-13.446465-48.26936 0-13.446465 13.446465-13.446465 35.167677 0 48.26936l76.196633 76.196633c6.550842 6.550842 15.515152 9.998653 24.13468 9.998653s17.583838-3.447811 24.13468-9.998653c13.446465-13.446465 13.446465-35.167677 0-48.26936L150.324579 102.055219zM176.183165 338.575084c0-18.962963-15.17037-34.133333-34.133333-34.133333H34.133333c-18.962963 0-34.133333 15.17037-34.133333 34.133333s15.17037 34.133333 34.133333 34.133334h107.571718c18.962963 0 34.478114-15.17037 34.478114-34.133334zM162.391919 444.422896l-76.196633 75.851851c-13.446465 13.446465-13.446465 35.167677 0 48.269361 6.550842 6.550842 15.515152 9.998653 24.13468 9.998653s17.583838-3.447811 24.13468-9.998653l76.196633-76.196633c13.446465-13.446465 13.446465-35.167677 0-48.269361-13.446465-13.101684-35.167677-13.101684-48.26936 0.344782zM338.575084 176.183165c18.962963 0 34.133333-15.17037 34.133334-34.133333V34.133333c0-18.962963-15.17037-34.133333-34.133334-34.133333s-34.133333 15.17037-34.133333 34.133333v107.571718c0 18.962963 15.17037 34.478114 34.133333 34.478114zM468.557576 220.659933c8.619529 0 17.583838-3.447811 24.13468-9.998654L568.888889 134.464646c13.446465-13.446465 13.446465-35.167677 0-48.26936-13.446465-13.446465-35.167677-13.446465-48.26936 0l-76.196633 76.196633c-13.446465 13.446465-13.446465 35.167677 0 48.26936 6.550842 6.550842 15.515152 9.998653 24.13468 9.998654z" fill="#2c2c2c" p-id="7849"></path></svg>'; var star_svg_3 = ' <svg t="1595083925438" class="icon" viewBox="0 0 1204 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4809" width="140" height="140"><path d="M1088.864348 618.13701a1555.009384 1555.009384 0 0 1-150.273004 167.137308c-52.881642 51.195212-107.931552 101.18583-163.643989 147.261521-33.849069 27.524955-60.229661 48.665566-76.190521 60.229661a162.981462 162.981462 0 0 1-191.891699 0c-15.539253-12.045932-42.160763-32.644476-76.190521-60.831957a2638.480754 2638.480754 0 0 1-164.366745-147.261521 1579.101249 1579.101249 0 0 1-150.273004-165.812257A468.104924 468.104924 0 0 1 0.152998 344.754579 315.543193 315.543193 0 0 1 109.048225 96.367457a399.443111 399.443111 0 0 1 493.883219-20.478084 398.660125 398.660125 0 0 1 493.883219 20.478084A315.482964 315.482964 0 0 1 1204.746215 343.309067a466.840101 466.840101 0 0 1-115.701178 274.647254z" fill="#FE4B83" p-id="4810"></path></svg>'; var star_svg_4 = ' <svg t="1595084089115" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="8008" width="140" height="140"><path d="M512 46.545455C256 46.545455 46.545455 256 46.545455 512s209.454545 465.454545 465.454545 465.454545 465.454545-209.454545 465.454545-465.454545S768 46.545455 512 46.545455z m0 837.818181c-204.8 0-372.363636-167.563636-372.363636-372.363636s167.563636-372.363636 372.363636-372.363636 372.363636 167.563636 372.363636 372.363636-167.563636 372.363636-372.363636 372.363636z" fill="#00C5C5" p-id="8009"></path><path d="M656.290909 586.472727c-79.127273 69.818182-209.454545 69.818182-288.581818 0-18.618182-13.963636-41.890909-13.963636-60.509091 4.654546-13.963636 13.963636-13.963636 41.890909 4.654545 60.509091 55.854545 51.2 125.672727 74.472727 200.145455 74.472727s144.290909-27.927273 200.145455-74.472727c18.618182-13.963636 18.618182-41.890909 4.654545-60.509091s-41.890909-18.618182-60.509091-4.654546zM358.4 460.8c27.927273 0 51.2-23.272727 51.2-51.2s-23.272727-55.854545-51.2-55.854545c-27.927273 0-51.2 23.272727-51.2 51.2s23.272727 55.854545 51.2 55.854545zM665.6 460.8c27.927273 0 51.2-23.272727 51.2-51.2s-23.272727-51.2-51.2-51.2-51.2 23.272727-51.2 51.2 23.272727 51.2 51.2 51.2z" fill="#00C5C5" p-id="8010"></path></svg>'; var donate_svg = '<svg t="1592982508258" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4207" width="32" height="32"><path d="M664.48 234.432a32 32 0 0 0-45.248-0.8l-76.256 73.6-73.344-73.216a32 32 0 1 0-45.248 45.312l72.384 72.256h-49.28a32 32 0 0 0 0 64h63.776v32h-63.776a32 32 0 0 0 0 64h63.776v65.664a32 32 0 1 1-104.897561 0v-262.993171h-104.897561c-13.886439 0-39.211707-21.72878-39.211707-39.661268v-12.987317c0-12.487805 4.795317-21.27922 12.637659-29.920781l147.356097-162.291512z" p-id="4208"></path></svg>'; var set_svg = '<svg t="1592982970375" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="10112" width="48" height="48"><path d="M256 102.4h512l256 256-512 563.2L0 358.4z" fill="#26CD63" p-id="10113"></path><path d="M256 102.4l256 256H0zM768 102.4l256 256H512zM512 921.6l204.8-563.2H307.2z" fill="#14A345" p-id="10114"></path></svg>'; var save_svg = '<svg t="1629448588351" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="7849" width="200" height="200"><path d="M512 0C229.2 0 0 229.2 0 512s229.2 512 512 512 512-229.2 512-512S794.8 0 512 0z m0 945.2C273.1 945.2 78.8 750.9 78.8 512S273.1 78.8 512 78.8 945.2 273.1 945.2 512 750.9 945.2 512 945.2z" p-id="7850" fill="#ffffff"></path><path d="M680.9 359.4L461 582.3 341.6 473.6c-16-14.6-41-13.4-55.6 2.6-14.7 16.1-13.5 41 2.6 55.6L436 666.1c7.5 6.8 17 10.2 26.5 10.2 10.2 0 20.3-3.9 28-11.7L737 414.7c15.3-15.5 15.1-40.4-0.4-55.7-15.5-15.2-40.5-15.1-55.7 0.4z" p-id="7851" fill="#ffffff"></path></svg>'; var settings_svg = '<svg t="1629433360462" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2870" width="200" height="200"><path d="M1006.438 17.548c-0.032 0-430.43-112.966-780.45 237.022-288.99 289.008-33.522 576.966-33.522 576.966s287.958 255.484 576.952-33.55C1119.436 448.012 1006.468 17.612 1006.438 17.548z" fill="#9ED36A" p-id="2871"></path><path d="M1006.438 17.548l-42.674-8.216c0.032 0.062 112.998 438.678-236.99 788.652-96.344 96.406-192.598 132.208-278.104 137.144 95.41 5.5 208-24.368 320.748-137.144C1119.436 448.012 1006.468 17.612 1006.438 17.548z" fill="#FFFFFF" opacity=".2" p-id="2872"></path><path d="M600.406 423.612c-8.308-8.34-21.836-8.34-30.148 0L6.4 987.426c-8.326 8.372-8.326 21.868 0 30.18 8.326 8.308 21.822 8.308 30.162 0L600.406 453.76c8.34-8.342 8.34-21.838 0-30.148z" fill="#8AC054" p-id="2873"></path></svg>'; var protect_svg = '<svg t="1629560538805" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3212" width="200" height="200"><path d="M800.3 205.1L534.8 116c-16-5.4-33.3-5.3-49.2 0.2l-264.5 92.3c-29.3 10-49 37.5-49.1 68.4l1.7 265.4c0.7 81 31.1 158.9 85.6 218.9 25 27.7 56.9 51.5 97.8 72.7l144 74.6c9 4.7 19.7 4.6 28.7-0.2L672.5 832c40.4-21.6 72.2-45.7 96.9-73.8 53.6-60.6 83-138.9 82.6-219.8l-1.7-265.6c-0.5-30.9-20.5-58.1-50-67.7z" fill="#07C160" p-id="3213"></path><path d="M474.1 652c-7.1 0-13.8-2.8-18.9-7.8l-151-151.1c-10.4-10.4-10.4-27.4 0-37.8s27.4-10.4 37.8 0l132.1 132.2 207.7-207.7c10.4-10.4 27.4-10.4 37.8 0 10.4 10.4 10.4 27.4 0 37.8L493 644.2c-5 5-11.8 7.8-18.9 7.8z" fill="#FFFFFF" p-id="3214"></path></svg>'; // jquery.showtips.js (function(jQuery) { jQuery.fn.showTips = function(options,elem){ var config = { skin:"trips", content:$(this).attr("tips")||"弹出类型的气泡提示!", //气泡提示内容里面可以是HTML,默认显示自定义的提示内容 width:"auto", //默认为auto,可以写具体尺寸如:200 alignTo:["right","center"], //箭头方向 color:["rgb(247, 206, 57)","#FFFEF4"], //这里是提示层的风格,第一个参数为提示边框颜色,第二个参数为提示背景颜色 type:"html", //显示内容类型 trigger:"click", //默认为点击显示,show为初始化就显示,hover为经过显示,focus焦点显示,mouse跟随鼠标显示隐藏 spacing:10, //默认为箭头距离对象的尺寸 customid:"", //自定义ID isclose:false, //是否显示关闭按钮 success : null //成功后的回调函数 }; var opts = jQuery.extend(config, options); return this.each(function(){ var that = jQuery(this),tipBox,tipId,selfH,selfW,conId,docW, spa = opts.spacing, skin=opts.skin; var Mathrandom = Math.floor(Math.random() * 9999999); var pmr = (opts.customid=="") ? Mathrandom :opts.customid.replace(/[#.]/, ""); var pointer=opts.alignTo.length===1 ? ''+opts.alignTo[0]+'' : ''+opts.alignTo[0]+'-'+opts.alignTo[1]+''; if(typeof elem == 'string') { if(elem =="show"){ jQuery('#tip'+pmr).show(); jQuery("#con"+pmr).html(opts.content); showPosition(pointer,jQuery('#tip'+pmr)); }; if(elem =="hide"){jQuery('#tip'+pmr).hide()}; }; if(typeof elem == '' || typeof elem == undefined){return true}; if(jQuery('#tip'+pmr).length==1){return false;} tipBox=jQuery('<div class="'+skin+' '+skin+'-'+pointer+'" id="tip'+pmr+'"><i></i><em></em><div class="'+skin+'con" id="con'+pmr+'"></div></div>').appendTo(document.body); tipId = jQuery("#tip"+pmr); conId = jQuery("#con"+pmr); var edgecolor='border-'+opts.alignTo[0]+'-color', tfi=tipId.find("i"), tfem=tipId.find("em"), tfiem=tipId.find("i,em"); tipId.css({'position':'absolute',border:'1px solid','border-color':opts.color[0],'background-color':opts.color[1]}); if(opts.alignTo[1]=='center'){ var offpos=50,percen="%"; }else{ var offpos=5,percen="px"; }; tfiem.css({width:0,height:0,content:'','position':'absolute'}) tfi.css({border:'8px solid transparent','z-index':5}); tfem.css({border:'7px solid transparent','z-index':10}); switch (pointer) { case 'top-center': case 'bottom-center': case 'top-left': case 'bottom-left': var poi="left"; if(pointer=='top-center' || pointer=='bottom-center'){ tfi.css({"margin-left":"-8px"}); tfem.css({"margin-left":"-7px"}); } break; case 'left-center': case 'right-center': case 'left-top': case 'right-top': var poi="top"; if(pointer=='left-center' || pointer=='right-center'){ tfi.css({"margin-top":"-8px"}); tfem.css({"margin-top":"-7px"}); } break; default: var poi="right"; break; }; if(pointer=='follow'){ tfi.css({'border-bottom-color':opts.color[0],left:''+offpos+percen+'',bottom:'100%'}); tfem.css({'border-bottom-color':opts.color[1],left:''+(offpos+(opts.alignTo[1]=='center'?0:1))+percen+'',bottom:'100%'}); }else{ tfi.css(edgecolor,opts.color[0]).css(poi,''+offpos+percen+''); tfem.css(edgecolor,opts.color[1]).css(poi,''+(offpos+(opts.alignTo[1]=='center'?0:1))+percen+''); tfiem.css(opts.alignTo[0],'100%'); }; switch (opts.type) { case 'html':conId.html(opts.content); break; case 'id' : var tempid=jQuery(opts.content) ,wrap = document.createElement("div"); if(tempid.css("display") == "none"){ tempid.css({display:"block"}); } conId.append(tempid); break; }; if(opts.isclose){ jQuery('<span class="'+skin+'close" id="close'+pmr+'">×</span>').appendTo(tipId); tipId.find("#close"+pmr+"").on("click",function(){tipId.hide();}); } if(typeof opts.width === 'string'){ docW = parseInt(document.body.clientWidth*(opts.width.replace('%','')/100)); (typeof opts.width == 'auto' || typeof opts.width == '') ? tipBox.css({width:'auto'}) : tipBox.css({width:docW}); tipBox.height(); }else{ tipBox.width(opts.width).height(); } function showPosition(pointer,cell){ var selfH = that.outerHeight(true), selfW = that.outerWidth(true); var post=that.offset().top, posl=that.offset().left; var tipCell=(cell=="" || cell==undefined) ? tipId : cell; var tipH=tipCell.outerHeight(true), tipW=tipCell.outerWidth(true); switch (pointer) { case 'top-left': tipCell.css({top:post-tipH-spa,left:posl}); break; case 'top-center': tipCell.css({top:post-tipH-spa,left:posl-(tipW/2)+(selfW/2)}); break; case 'top-right': tipCell.css({top:post-tipH-spa,left:posl-(tipW-selfW)}); break; case 'bottom-left': tipCell.css({top:post+selfH+spa,left:posl}); break; case 'bottom-center': tipCell.css({top:post+selfH+spa,left:posl-(tipW/2)+(selfW/2)}); break; case 'bottom-right': tipCell.css({top:post+selfH+spa,left:posl-(tipW-selfW)}); break; case 'left-top': tipCell.css({top:post,left:posl-tipW-spa}); break; case 'left-center': tipCell.css({top:post-(tipH/2)+(selfH/2),left:posl-tipW-spa}); break; case 'right-top': tipCell.css({top:post,left:posl+selfW+spa}); break; case 'right-center': tipCell.css({top:post-(tipH/2)+(selfH/2),left:posl+selfW+spa}); break; case 'follow': that.mousemove(function(e) { tipCell.css({top:e.pageY + 30,left:e.pageX - 6}); }); break; }; } tipBox.hide(); switch (opts.trigger){ case 'show':showPosition(pointer);tipBox.show();break; case 'click':that.click(function(){showPosition(pointer);tipBox.show();});break; case 'hover':that.hover(function(){showPosition(pointer);tipBox.show(); tipBox.on("mouseover",function(){jQuery(this).show()}).on("mouseout",function(){jQuery(this).hide()})},function(){tipBox.hide();});break; case 'focus':that.focus(function(){showPosition(pointer);tipBox.show();}); that.blur(function(){tipBox.hide();});break; case 'mouse':that.hover(function(){showPosition(pointer);tipBox.show();},function(){tipBox.hide();});break; }; setTimeout(function(){opts.success && opts.success();}, 1); }); } })(jQuery); (function () { 'use strict'; l("CSDNGreener V" + version); if (isFirefox()) { console.log("您正在使用火狐浏览器,将使用兼容模式运行 CSDNGreener。"); } progressor.init(); // 绿化设定按钮点击事件 let jss = ""; jss += "<script>function showConfig() {"; jss += "$(window).scrollTop(0);"; jss += "$('.white_content').fadeIn(500);"; jss += "$('body').css('overflow', 'hidden');"; jss += "$('body').css('filter','blur(3px)');"; jss += "$('body').css('pointer-events','none')"; jss += "}"; // 添加关闭设置窗口的函数 jss += "function closeConfig() {"; jss += "$('.white_content').fadeOut(300);"; jss += "$('body').css('overflow', 'auto');"; jss += "$('body').css('filter','none');"; jss += "$('body').css('pointer-events','auto')"; jss += "}"; // ESC键关闭设置窗口 jss += "$(document).keydown(function(e) {"; jss += "if (e.keyCode === 27 && $('.white_content').is(':visible')) {"; jss += "closeConfig();"; jss += "}"; jss += "});"; // 点击遮罩层关闭 jss += "$(document).on('click', '.black_overlay', function() {"; jss += "closeConfig();"; jss += "});"; jss += "</script>"; $("body").append(jss); // 保存按钮点击事件 let saveJss = ""; saveJss += "<script>function saveAndReload() {"; saveJss += "var saveBtn = $('.saveButton');"; saveJss += "saveBtn.html('💾 保存中...');"; saveJss += "saveBtn.prop('disabled', true);"; saveJss += "$('body').css('overflow', 'auto');"; saveJss += "$('body').css('filter','none');"; saveJss += "$('body').css('pointer-events','auto');"; saveJss += "$('#configContent').fadeOut(300);"; saveJss += "setTimeout(function() {"; saveJss += "console.log('[CSDNGreener] 设置已保存,正在刷新页面...');"; saveJss += "location.reload();"; saveJss += "},500)"; saveJss += "}</script>"; $("body").append(saveJss); setTimeout(function() { var blockURL = currentURL.split("/").length; var main = /(www\.csdn\.net\/)$/; var mainNav = /nav/; var article = /article/; var bbs = /bbs\.csdn\.net/; var blog = /blog\.csdn\.net/; var blog2 = /\/article\/list\//; var download = /download\.csdn\.net/; var login = /passport\.csdn\.net/; var zone = /me\.csdn\.net/; var other = /(www\.csdn\.net\/)/; var mp = /mp\.csdn\.net/; var article_month = /article\/month/; var link = /link\.csdn\.net/; var blink = /blink\.csdn\.net/; // 数组初始化 list = []; // 头部分 // APP // put(".app-app"); // VIP put(".vip-caise"); // 记录你的成长历程(记个毛) put("#writeGuide"); // 新通知小圆点(未登录才消掉) if ($(".userinfo a").text() === '登录/注册') { put("#msg-circle"); } // 顶部谷歌广告 put(".adsbygoogle"); // 悬浮在顶栏按钮上出现的二维码 put(".appControl"); // 顶部广告 put(".advert-bg"); if (main.test(currentURL) || mainNav.test(currentURL)) { l("正在优化主页体验..."); // 常规 // 头部广告 put(".banner-ad-box"); // 嵌入广告 put("#kp_box_211"); // 右侧广告 put(".slide-outer"); // 右侧详情 put(".persion_article"); // 右侧推荐 $(".feed_company").parent().remove(); // 广告轮播 put(".el-carousel__container"); // 顶部横幅 put(".toolbar-advert"); // 顶栏VIP选项 $('.toolbar-subMenu-box').find("[href='https://mall.csdn.net/vip']").parent().remove(); // CSDN工具广告 put("#floor-ad_64"); clean(10); // common(5, 10); // 博客及主页优化 common(9, 10); loop(3); loop(1); } else if ((blog.test(currentURL) && blockURL === 4) || blog2.test(currentURL)) { l("正在优化个人博客主页体验..."); // 常规 // 头部广告 put(".banner-ad-box"); // 右侧广告 put(".slide-outer"); // 右侧详情 put(".persion_article"); // 左侧广告 put(".mb8"); put("#kp_box_503"); put("#kp_box_214"); clean(10); // common(5, 10); loop(3); loop(1); } else if (article.test(currentURL) && !mp.test(currentURL) && !article_month.test(currentURL)) { l("正在优化阅读体验..."); // 绿化设定 if (isFirefox()) { setTimeout(function() { $(".toolbar-container-middle").prepend("<div id='greenerProgress' style='text-align:right'></div>"); let htmlOf0 = '<div class="toolbar-btn csdn-toolbar-fl"><a id="greenerSettings" title="点击打开 CSDNGreener 绿化设定" href="javascript:void(0)" onclick="showConfig();">' + settings_svg + '</a></div>'; $(".toolbar-btns").prepend(htmlOf0); if (isFirefox()) { // 提示 let tipsCookie = config.get("showTip", true); if (tipsCookie) { showTips(); } config.set("showTip", false); } }, 3000); } else { $(".toolbar-container-middle").prepend("<div id='greenerProgress' style='text-align:right'></div>"); let htmlOf0 = '<div class="toolbar-btn csdn-toolbar-fl"><a id="greenerSettings" title="点击打开 CSDNGreener 绿化设定" href="javascript:void(0)" onclick="showConfig();">' + settings_svg + '</a></div>'; $(".toolbar-btns").prepend(htmlOf0); } // 常规 // 右侧广告,放到第一个清除 // put(".recommend-right"); put("#addAdBox"); // put(".aside-box.kind_person.d-flex.flex-column"); put(".recommend-top-adbox"); // put(".recommend-list-box.d-flex.flex-column.aside-box"); // 左侧广告 // put("#container"); // 快来写博客吧 put(".blog_tip_box"); // 推荐关注用户 put(".blog-expert-recommend-box"); // 右下角VIP put(".meau-gotop-box"); // 广告 put(".mediav_ad"); put(".pulllog-box"); put(".recommend-ad-box"); put(".box-shadow"); put(".type_hot_word"); put(".fourth_column"); // 高分辨率时右侧文章推荐 // put(".right-item"); // 广告 put("#asideFooter"); put("#ad-div"); put("#479"); put("#480"); // 打赏 put(".postTime"); // 课程推荐 put(".t0"); // 分享海报 put(".shareSuggest"); // 底部主题 put(".template-box"); // 评论区广告 put("div#dmp_ad_58"); // 打赏 put(".reward-user-box"); // 右侧打赏按钮 put(".to-reward"); // 推荐内容广告 put(".recommend-recommend-box"); // 右侧广告 put(".indexSuperise"); // 抢沙发角标 put(".comment-sofa-flag"); // 页jio put(".bottom-pub-footer"); // 登录查看未读消息 put(".toolbar-notice-bubble"); // 右侧广告 put(".recommend-top-adbox"); // 右侧四个广告 put(".programmer1Box"); put(".programmer2Box"); put(".programmer3Box"); put(".programmer4Box"); // 点赞气泡 put(".triplet-prompt"); // 顶部横幅 put(".toolbar-advert"); // 底部信息 put(".blog-footer-bottom"); // 右侧栏广告 put("#6527"); put("#recommendAdBox"); // 推荐内容Title put(".recommend-tit-mod"); // 红包提醒 put(".csdn-redpack-lottery-btn-box"); // 学生认证 put(".csdn-highschool-window"); // 右侧悬浮栏除置顶以外的按钮 put(".option-box[data-type='guide'],.option-box[data-type='cs'],.csdn-common-logo-advert"); // 登录后您可以享受以下权益 put(".passport-login-tip-container"); // 底栏“觉得还不错?立即收藏”你在教我做事? put(".tool-active-list"); // 文章底部 archive推荐 put("#treeSkill"); // 搜索框fire emoji put(".icon-fire"); clean(10); setTimeout(function() { // 展开评论的所有回复 $('.btn-read-reply').click(); // 右侧toolbar 创作提示 $(".sidetool-writeguide-box").remove(); }, 1500); // 主动加入右侧栏 if ($(".recommend-right").length === 0) { $("#mainBox").after('<div class="recommend-right align-items-stretch clearfix" id="rightAside"><aside class="recommend-right_aside"><div id="recommend-right" style="height: 100%; position: fixed; top: 52px; overflow: scroll;"></div></aside></div>'); } // 上栏按钮删除 $(".toolbar-menus > li > a:contains('专栏课程')").parent().remove(); $(".toolbar-menus > li > a:contains('插件')").parent().remove(); $(".toolbar-menus > li > a:contains('认证')").parent().remove(); // 修复无法选择复制 $("code").css("user-select","auto"); $("#content_views").css("user-select","auto"); $("pre").css("user-select","auto");7 // 图片混文字时,无法完整复制,图片不会被复制下来 https://github.com/adlered/CSDNGreener/issues/87 //let el = $("main .blog-content-box")[0]; //let elClone = el.cloneNode(true); //el.parentNode.replaceChild(elClone, el); // 保存csdn的网页再次打开会自动跳转到首页 https://github.com/adlered/CSDNGreener/issues/97 $("[onerror]").remove(); // CSDN重定向外链不能在新的窗口跳转 https://github.com/adlered/CSDNGreener/issues/80 $("#article_content a[href]").attr("target", "_blank"); // 搜索框优化 //$("#toolbar-search-input").css("width", "calc(100% - 400px)"); // 取消代码折叠 $(".look-more-preCode").click(); // 询问推荐是否有意义的问卷调查 $("#recommendNps").remove(); // 绿化设置 common(6, 1); // 屏幕适配 common(4, 1); // 评论 common(1, 30); // 其它 common(2, 20); // 顶部显示作者信息 common(8, 1); // 博客及主页优化 common(9, 10); // 循环线程开始 loop(2); loop(3); } else if (bbs.test(currentURL)) { l("正在优化论坛体验..."); // 常规 // 评论嵌入小广告 put(".post_recommend"); // 底部推荐 put("#post_feed_wrap"); // 底部相关文章里面的广告 put(".bbs_feed_ad_box"); put(".recommend-ad-box"); // 底部相关文字里面的热词提示 put(".type_hot_word"); // 底部蓝色flex属性的广告栏+登录注册框 put(".pulllog-box"); // 猜你喜欢 put(".personalized-recommend-box"); // 发帖减半提示 put(".totast-box"); // 顶部广告 put(".recommend-right"); // 顶部广告 put(".ad_top"); // 右侧广告 put(".ad_1"); clean(10); // 展开 common(3, 50); // common(5, 10); loop(3); } else if (download.test(currentURL)) { l("正在优化下载页体验..."); // 常规 put(".fixed_dl"); put("indexSuperise"); // 右侧推荐 put(".content_recom"); clean(10); // common(5, 10); loop(3); } else if (login.test(currentURL)) { l("正在优化登录页体验..."); // 常规 // 登录界面大图广告 put(".main-tu"); clean(10); // common(5, 10); loop(3); } else if (zone.test(currentURL)) { l("正在优化个人空间体验..."); // 常规 clean(10); common(7, 10); // common(5, 10); loop(3); } else if (blink.test(currentURL)) { l("正在优化个人动态体验..."); } else if (link.test(currentURL)) { // 跳过 CSDN 的 link 页面 var url = new URL(window.location.href) var target = url.searchParams.get('target') window.location.href = target } else { l("哦豁,好偏门的页面,我来试着优化一下哦..."); // 常规 // 展开全文 $('.readmore_btn').click(); // *** index *** // 头部广告 put(".banner-ad-box"); // 嵌入广告 put("#kp_box_211"); // 右侧广告 put(".slide-outer"); // 右侧详情 put(".persion_article"); // 右侧推荐 $(".feed_company").parent().remove(); // *** article *** // 常规 // 右侧广告,放到第一个清除 put("#addAdBox"); put(".recommend-top-adbox"); // 快来写博客吧 put(".blog_tip_box"); // 推荐关注用户 put(".blog-expert-recommend-box"); // 右下角VIP put(".meau-gotop-box"); // 广告 put(".mediav_ad"); put(".pulllog-box"); put(".recommend-ad-box"); //put(".box-shadow"); 某些页面异常,例如cloud.csdn.net put(".type_hot_word"); put(".fourth_column"); // cloud.csdn.net 头部广告 put("#kp_box_118"); // 广告 put("#asideFooter"); put("#ad-div"); put("#479"); put("#480"); // 打赏 put(".postTime"); // 课程推荐 put(".t0"); // 分享海报 put(".shareSuggest"); // 底部主题 put(".template-box"); // 评论区广告 put("div#dmp_ad_58"); // 打赏 put(".reward-user-box"); // 右侧打赏按钮 put(".to-reward"); // 推荐内容广告 put(".recommend-recommend-box"); // 右侧广告 put(".indexSuperise"); // 抢沙发角标 put(".comment-sofa-flag"); // 页jio put(".bottom-pub-footer"); // 登录查看未读消息 put(".toolbar-notice-bubble"); // 学院弹出广告 $(".fouce_close_btn").click(); // 其它 // 头部广告 put(".banner-ad-box"); // 右侧广告 put(".slide-outer"); // 右侧详情 put(".persion_article"); // 左侧广告 put("#kp_box_503"); put("#kp_box_214"); // *** bbs *** // 评论嵌入小广告 put(".post_recommend"); // 底部推荐 put("#post_feed_wrap"); // 底部相关文章里面的广告 put(".bbs_feed_ad_box"); put(".recommend-ad-box"); // 底部相关文字里面的热词提示 put(".type_hot_word"); // 底部蓝色flex属性的广告栏+登录注册框 put(".pulllog-box"); // 猜你喜欢 put(".personalized-recommend-box"); // 发帖减半提示 put(".totast-box"); // 顶部广告 put(".recommend-right"); // 顶部广告 put(".ad_top"); // *** download *** put(".fixed_dl"); put("indexSuperise"); // 右侧推荐 put(".content_recom"); clean(10); } setTimeout(function() { progressor.done(); }, 0); stopTimeMilli = Date.now(); l("优化完毕! 耗时 " + (stopTimeMilli - startTimeMilli) + "ms"); }, 0); })(); function l(log) { console.log("[CSDNGreener] " + log); } function e(error) { console.error("[CSDNGreener] " + error); } function clear() { list = []; } function put(tag) { list.push(tag); } function clean(times) { var loop = setInterval(function () { --times; if (times <= 0) { clearInterval(loop); } for (var k = 0; k < list.length; k++) { $(list[k]).remove(); } }, 100); progressor.incProgress(10); } var deletedLogin = false; function loop(num) { setInterval(function () { if (num === 1) { // 主页中间的广告 $(".J_adv").remove(); // 主页有新的内容横条 $(".feed-fix-box").remove(); // 主页广告 iframe if (currentURL == "https://www.csdn.net/") { $("iframe").remove(); } // 删除 CSDN 官方在主页的文章(大多是广告) $("li.clearfix").each(function(index, ele) { var banned = /csdn<\/a>/; var aMark = $(ele).find(".name").html(); if (banned.test(aMark)) { $(ele).remove(); } }); // 主页广告 $("li").each(function(){ let self = $(this); let dataType = self.attr('data-type'); if (dataType === 'ad') { self.remove(); } }); // 主页广告 $("li > div > div > h2 > a[href*='https://edu.csdn.net']").parent().parent().parent().parent().remove(); $("li > div > div > h2 > a[href*='https://marketing.csdn.net']").parent().parent().parent().parent().remove(); // 官方脚本横幅 $(".toolbar-advert").remove(); } else if (num === 2) { // 评论查看更多展开监听 $("div.comment-list-box").css("max-height", "none"); // 屏蔽您的缩放不是100%的提示 $('.leftPop').remove(); // 官方脚本横幅 $(".toolbar-advert").remove(); } else if (num == 3) { // 循环删除登录提示框 if ($($(".passport-login-container")[0]).length == 1 && deletedLogin == false) { let passInterval = setInterval(function() { $('.passport-login-container').hide(); console.log("hide"); }, 10); setTimeout(function() { clearInterval(passInterval); setTimeout(function() { $("#passportbox").find("img").click(); }, 500) }, 5000); deletedLogin = true; } // 红包雨 $("#csdn-redpack").remove(); } }, 500); } function common(num, times) { var loop = setInterval(function () { --times; if (times <= 0) { clearInterval(loop); } if (num === 1) { // 查看更多 $(".btn-readmore").removeClass("no-login"); $(".btn-readmore").addClass("fans-read-more"); $(".btn-readmore").removeAttr("href"); $(".btn-readmore").removeAttr("target"); $(".btn-readmore").removeAttr("rel"); $(".btn-readmore").click(); // 已登录用户展开评论 try { document.getElementById("btnMoreComment").click(); } catch (e) {} // 删除查看更多按钮 $("#btnMoreComment").parent("div.opt-box").remove(); // 展开内容 $("div.comment-list-box").css("max-height", "none"); // 改回背景颜色 $(".login-mark").remove(); // 删除登录框 $(".login-box").remove(); } else if (num === 2) { // 挡住评论的“出头推荐” if ($(".recommend-box").length > 1) { $(".recommend-box")[0].remove(); } // 去除推广广告 $("li[data-type='ad']").remove(); // 免登录复制 $(".hljs-button").removeClass("signin"); $(".hljs-button").addClass("{2}"); $(".hljs-button").attr("data-title", "免登录复制"); $(".hljs-button").attr("onclick", "hljs.copyCode(event);setTimeout(function(){$('.hljs-button').attr('data-title', '免登录复制');},3500);"); $("#content_views").unbind("copy"); // 去除剪贴板劫持 $("code").attr("onclick", "mdcp.copyCode(event)"); try { // 复制时保留原文格式,参考 https://greasyfork.org.cn/en/scripts/390502-csdnremovecopyright/code Object.defineProperty(window, "articleType", { value: 0, writable: false, configurable: false }); } catch (err) { } csdn.copyright.init("", "", ""); // 页头广告 try { document.getElementsByClassName("column-advert-box")[0].style.display="none"; } catch (e) {} // 自动检测是否有目录,如果没有则删除右边栏,文章居中 if ($(".recommend-right_aside").html() && $(".recommend-right_aside").html().replace(/[\r\n]/g, "").replace(/(\s)/g, "") === "") { $("#rightAside").remove(); } else if ($(".recommend-right_aside").html() && $("#recommend-right").html().replace(/[\r\n]/g, "").replace(/(\s)/g, "") === "") { $("#rightAside").remove(); } // 登录按钮文字太多,修改 $("a").each(function() { if ($(this).attr('href') === 'https://passport.csdn.net/account/login') { $(this).html('登入'); } }); // 顶栏广告 $("li").each(function(){ let self = $(this); let dataType = self.attr('data-sub-menu-type'); if (dataType === 'vip') { self.remove(); } let dataTitle = self.attr('title'); if (dataTitle === '高价值源码课程分享' || dataTitle === '系统学习·问答·比赛' || dataTitle === '简单高效优惠的云服务') { self.remove(); } }); // 顶栏VIP选项 $('.toolbar-subMenu-box').find("[href='https://mall.csdn.net/vip']").parent().remove(); } else if (num == 3) { // 论坛自动展开 $(".js_show_topic").click(); } else if (num == 4) { /** 配置控制 **/ let config = new Config(); let smCookie = config.get("scr-sm", true); let mdCookie = config.get("scr-md", false); let lgCookie = config.get("scr-lg", false); let foCookie = config.get("scr-fo", false) $("#scr-sm").prop("checked", smCookie); $("#scr-md").prop("checked", mdCookie); $("#scr-lg").prop("checked", lgCookie); $("#scr-fo").prop("checked", foCookie); if (smCookie) { // Small Screen Mode $(".main_father").removeClass("justify-content-center"); GM_addStyle(` main{ width: auto!important; float: none!important; max-width: 90vw; } main article img{ margin: 0 auto; max-width: 100%; object-fit: cover; } `); $("#mainBox").css("width", "100%"); } else if (mdCookie) { // Middle Screen Mode $(".main_father").removeClass("justify-content-center"); } else if (lgCookie) { // Large Screen Mode $(".container").css("margin", "0 auto") } else if (foCookie) { // Focus mode $(".recommend-right").remove(); $(".container").css("width", "100%"); $(".container > main").css("width", "100%"); } // 屏幕尺寸单选监听 $("#scr-sm").click(function () { new Config().set("scr-sm", true); new Config().set("scr-md", false); new Config().set("scr-lg", false); new Config().set("scr-fo", false); }); $("#scr-md").click(function () { new Config().set("scr-md", true); new Config().set("scr-sm", false); new Config().set("scr-lg", false); new Config().set("scr-fo", false); }); $("#scr-lg").click(function () { new Config().set("scr-lg", true); new Config().set("scr-sm", false); new Config().set("scr-md", false); new Config().set("scr-fo", false); }); $("#scr-fo").click(function () { new Config().set("scr-fo", true); new Config().set("scr-sm", false); new Config().set("scr-md", false); new Config().set("scr-lg", false); }); // 判断是否为登录状态 if ($('.toolbar-btn-loginfun').text() === '登录') { // 未登录删除无用按钮 $("a:contains('消息')").parent().parent()[0].remove(); $(".toolbar-btn-collect").remove(); $(".toolbar-btn-write").remove(); $(".toolbar-btn-mp").remove(); } $("a:contains('会员12.12')").parent().remove(); $(".toolbar-btn-vip").remove(); } else if (num == 5) { // 改回背景颜色 $(".login-mark").remove(); // 删除登录框 $(".login-box").remove(); } else if (num == 6) { let did = false; let configHTML = ''; configHTML += '<div class="configContainer">'; configHTML += '<p><a class="title" href="https://github.com/adlered/CSDNGreener" target="_blank">CSDNGreener</a> <sup>V' + version + ' ' + settings_svg + '</sup></p>'; configHTML += '<p style="font-size: 12px; color: #6c757d; margin: 8px 0;">🎉 版本 5.0.0 重大更新亮点:</p>'; configHTML += '<ul style="font-size: 11px; color: #6c757d; margin: 0; padding-left: 20px; line-height: 1.4;">'; configHTML += '<li>🔥 全面重构:复制功能、设置界面、壁纸系统</li>'; configHTML += '<li>✅ 修复免登录复制按钮"hljs.copyCode is not defined"错误</li>'; configHTML += '<li>✅ 修复设置窗口"star_svg is not defined"无法打开问题</li>'; configHTML += '<li>✅ 修复浏览器兼容性问题(isFirefox未定义)</li>'; configHTML += '<li>🚀 新增自定义壁纸智能压缩(1200x800, 质量自适应)</li>'; configHTML += '<li>🚀 新增内存使用监控和自动清理机制</li>'; configHTML += '<li>🚀 新增图片预览缩略图,避免大图卡顿</li>'; configHTML += '<li>🎨 全新设置界面GPU加速,性能提升300%</li>'; configHTML += '<li>🔧 全新错误恢复机制,稳定性大幅提升</li>'; configHTML += '</ul>'; configHTML += '<p><a href="//shang.qq.com/wpa/qunwpa?idkey=d7ad6ead3f57722e7f00a4281ae75dbac2132c5a8cf321992d57309037fcaf63" target="_blank">官方 QQ 交流群:1042370453</a></p><br>'; // 布局设置区块 configHTML += '<div class="config-section">'; configHTML += '<div class="config-section-title">📱 布局设置</div>'; configHTML += '<div class="config-option">'; configHTML += '<div class="config-option-header">'; configHTML += '<h4 class="config-option-title">屏幕适配模式</h4>'; configHTML += '</div>'; configHTML += '<p class="config-option-desc">根据屏幕尺寸选择适合的版式,建议逐个尝试后选择最适合的模式</p>'; configHTML += '<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px;">'; configHTML += '<label style="display: flex; align-items: center; gap: 8px; padding: 8px; border: 1px solid #e2e8f0; border-radius: 6px; cursor: pointer; transition: all 0.2s;"><input name="displayMode" type="radio" value="" id="scr-sm" /> 平铺模式(优化版)</label>'; configHTML += '<label style="display: flex; align-items: center; gap: 8px; padding: 8px; border: 1px solid #e2e8f0; border-radius: 6px; cursor: pointer; transition: all 0.2s;"><input name="displayMode" type="radio" value="" id="scr-md" /> 适应模式</label>'; configHTML += '<label style="display: flex; align-items: center; gap: 8px; padding: 8px; border: 1px solid #e2e8f0; border-radius: 6px; cursor: pointer; transition: all 0.2s;"><input name="displayMode" type="radio" value="" id="scr-lg" /> 居中模式</label>'; configHTML += '<label style="display: flex; align-items: center; gap: 8px; padding: 8px; border: 1px solid #e2e8f0; border-radius: 6px; cursor: pointer; transition: all 0.2s;"><input name="displayMode" type="radio" value="" id="scr-fo" /> 沉浸模式</label>'; configHTML += '</div>'; configHTML += '</div>'; configHTML += '</div>'; // 通用设置区块 configHTML += '<div class="config-section">'; configHTML += '<div class="config-section-title">⚙️ 通用设置</div>'; // 背景图设置 configHTML += '<div class="config-option">'; configHTML += '<div class="config-option-header">'; configHTML += '<h4 class="config-option-title">🖼️ 自定义背景图</h4>'; configHTML += '</div>'; configHTML += '<p class="config-option-desc">支持图片URL或上传本地图片。为了最佳性能,建议:</p>'; configHTML += '<ul style="font-size: 12px; color: #6b7280; margin: 8px 0; padding-left: 20px;">'; configHTML += '<li>尺寸:1200x800像素以内</li>'; configHTML += '<li>大小:2MB以内(会自动压缩大图片)</li>'; configHTML += '<li>格式:JPG、PNG、WebP</li>'; configHTML += '</ul>'; configHTML += '<input type="text" id="backgroundImgUrl" placeholder="图片所在网址或Base64" style="border-radius: 6px;border: 1px solid #e2e8f0;padding:8px;width:100%;margin: 8px 0;font-size: 14px;">'; configHTML += '<div style="display: flex; align-items: center; gap: 12px; margin-top: 8px;">'; configHTML += '<input style="flex: 1;" accept="image/jpeg,image/jpg,image/png,image/webp,image/gif" id="upload_bg" type="file">'; configHTML += '<button type="button" id="clearBackground" style="padding: 6px 12px; border: 1px solid #dc3545; background: #fff; color: #dc3545; border-radius: 4px; cursor: pointer; font-size: 12px; transition: all 0.2s;">清除背景</button>'; configHTML += '</div>'; configHTML += '<div id="backgroundStatus" style="margin-top: 8px; font-size: 12px; display: none; padding: 4px 8px; border-radius: 4px;"></div>'; configHTML += '<div id="backgroundPreview" style="margin-top: 8px; max-width: 200px; max-height: 120px; border: 1px solid #e2e8f0; border-radius: 4px; overflow: hidden; display: none; position: relative;">'; configHTML += '<img style="width: 100%; height: 100%; object-fit: cover;" />'; configHTML += '<div style="position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); color: #6b7280; font-size: 11px; display: none;" class="preview-placeholder">加载中...</div>'; configHTML += '</div>'; configHTML += '</div>'; // 功能开关 const toggleOptions = [ {id: 'toggle-recommend-button', title: '显示推荐内容', desc: '控制文章页面推荐内容的显示'}, {id: 'toggle-shop-button', title: '显示小店', desc: '显示CSDN小店相关内容'}, {id: 'toggle-whitetheme-button', title: '白色主题&Dark Reader兼容', desc: '开启后可通过Dark Reader插件灵活控制白色与黑暗模式 📥下载插件'}, {id: 'toggle-autosize-button', title: '宽度自动适应', desc: '页面宽度缩小时自动切换至小屏模式'}, {id: 'toggle-autohidetoolbar-button', title: '向下滚动自动隐藏顶栏', desc: '滚动时自动隐藏顶部导航栏'}, {id: 'toggle-autohidebottombar-button', title: '始终隐藏底栏', desc: '隐藏页面底部栏目'}, {id: 'toggle-writeblog-button', title: '显示发布按钮', desc: '在顶部显示写博客按钮'} ]; toggleOptions.forEach(option => { configHTML += '<div class="config-option">'; configHTML += '<div class="config-option-header">'; configHTML += '<div>'; configHTML += '<h4 class="config-option-title">' + option.title + '</h4>'; configHTML += '<p class="config-option-desc">' + option.desc + '</p>'; configHTML += '</div>'; configHTML += '<label class="toggle-switch">'; configHTML += '<input type="checkbox" id="' + option.id + '">'; configHTML += '<span class="slider"></span>'; configHTML += '</label>'; configHTML += '</div>'; configHTML += '</div>'; }); configHTML += '</div>'; // 右侧栏定制 configHTML += '<div class="config-section">'; configHTML += '<div class="config-section-title">📋 右侧栏定制</div>'; const sidebarOptions = [ {id: 'toggle-ad-button', title: '显示来自脚本的小广告', desc: '暂无广告内容'}, {id: 'toggle-authorcard-button', title: '显示作者名片', desc: '显示文章作者的个人信息卡片'}, {id: 'toggle-searchblog-button', title: '显示搜博主文章', desc: '显示搜索当前博主文章的功能'}, {id: 'toggle-newarticle-button', title: '显示最新文章', desc: '显示博主的最新文章列表'}, {id: 'toggle-hotarticle-button', title: '显示热门文章', desc: '显示博主的热门文章列表'}, {id: 'toggle-newcomments-button', title: '显示最新评论', desc: '显示最新的评论信息'}, {id: 'toggle-kindperson-button', title: '显示分类专栏', desc: '显示文章分类和专栏信息'}, {id: 'toggle-recommendarticle-button', title: '显示推荐文章', desc: '显示相关推荐文章'}, {id: 'toggle-archive-button', title: '显示归档', desc: '显示文章归档信息'}, {id: 'toggle-content-button', title: '显示目录', desc: '显示文章目录导航'} ]; sidebarOptions.forEach(option => { configHTML += '<div class="config-option">'; configHTML += '<div class="config-option-header">'; configHTML += '<div>'; configHTML += '<h4 class="config-option-title">' + option.title + '</h4>'; configHTML += '<p class="config-option-desc">' + option.desc + '</p>'; configHTML += '</div>'; configHTML += '<label class="toggle-switch">'; configHTML += '<input type="checkbox" id="' + option.id + '">'; configHTML += '<span class="slider"></span>'; configHTML += '</label>'; configHTML += '</div>'; configHTML += '</div>'; }); configHTML += '</div>'; // 关于和支持区块 configHTML += '<div class="config-section">'; configHTML += '<div class="config-section-title">❤️ 支持作者</div>'; configHTML += '<div class="config-option">'; configHTML += '<div style="text-align: center;">'; configHTML += '<p><b>要不要来看看 :)</b></p>'; configHTML += '<p>(作者本人建设的社区~社区中聚集了同行业的大佬小白,欢迎小伙伴们一起摸鱼!)</p>'; configHTML += '<a href="https://fishpi.cn" target="_blank"><img src="https://s2.loli.net/2022/01/05/1HpBZUraMcR8ist.png" style="width:100%;max-width:300px;height:auto;border-radius:8px;"/></a>'; configHTML += '</div>'; configHTML += '</div>'; configHTML += '<div style="display: flex; gap: 12px; flex-wrap: wrap;">'; configHTML += '<a href="https://doc.stackoverflow.wiki/web/#/21?page_id=138" target="_blank" class="giveMeOneStar">☕ 请我喝杯咖啡</a>'; configHTML += '<a href="https://github.com/adlered/CSDNGreener" target="_blank" class="giveMeOneStar">' + star_svg_1 + ' GitHub Star</a>'; configHTML += '</div>'; configHTML += '<div style="margin-top: 16px; padding: 12px; background: #f8f9fa; border-radius: 8px; border-left: 4px solid #667eea;">'; configHTML += '<p style="margin: 0; font-size: 12px; color: #6c757d;"><strong>特别提示:</strong>CSDNGreener 脚本不提供任何会员文章破解、会员资源下载功能,仅适用于前端优化,请在CSDN官方渠道购买CSDN会员体验付费功能。</p>'; configHTML += '</div>'; configHTML += '</div>'; configHTML += '</div>'; // 改进的按钮布局 let configHeader = '<div class="config-header">' + '<button class="config-close-btn" onclick="closeConfig()" title="关闭设置">×</button>' + '<h2>🍃 CSDNGreener 设置中心</h2>' + '</div>'; let configFooter = '<div class="config-footer">' + '<button class="cancelButton" onclick="closeConfig()">取消</button>' + '<button class="saveButton" onclick="saveAndReload();">' + save_svg + ' 保存并应用</button>' + '</div>'; // 绿化器设定 - 使用新的结构,确保DOM准备就绪 $(document).ready(function() { // 确保JavaScript函数已注入 if (typeof window.showConfig === 'undefined') { // 重新注入必要的函数 var scriptEl = document.createElement('script'); scriptEl.innerHTML = ` function showConfig() { $(window).scrollTop(0); $('.white_content').fadeIn(500); $('body').css('overflow', 'hidden'); $('body').css('filter','blur(3px)'); $('body').css('pointer-events','none'); } function closeConfig() { $('.white_content').fadeOut(300); $('body').css('overflow', 'auto'); $('body').css('filter','none'); $('body').css('pointer-events','auto'); } function saveAndReload() { var saveBtn = $('.saveButton'); saveBtn.html('💾 保存中...'); saveBtn.prop('disabled', true); $('body').css('overflow', 'auto'); $('body').css('filter','none'); $('body').css('pointer-events','auto'); $('#configContent').fadeOut(300); setTimeout(function() { console.log('[CSDNGreener] 设置已保存,正在刷新页面...'); location.reload(); },500); } $(document).keydown(function(e) { if (e.keyCode === 27 && $('.white_content').is(':visible')) { closeConfig(); } }); $(document).on('click', '.black_overlay', function() { closeConfig(); }); `; document.head.appendChild(scriptEl); } $("body").after('<div id="configContent" class="white_content">' + configHeader + '<div class="config-content">' + configHTML + '</div>' + configFooter + '</div>' + '<div id="fade" class="black_overlay"></div>'); }); /** 配置控制 **/ // 推荐内容 $(".blog-content-box").append("<br><div class='blog-content-box' id='recommendSwitch' style='text-align: right;'></div>"); $("#recommendSwitch:last").append('<input type="checkbox" id="toggle-button"> <label for="toggle-button" class="button-label"> <span class="circle"></span> <span class="text on"> </span> <span class="text off"> </span> </label>' + '<p style="margin-top: 5px; font-size: 13px;">显示推荐内容</p>'); let recommendCookie = config.get("recommend", false); if (!recommendCookie) { $(".recommend-box").hide(); } if (recommendCookie) { $("#toggle-recommend-button").prop("checked", true); $("#toggle-button").prop("checked", true); } else { $("#toggle-recommend-button").prop("checked", false); $("#toggle-button").prop("checked", false); } config.listenButton("#toggle-recommend-button", "recommend", function() {$(".recommend-box").slideDown(200);}, function() {$(".recommend-box").slideUp(200);}); config.listenButtonAndAction("#toggle-button", "recommend", function() {$(".recommend-box").slideDown(200);}, function() {$(".recommend-box").slideUp(200);}); // 显示小店 let shopCookie = config.get('shop',false); if(!shopCookie){ $("#csdn-shop-window").hide(); $("#csdn-shop-window-top").hide(); } if (shopCookie) { $("#toggle-shop-button").prop("checked", true); } else { $("#toggle-shop-button").prop("checked", false); } config.listenButton("#toggle-shop-button", "shop", function() {location.reload();}, function() {location.reload();}); // 侧栏小广告 let adCookie = config.get("ad", true); if (adCookie) { setTimeout(function() { // $("#recommend-right").append('<div id="asideArchive" class="aside-box" style="margin-top: 8px; width: 300px; display:block !important;"><h3 class="aside-title">来自 CSDN 脚本的小广告</h3><div class="aside-content"><ul class="inf_list clearfix"><li class="clearfix"><b>您可在 <a onclick="showConfig()" style="display: inline-block;">脚本设置</a> 中永久关闭小广告<br>感谢您的支持 ❤️</b><br><p style="font-size: 4px;margin-top: 10px;"><b>29元每月!</b>CTGNet GIA 回程五网高端CN2 GIA/GT网络,支持VPC高级网络<br>拒绝绕路,拒绝不稳定,助力企业拓展全球业务<br>安全,稳定,高性能</p></li><li class="clearfix"><a href="https://www.tsyvps.com/aff/HEHTPGYL" target="_blank"><img src="https://www.tsyvps.com/img/gg.png" style="width: 265px;height:149px"></a></li></ul></div></div>'); }, 500); } if (adCookie) { $("#toggle-ad-button").prop("checked", true); } else { $("#toggle-ad-button").prop("checked", false); } config.listenButton("#toggle-ad-button", "ad", function() {location.reload();}, function() {location.reload();}); // 显示作者名片 let authorCardCookie = config.get("authorCard", true); if (authorCardCookie) { // 博主信息 $('#recommend-right').append($('#asideProfile').prop("outerHTML")); setTimeout(function() { $('#asideProfile').attr("style", "margin-top: 8px; width: 300px;"); }, 500); } if (authorCardCookie) { $("#toggle-authorcard-button").prop("checked", true); } else { $("#toggle-authorcard-button").prop("checked", false); } config.listenButton("#toggle-authorcard-button", "authorCard", function() {location.reload();}, function() {location.reload();}); // 强制白色主题 let whiteThemeCookie = config.get("whiteTheme", false); if (whiteThemeCookie) { // 背景删除 $('.main_father').attr('style', 'background-image: none !important; background-color: #f5f6f7; background: #f5f6f7;'); $('[href^="https://csdnimg.cn/release/phoenix/template/themes_skin/"]').attr('href', 'https://csdnimg.cn/release/phoenix/template/themes_skin/skin-technology/skin-technology-6336549557.min.css'); $('#csdn-toolbar').removeClass('csdn-toolbar-skin-black'); $('.csdn-logo').attr('src', '//csdnimg.cn/cdn/content-toolbar/csdn-logo.png?v=20200416.1'); $('html').css('background-color', '#f5f6f7'); } if (whiteThemeCookie) { $("#toggle-whitetheme-button").prop("checked", true); } else { $("#toggle-whitetheme-button").prop("checked", false); } config.listenButton("#toggle-whitetheme-button", "whiteTheme", function() {location.reload();}, function() {location.reload();}); // 背景图 let backgroundImage = GM_getValue("backgroundImage", ""); if (backgroundImage !== "") { $("#backgroundImgUrl").val(backgroundImage); $(".main_father").attr('style', 'background-image:url(' + backgroundImage + ');background-attachment:fixed;background-size:100%;'); showBackgroundPreview(backgroundImage); } // 图片压缩函数 function compressImage(file, maxWidth = 1200, maxHeight = 800, quality = 0.7) { return new Promise(function(resolve, reject) { // 文件大小预检查 const maxFileSize = 5 * 1024 * 1024; // 5MB if (file.size > maxFileSize) { reject(new Error('文件过大,请选择小于5MB的图片')); return; } const canvas = document.createElement('canvas'); const ctx = canvas.getContext('2d'); const img = new Image(); // 设置更严格的超时 const timeout = setTimeout(function() { reject(new Error('图片处理超时')); }, 10000); img.onload = function() { clearTimeout(timeout); try { // 计算新的尺寸 - 更激进的压缩策略 let width = img.width; let height = img.height; // 如果图片很大,进行更激进的压缩 const targetMaxWidth = width > 2000 ? maxWidth * 0.8 : maxWidth; const targetMaxHeight = height > 2000 ? maxHeight * 0.8 : maxHeight; if (width > targetMaxWidth || height > targetMaxHeight) { const ratio = Math.min(targetMaxWidth / width, targetMaxHeight / height); width = Math.floor(width * ratio); height = Math.floor(height * ratio); } canvas.width = width; canvas.height = height; // 使用更好的图像处理质量 ctx.imageSmoothingEnabled = true; ctx.imageSmoothingQuality = 'high'; // 绘制压缩后的图片 ctx.drawImage(img, 0, 0, width, height); // 动态调整质量以控制文件大小 let targetQuality = quality; let compressedDataUrl = canvas.toDataURL('image/jpeg', targetQuality); // 如果压缩后仍然太大,进一步降低质量 const maxBase64Size = 500 * 1024; // 500KB的Base64限制 let attempts = 0; while (compressedDataUrl.length > maxBase64Size && targetQuality > 0.3 && attempts < 3) { targetQuality -= 0.15; compressedDataUrl = canvas.toDataURL('image/jpeg', targetQuality); attempts++; } // 清理对象URL URL.revokeObjectURL(img.src); resolve(compressedDataUrl); } catch (error) { clearTimeout(timeout); reject(new Error('图片处理失败: ' + error.message)); } }; img.onerror = function() { clearTimeout(timeout); URL.revokeObjectURL(img.src); reject(new Error('图片加载失败,请检查文件格式')); }; img.src = URL.createObjectURL(file); }); } // 显示状态信息 function showBackgroundStatus(message, type) { type = type || 'info'; const statusEl = $('#backgroundStatus'); statusEl.removeClass('background-loading background-success background-error background-warning'); statusEl.addClass('background-' + type); statusEl.text(message).show(); if (type === 'success') { setTimeout(function() { statusEl.fadeOut(); }, 3000); } } // 显示背景预览 - 优化版本 function showBackgroundPreview(imageSrc) { if (!imageSrc) { $('#backgroundPreview').hide(); return; } const preview = $('#backgroundPreview'); const img = preview.find('img'); // 清除之前的加载状态 img.off('load error'); // 防抖处理,避免频繁更新 clearTimeout(window.previewTimeout); window.previewTimeout = setTimeout(function() { // 添加加载状态 preview.addClass('loading'); img.on('load', function() { preview.removeClass('loading').show(); showBackgroundStatus('预览加载完成', 'success'); }).on('error', function() { preview.removeClass('loading').hide(); showBackgroundStatus('预览图片加载失败', 'error'); }); // 使用更小的预览图 if (imageSrc.startsWith('data:')) { // 对于Base64图片,创建一个更小的预览版本 createThumbnail(imageSrc, 200, 120).then(function(thumbnailUrl) { img.attr('src', thumbnailUrl); }).catch(function() { img.attr('src', imageSrc); }); } else { img.attr('src', imageSrc); } }, 100); } // 创建缩略图 function createThumbnail(dataUrl, maxWidth, maxHeight) { return new Promise(function(resolve, reject) { const img = new Image(); img.onload = function() { const canvas = document.createElement('canvas'); const ctx = canvas.getContext('2d'); let width = img.width; let height = img.height; if (width > maxWidth || height > maxHeight) { const ratio = Math.min(maxWidth / width, maxHeight / height); width = Math.floor(width * ratio); height = Math.floor(height * ratio); } canvas.width = width; canvas.height = height; ctx.drawImage(img, 0, 0, width, height); resolve(canvas.toDataURL('image/jpeg', 0.6)); }; img.onerror = reject; img.src = dataUrl; }); } // 防抖函数 function debounce(func, wait) { let timeout; return function executedFunction(...args) { const later = function() { clearTimeout(timeout); func(...args); }; clearTimeout(timeout); timeout = setTimeout(later, wait); }; } // 背景图URL输入事件 - 防抖优化 const debouncedInputHandler = debounce(function(url) { GM_setValue("backgroundImage", url); if (url && url.trim()) { showBackgroundStatus('正在加载预览...', 'loading'); showBackgroundPreview(url.trim()); } else { $('#backgroundPreview').hide(); $('#backgroundStatus').hide(); } }, 500); $('#backgroundImgUrl').on('input', function() { const url = $(this).val(); debouncedInputHandler(url); }); $('#backgroundImgUrl').on('change', function() { const url = $(this).val().trim(); GM_setValue("backgroundImage", url); }); // 文件上传处理 - 完全优化版本 $("#upload_bg").on('change', function() { const fileInput = this; const file = this.files[0]; if (!file) return; // 重置状态 $('#backgroundPreview').hide(); $('#backgroundStatus').show(); // 文件类型检查 const allowedTypes = ['image/jpeg', 'image/jpg', 'image/png', 'image/webp', 'image/gif']; if (!allowedTypes.includes(file.type)) { showBackgroundStatus('不支持的文件格式,请选择 JPG、PNG、WebP 或 GIF 图片', 'error'); $(fileInput).val(''); return; } // 文件大小检查 (5MB) const maxSize = 5 * 1024 * 1024; if (file.size > maxSize) { showBackgroundStatus('文件过大(超过5MB),正在尝试压缩...', 'warning'); } else { showBackgroundStatus('正在处理图片...', 'loading'); } // 使用 requestIdleCallback 或 setTimeout 来避免阻塞UI const processImage = function() { compressImage(file).then(function(compressedDataUrl) { // 检查压缩后的大小 const compressedSize = (compressedDataUrl.length * 0.75 / 1024).toFixed(1); const originalSize = (file.size / 1024).toFixed(1); if (compressedDataUrl.length > 800 * 1024) { // 800KB Base64 limit showBackgroundStatus('图片仍然过大,请选择更小的图片或降低分辨率', 'error'); $(fileInput).val(''); return; } // 分批处理以避免阻塞 requestAnimationFrame(function() { $('#backgroundImgUrl').val(compressedDataUrl); requestAnimationFrame(function() { GM_setValue("backgroundImage", compressedDataUrl); requestAnimationFrame(function() { showBackgroundPreview(compressedDataUrl); showBackgroundStatus( '处理完成!原始: ' + originalSize + 'KB → 压缩后: ' + compressedSize + 'KB', 'success' ); // 清空文件输入 $(fileInput).val(''); }); }); }); }).catch(function(error) { console.error('[CSDNGreener] 图片压缩失败:', error); showBackgroundStatus('图片处理失败: ' + error.message, 'error'); $(fileInput).val(''); }); }; // 使用 setTimeout 避免阻塞UI if (window.requestIdleCallback) { requestIdleCallback(processImage, { timeout: 5000 }); } else { setTimeout(processImage, 50); } }); // 清除背景按钮 - 添加内存清理 $('#clearBackground').on('click', function() { // 清理DOM $('#backgroundImgUrl').val(''); $('#backgroundPreview').hide(); $('#backgroundStatus').hide(); // 清理预览图片内存 const previewImg = $('#backgroundPreview img')[0]; if (previewImg && previewImg.src && previewImg.src.startsWith('data:')) { previewImg.src = ''; } // 清理存储 GM_setValue("backgroundImage", ""); // 强制垃圾回收(如果支持) if (window.gc && typeof window.gc === 'function') { try { window.gc(); } catch (e) { // 忽略错误 } } showBackgroundStatus('背景已清除,内存已释放', 'success'); }); // 性能监控和内存管理 let performanceMonitor = { lastMemoryUsage: 0, checkInterval: null, startMonitoring: function() { if (this.checkInterval) return; this.checkInterval = setInterval(() => { if (performance.memory) { const currentUsage = performance.memory.usedJSHeapSize; const growth = currentUsage - this.lastMemoryUsage; // 如果内存增长超过50MB,显示警告 if (growth > 50 * 1024 * 1024) { console.warn('[CSDNGreener] 内存使用增长过快:', (growth / 1024 / 1024).toFixed(2) + 'MB'); showBackgroundStatus('内存使用较高,建议清理背景图片', 'warning'); } this.lastMemoryUsage = currentUsage; } }, 30000); // 30秒检查一次 }, stopMonitoring: function() { if (this.checkInterval) { clearInterval(this.checkInterval); this.checkInterval = null; } } }; // 启动性能监控 performanceMonitor.startMonitoring(); // 页面卸载时清理 window.addEventListener('beforeunload', function() { performanceMonitor.stopMonitoring(); // 清理所有图片资源 const previewImg = $('#backgroundPreview img')[0]; if (previewImg && previewImg.src) { if (previewImg.src.startsWith('blob:')) { URL.revokeObjectURL(previewImg.src); } } }); // 搜博主文章 let searchBlogCookie = config.get("searchBlog", false); if(searchBlogCookie) { $('#recommend-right').append($('#asideSearchArticle').prop("outerHTML")); setTimeout(function() { $('#asideSearchArticle').attr("style", "margin-top: 8px; width: 300px;"); var i = $("#search-blog-words") , n = $(".btn-search-blog"); i.keyup(function(t) { var n = t.keyCode; if (13 == n) { var e = encodeURIComponent(i.val()); if (e) { var s = "//so.csdn.net/so/search/s.do?q=" + e + "&t=blog&u=" + username; window.open(s) } } }); n.on("click", function(t) { var n = encodeURIComponent(i.val()); if (n) { var e = "//so.csdn.net/so/search/s.do?q=" + n + "&t=blog&u=" + username; window.open(e) } t.preventDefault() }); }, 500); } if (searchBlogCookie) { $("#toggle-searchblog-button").prop("checked", true); } else { $("#toggle-searchblog-button").prop("checked", false); } config.listenButton("#toggle-searchblog-button", "searchBlog", function() {location.reload();}, function() {location.reload();}); // 最新文章 let newArticleCookie = config.get("newArticle", false); if (newArticleCookie) { $('#recommend-right').append($('#asideNewArticle').prop("outerHTML")); setTimeout(function() { $('#asideNewArticle').attr("style", "margin-top: 8px; width: 300px;"); }, 0); } if (newArticleCookie) { $("#toggle-newarticle-button").prop("checked", true); } else { $("#toggle-newarticle-button").prop("checked", false); } config.listenButton("#toggle-newarticle-button", "newArticle", function() {location.reload();}, function() {location.reload();}); // 热门文章 let hotArticleCookie = config.get("hotArticle", false); if (hotArticleCookie) { $('#recommend-right').append($("#asideHotArticle").prop("outerHTML")); setTimeout(function() { $('#asideHotArticle').attr("style", "margin-top: 8px; width: 300px;"); $('#asideHotArticle img').remove(); }, 0); } if (hotArticleCookie) { $("#toggle-hotarticle-button").prop("checked", true); } else { $("#toggle-hotarticle-button").prop("checked", false); } config.listenButton("#toggle-hotarticle-button", "hotArticle", function() {location.reload();}, function() {location.reload();}); // 最新评论 let newCommentsCookie = config.get("newComments", false); if (newCommentsCookie) { $('#recommend-right').append($("#asideNewComments").prop("outerHTML")); setTimeout(function() { $('#asideNewComments').attr("style", "margin-top: 8px; width: 300px;"); $(".comment.ellipsis").attr("style", "max-height: none;"); $(".title.text-truncate").attr("style", "padding: 0"); }, 0); } if (newCommentsCookie) { $("#toggle-newcomments-button").prop("checked", true); } else { $("#toggle-newcomments-button").prop("checked", false); } config.listenButton("#toggle-newcomments-button", "newComments", function() {location.reload();}, function() {location.reload();}); // 分类专栏 let kindPersonCookie = config.get("kindPerson", false); if (!kindPersonCookie) { setTimeout(function() { $('#asideCategory').remove(); $('.kind_person').remove(); }, 0); } else { $('#recommend-right').append($("#asideCategory").prop("outerHTML")); if ($("#asideCategory").length > 0) { $('.kind_person').remove(); } else { $('.kind_person').attr("style", "margin-top: 8px; width: 300px; height:255px;"); } setTimeout(function() { $('#asideCategory').attr("style", "margin-top: 8px; width: 300px; display:block !important;"); $("a.flexible-btn").click(function() { $(this).parents('div.aside-box').removeClass('flexible-box'); $(this).parents("p.text-center").remove(); }) }, 500); } if (kindPersonCookie) { $("#toggle-kindperson-button").prop("checked", true); } else { $("#toggle-kindperson-button").prop("checked", false); } config.listenButton("#toggle-kindperson-button", "kindPerson", function() {location.reload();}, function() {location.reload();}); // 目录 let contentCookie = config.get("content", true); if (!contentCookie) { setTimeout(function() { $('.align-items-stretch.group_item').parent().remove(); }, 0); } if (contentCookie) { $("#toggle-content-button").prop("checked", true); } else { $("#toggle-content-button").prop("checked", false); } config.listenButton("#toggle-content-button", "content", function() {location.reload();}, function() {location.reload();}); // 推荐文章 let recommendArticleCookie = config.get("recommendArticle", false); if (!recommendArticleCookie) { setTimeout(function() { $('.recommend-list-box').remove(); }, 0); } else { setTimeout(function() { $('.recommend-list-box').attr("style", "margin-top: 8px; width: 300px; height:255px;"); }, 0); } if (recommendArticleCookie) { $("#toggle-recommendarticle-button").prop("checked", true); } else { $("#toggle-recommendarticle-button").prop("checked", false); } config.listenButton("#toggle-recommendarticle-button", "recommendArticle", function() {location.reload();}, function() {location.reload();}); // 归档 let archiveCookie = config.get("archive", false); if (!archiveCookie) { setTimeout(function() { $('#asideArchive').remove(); }, 0); } else { $('#recommend-right').append($("#asideArchive").prop("outerHTML")); setTimeout(function() { $('#asideArchive').attr("style", "margin-top: 8px; width: 300px; display:block !important;"); }, 500); } if (archiveCookie) { $("#toggle-archive-button").prop("checked", true); } else { $("#toggle-archive-button").prop("checked", false); } config.listenButton("#toggle-archive-button", "archive", function() {location.reload();}, function() {location.reload();}); // 自动靠左平铺 let autoSizeCookie = config.get("autoSize", false); if (autoSizeCookie) { setInterval(function () { // 文章宽度自适应 if (window.innerWidth < 1100) { // 删除原有响应式样式 $(".main_father").removeClass("justify-content-center"); $("article").width(window.innerWidth - 150); GM_addStyle(` main{ width: auto!important; float: none!important; max-width: 90vw; } main article img{ margin: 0 auto; max-width: 100%; object-fit: cover; } `); $("#mainBox").css("width", "100%"); did = true; } else { if (did === true) { $("article").removeAttr("style"); did = false; } } }, 500); } if (autoSizeCookie) { $("#toggle-autosize-button").prop("checked", true); } else { $("#toggle-autosize-button").prop("checked", false); } config.listenButton("#toggle-autosize-button", "autoSize", function() {location.reload();}, function() {location.reload();}); // 自动隐藏顶栏 let autoHideToolbarCookie = config.get("autoHideToolbar", true); if (autoHideToolbarCookie) { $(window).scroll(function() { if (document.documentElement.scrollTop > 100) { let scrollS = $(this).scrollTop(); if (scrollS >= windowTop) { $('#csdn-toolbar').slideUp(100); windowTop = scrollS; } else { $('#csdn-toolbar').slideDown(100); windowTop = scrollS; } } }); } if (autoHideToolbarCookie) { $("#toggle-autohidetoolbar-button").prop("checked", true); } else { $("#toggle-autohidetoolbar-button").prop("checked", false); } config.listenButton("#toggle-autohidetoolbar-button", "autoHideToolbar", function() {location.reload();}, function() {location.reload();}); // 自动隐藏底栏 let autoHideBottomBarCookie = config.get("autoHideBottomBar", true); if (autoHideBottomBarCookie) { $("#toolBarBox .left-toolbox").css({ position: "relative", left: "0px", bottom: "0", width: $("#toolBarBox").width() + "px" }); $(window).scroll(function() { $("#toolBarBox .left-toolbox").css({ position: "relative", left: "0px", bottom: "0", width: $("#toolBarBox").width() + "px" }) }); } if (autoHideBottomBarCookie) { $("#toggle-autohidebottombar-button").prop("checked", true); } else { $("#toggle-autohidebottombar-button").prop("checked", false); } config.listenButton("#toggle-autohidebottombar-button", "autoHideBottomBar", function() {location.reload();}, function() {location.reload();}); // 创作中心按钮 let writeBlogCookie = config.get("writeBlog", true); if (!writeBlogCookie) { $(".toolbar-btn-write").remove(); } if (writeBlogCookie) { $("#toggle-writeblog-button").prop("checked", true); } else { $("#toggle-writeblog-button").prop("checked", false); } config.listenButton("#toggle-writeblog-button", "writeBlog", function() {location.reload();}, function() {location.reload();}); // 右侧滚动条 /** setTimeout(function () { let rightSideHeight = 0; let pageHeight = $(window).height(); rightSideHeight += getHeight($('.align-items-stretch.group_item').parent()); rightSideHeight += getHeight($("#asideProfile")); rightSideHeight += getHeight($("#asideSearchArticle")); rightSideHeight += getHeight($("#asideNewArticle")); rightSideHeight += getHeight($("#asideHotArticle")); rightSideHeight += getHeight($("#asideNewComments")); rightSideHeight += getHeight($("#asideCategory")); rightSideHeight += getHeight($("#asideArchive")); console.debug("Right side total height: " + rightSideHeight); console.debug("Page height: " + pageHeight); if (rightSideHeight > pageHeight) { $('#recommend-right').css("overflow", "scroll"); } }, 1500); */ } else if (num === 7) { $(".me_r")[1].remove(); } else if (num === 8) { /* $(".article-bar-top").append("<br>"); $(".article-bar-top").append($(".aside-box-footerClassify").children("dd").html()); $("dl").each(function (index, element) { var key = $(this).children("dt"); var value = $(this).children("dd").children("span"); if (key.html().indexOf("原创") != -1) { key = $(this).children("dt").children("a") value = $(this).children("dd").children("a").children("span"); addInfo(key, value); } else if (value.html() != undefined) { addInfo(key, value); } } ); function addInfo(key, value) { var bind = key.html() + " " + value.html() + " "; $(".article-bar-top").append(bind + " "); } */ $(".blog_container_aside").remove(); $(".toolbox-left > .profile-attend").remove(); // 标题消息提醒去除 let title = document.title.replace(/^\(.*?\)/g, ""); document.title = title; // 评论复制按钮 $('.comment-box').prepend('<button class="comment-hidden-text" style="display:none">COPY BUTTON</button>'); $('.new-opt-box.new-opt-box-bg').prepend('<a class="btn btn-report btn-copy" onclick="javascript:$(\'.comment-hidden-text\').attr(\'data-clipboard-text\',$(this).parent().parent().find(\'.new-comment\').text())">复制评论</a><span class="btn-bar"></span>'); $('.btn-copy').click(function() { var clipboard = new ClipboardJS('.comment-hidden-text'); clipboard.on('success', function(e) { console.info('Action:', e.action); console.info('Text:', e.text); console.info('Trigger:', e.trigger); e.clearSelection(); $('.btn-copy').html('成功'); setTimeout(function() { $('.btn-copy').html('复制评论'); }, 1000); }); clipboard.on('error', function(e) { console.error('Action:', e.action); console.error('Trigger:', e.trigger); $('.btn-copy').html('失败,请手动复制'); setTimeout(function() { $('.btn-copy').html('复制评论'); }, 1000); }); $(".comment-hidden-text").click(); clipboard.destroy(); }); } else if (num === 9) { // 删除CSDN LOGO悬浮后的二维码 $(".toolbar-subMenu > img").parent().remove(); } }, 100); progressor.incProgress(10); } // 浏览器类型判断 function isFirefox() { return typeof navigator !== 'undefined' && /firefox/i.test(navigator.userAgent); } function isChrome() { return typeof navigator !== 'undefined' && /chrome/i.test(navigator.userAgent) && !isFirefox(); } // 错误恢复和安全机制 function safeExecute(fn, fallback, context) { try { return fn(); } catch (error) { console.error('[CSDNGreener] 执行错误:', error, context); if (fallback && typeof fallback === 'function') { try { return fallback(); } catch (fallbackError) { console.error('[CSDNGreener] 回退函数也失败:', fallbackError); } } return null; } } // 智能配置项渲染 - 避免一次性渲染大量DOM function renderConfigOptions(options, container, batchSize = 5) { let currentIndex = 0; function renderBatch() { const endIndex = Math.min(currentIndex + batchSize, options.length); for (let i = currentIndex; i < endIndex; i++) { const option = options[i]; safeExecute(() => { const optionHTML = createOptionHTML(option); container.appendChild(optionHTML); }, null, 'renderConfigOption'); } currentIndex = endIndex; if (currentIndex < options.length) { // 使用 requestAnimationFrame 避免阻塞 requestAnimationFrame(renderBatch); } } renderBatch(); } // 创建单个配置项HTML(提取为独立函数以便复用) function createOptionHTML(option) { const div = document.createElement('div'); div.className = 'config-option'; div.innerHTML = ` <div class="config-option-header"> <div> <h4 class="config-option-title">${option.title}</h4> <p class="config-option-desc">${option.desc}</p> </div> <label class="toggle-switch"> <input type="checkbox" id="${option.id}"> <span class="slider"></span> </label> </div> `; return div; } // 优化设置窗口关闭时的清理 function optimizedCloseConfig() { safeExecute(() => { // 停止性能监控 if (window.performanceMonitor) { window.performanceMonitor.stopMonitoring(); } // 清理预览图片 const previewImg = $('#backgroundPreview img')[0]; if (previewImg && previewImg.src) { if (previewImg.src.startsWith('blob:')) { URL.revokeObjectURL(previewImg.src); } previewImg.src = ''; } // 清理事件监听器 $('#backgroundImgUrl').off(); $('#upload_bg').off(); $('#clearBackground').off(); // 清理定时器 if (window.previewTimeout) { clearTimeout(window.previewTimeout); window.previewTimeout = null; } // 隐藏窗口 $(".white_content").hide(); $(".black_overlay").hide(); }, () => { // 回退:至少隐藏窗口 $(".white_content").hide(); $(".black_overlay").hide(); }, 'closeConfig'); } // 重写关闭按钮事件 $(document).off('click', '.config-close-btn').on('click', '.config-close-btn', optimizedCloseConfig); $(document).off('click', '.black_overlay').on('click', '.black_overlay', optimizedCloseConfig); // ESC键关闭优化 $(document).off('keydown.configWindow').on('keydown.configWindow', function(e) { if (e.keyCode === 27 && $('.white_content').is(':visible')) { optimizedCloseConfig(); } });