// ==UserScript== // @name Wenshu Print Fix v3@极客律师 // @namespace geeklaw.wenshu.print // @version 0.5 // @description 最高法文书网打印优化:只打印正文,去掉上面的巨大空白和目录/概要,并提供导出 PDF 按钮 // @match https://wenshu.court.gov.cn/website/wenshu/*/index.html* // @run-at document-end // @grant none // ==/UserScript== (function () { 'use strict'; // 打印样式 function injectPrintStyle() { if (document.getElementById('wenshu-print-fix-style')) return; const style = document.createElement('style'); style.id = 'wenshu-print-fix-style'; style.textContent = ` @media print { /* 把页面当成一张白纸 */ html, body { margin: 0; padding: 0; background: #ffffff !important; } /* 只保留 .main */ body > *:not(.main) { display: none !important; } .main { margin: 0 !important; padding: 0 !important; background: #ffffff !important; } .main > * { display: none !important; } .main > .detailBg { display: block !important; margin: 0 auto !important; padding-top: 0 !important; } /* 只保留第二个 item_table(正文) */ .detailBg .detailBox > .item_table { display: none !important; } .detailBg .detailBox > .item_table:nth-of-type(2) { display: block !important; } /* 去掉目录按钮等装饰 */ .detailBg .del_left, .detailBg .mulu_box, .detailBg .mulu_top, .detailBg .mulu_center { display: none !important; } /* 去掉两侧黄边 */ .detailBg, .detailBg .detailBox, .detailBg .detailBox > .item_table, .detailBg .detailBox > .item_table:nth-of-type(2) { background: #ffffff !important; box-shadow: none !important; border: none !important; } /* 关键:正文容器不要固定宽度,改成自适应居中 */ .detailBg .detailBox .del_center { width: auto !important; max-width: 190mm !important; /* 小于 A4 的可打印宽度 */ margin: 0 auto !important; overflow: visible !important; } /* 防止内部再写死宽度 */ .detailBg .detailBox .del_center .PDF_box { width: auto !important; } } `; document.head.appendChild(style); } // 右下角「导出 PDF」按钮 function createExportButton() { if (document.getElementById('wenshu-export-pdf-btn')) return; const detail = document.querySelector('.detailBg'); if (!detail) return; // 不是文书全文页就不加 const btn = document.createElement('button'); btn.id = 'wenshu-export-pdf-btn'; btn.textContent = '导出 PDF'; btn.style.position = 'fixed'; btn.style.right = '16px'; btn.style.bottom = '16px'; btn.style.zIndex = '99999'; btn.style.padding = '6px 12px'; btn.style.borderRadius = '4px'; btn.style.border = '1px solid #888'; btn.style.background = '#ffffff'; btn.style.cursor = 'pointer'; btn.style.fontSize = '12px'; btn.style.boxShadow = '0 1px 4px rgba(0,0,0,.15)'; btn.addEventListener('click', () => { // 调用浏览器打印,目标选“另存为 PDF” window.print(); }); document.body.appendChild(btn); } function init() { injectPrintStyle(); createExportButton(); } if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', init); } else { init(); } })();