当前位置: 首页 > news >正文

CSDN 去水印打印神器 | 一键展开代码 + 清除水印 + 自动打印,完美保存技术文章!

使用方法:

  1. 打开要保存的技术文章页面

  2. 在浏览器控制台(F12)中粘贴此代码执行

  3. 浏览器打印对话框会自动弹出

  4. 页面会在打印后自动恢复

(function() { 'use strict'; const originalHTML = document.body.innerHTML; const originalStyle = document.body.style.cssText; try { // 1. 先展开所有折叠的代码块 document.querySelectorAll('.expand-btn, .fold-btn, .code-expand, .toggle-btn').forEach(btn => { btn.click(); }); // 兼容CSDN的代码块展开 document.querySelectorAll('.hljs-button').forEach(btn => { if (btn.textContent.includes('展开')) btn.click(); }); // 2. 去水印(修复版) let removedCount = 0; document.querySelectorAll('*').forEach(el => { const className = el.className || ''; const id = el.id || ''; if ( (typeof className === 'string' && className.includes('watermark')) || (typeof id === 'string' && id.includes('watermark')) || el.style.pointerEvents === 'none' || (el.style.position === 'fixed' && parseInt(el.style.zIndex || 0) > 999) ) { el.remove(); removedCount++; } const computedStyle = getComputedStyle(el); if (computedStyle && typeof computedStyle.backgroundImage === 'string' && computedStyle.backgroundImage.includes('watermark')) { el.style.backgroundImage = 'none'; removedCount++; } }); // 3. 优化打印样式,让代码块完整显示 const printStyle = document.createElement('style'); printStyle.textContent = ` @media print { body { zoom: 0.8; } pre, code { white-space: pre-wrap !important; word-wrap: break-word !important; } .article_content { width: 100% !important; } header, footer, .sidebar, .comment, .advertisement { display: none !important; } } `; document.head.appendChild(printStyle); // 4. 弹出打印窗口 window.print(); // 5. 清理临时样式 document.head.removeChild(printStyle); } finally { // 恢复页面 document.body.innerHTML = originalHTML; document.body.style.cssText = originalStyle; } })();
http://www.cnnetsun.cn/news/1537919.html

相关文章:

  • QML 文本控件实战:Text、TextInput、TextEdit 的样式定制与交互优化
  • TradingAgents-CN终极教程:10分钟搭建你的AI股票投资分析系统
  • 深入解析C语言中的Stream(流)操作与文件处理实践
  • 手把手教你处理Android 11+的‘特殊权限’:从MANAGE_EXTERNAL_STORAGE申请到结果监听全流程
  • 李慕婉-仙逆-造相Z-Turbo与Unity引擎:实时3D场景概念图生成插件开发
  • AI专著写作权威指南:优质工具推荐,让你的学术之路更平坦
  • 【CP AUTOSAR】Wdg驱动与GPT定时器协同:实现精准看门狗管理的实战解析
  • 数字图像处理(十)腐蚀和膨胀:从原理到实战应用
  • Linux性能调优实战:5个perf命令的高效用法(附火焰图生成指南)
  • 保姆级教程:在Ubuntu 22.04上,用Xinference为你的RAGFLOW项目接入BGE重排序模型
  • 告别“手搓论文”焦虑:百考通AI期刊写作全流程通关秘籍
  • Qwen3.5-4B模型Qt桌面应用开发:集成AI对话功能
  • 3分钟终极解决方案:快速解除Cursor试用限制的完整指南
  • 200K上下文实测|【书生·浦语】internlm2-chat-1.8b长文本理解效果震撼展示
  • 为什么StyTr²能超越CNN?深入解析CAPE位置编码在风格迁移中的黑科技
  • 深入解析C#中SugarColumn在ORM映射中的高效应用
  • Qwen Pixel Art惊艳效果展示:16色限制下的精准色彩映射与抖动算法效果
  • 异常检测实战:局部异常因子(LOF)在金融风控中的应用
  • Phi-3-mini-128k-instruct在算法学习中的应用:动态规划与贪心算法例题讲解
  • 别再只会用Ettercap了!手把手教你用Python+Scapy从零写一个ARP欺骗脚本(附完整代码)
  • JavaScript基础课程三十、微信小程序实战
  • springboot-vue+nodejs的药膳食谱管理系统
  • FreeSWITCH外线对接避坑指南:IAD网关配置中5个必改的安全参数
  • 别再手动建模了!用C++和Gmsh自动导入STEP文件并生成六面体网格(附完整代码)
  • 3分钟免费获取股票数据:Python通达信接口终极指南
  • 【01】总目录——软件设计师50讲通关地图|从零基础到工程师职称
  • Qwen3-ASR-1.7B实战教程:curl命令行调用API实现无人值守识别任务
  • CI实战:一键配置npm仓库认证的authToken秘笈
  • MPC控制进阶:手把手教你用TCM网络提升预测精度(基于PyTorch实现)
  • 移动端也能跑!实测PaddleOCR PP-OCRv4_mobile_seal_det模型,在安卓上部署印章检测App