您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
/////部分问题解决方法在安装脚本页面下方,请仔细阅读/////基于《百度文库(wenku)在线下载PDF格式文件》修改部分代码,修复了打印页面空白问题。可将大部分文档打印成pdf/脚本仅供学习交流,请勿用于商业用途。
当前为
// ==UserScript== // @name 百度文库(wenku)| 免费下载BX修复版 // @version 1.20 // @description /////部分问题解决方法在安装脚本页面下方,请仔细阅读/////基于《百度文库(wenku)在线下载PDF格式文件》修改部分代码,修复了打印页面空白问题。可将大部分文档打印成pdf/脚本仅供学习交流,请勿用于商业用途。 // @author ChaorenLong // @namespace https://gitee.com/Bgz666/bdwenku-download-tampermonkey-script // @require https://cdn.bootcss.com/jquery/2.2.4/jquery.js // @match *://wenku.baidu.com/view/* // @match *://wenku.baidu.com/share/* // @grant unsafeWindow // @license GPL-2.0 // @icon https://www.baidu.com/cache/icon/favicon.ico // ==/UserScript== //感谢原作者 eko.zhan, HelloCodeMing 的脚本支持;脚本仅供学习交流使用,请勿用于商业用途。 ; (function () { 'use strict' window.onload = function(){ if(document.getElementsByClassName("goBtn")[0]){ const moreBtn = document.getElementsByClassName("goBtn")[0]; if(moreBtn){ moreBtn.click(); } } insert(); }; //insert print btn function insert() { if ($('#btnPrintStyle').length == 0) { $('head').append( [ '<style id="btnPrintStyle">', '.ez-btn{background-color: rgb(68,178,158);border-radius: 6px;color: #fff;border: 0;height: 30px;line-height: 30px;width: 92px;margin-top: 2px;display: block;position: relative;left: 9px;float: left;font-size: 16px;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;text-align: left;padding-left: 15px;transition: opacity .3s;}', '.ez-btn:hover{background-color:#ff4e26;}', '.ez-btn[title]:hover:after {content: attr(_title);position: absolute;top: -4px;left: 105%;min-width: 100px;max-width: 300px; padding: 4px 10px;background: #000000;color: #ffffff;border-radius: 4px;text-align:left;z-index:2021;}', '.ez-panel{z-index:2021;display:none;position: absolute;width: 300px;font-size:14px;background: #ffffff;color: blue; border-radius: 4px; border: 1px solid #ff4e26; padding: 6px; margin: 2px;}', '#doc-header-test .doc-value{margin-right: 10px !important;padding-right: 10px;}', '@media print {body {display: block !important;}}', '</style>' ].join(' ') ) } $('body').append( [ '<div class="ez-panel">', '<i><h3 style = "font-weight:600;color:black;font-size: 15px;">若点击后无反应,请允许弹出窗口</h3></i>', '<h3 style = "font-weight:600;color:black;font-size: 15px;"><i>跳转到新页面请耐心等待页面加载完成</i></h3>', '<h2 style = "font-weight:600;color:black;font-size: 15px;"><i>反馈请到 <a href ="https://gitee.com/Bgz666/bdwenku-download-tampermonkey-script" target="_blank" style ="color:orange">NameSpace</a>或 </i><a href ="https://greasyfork.org/zh-CN/scripts/439850/feedback" target="_blank" style = "color:rgb(58,158,178)">这里</a></h3>', '<i style = "font-weight:500;color:red;font-size: 15px;">(Chaorenlong注:下列问题对部分文档已修复,还有问题请<a href ="https://greasyfork.org/zh-CN/scripts/439850/feedback" target="_blank" style = "color:rgb(58,158,178)"> 反馈</a>)</i>', '<br/>常见问题(原作者提供):<br/>', '1、<a href="https://greasyfork.org/zh-CN/scripts/439850/#additional-info" target="_blank">点击免费下载后,如何打印成pdf文件?</a>', '<br/>2、<a href="https://greasyfork.org/zh-CN/forum/discussion/44509/x" target="_blank">文字重叠重影该如何解决?</a>', '<br/>3、<a href="https://greasyfork.org/zh-CN/scripts/439850/#additional-info" target="_blank">图片空白,或者图片只有一半的情况如何处理?</a>', '<br/>4、<a href="https://gitee.com/Bgz666/bdwenku-download-tampermonkey-script/issues/I4THTY" target="_blank">页数超过100页的文档该如何打印成pdf?</a>', '<br/>5、<a href="https://greasyfork.org/zh-CN/scripts/439850/#additional-info" target="_blank">打印出来的pdf文件里文字断裂,或者图片表格上下页分开如何处理?</a>', '<div>' ].join('') ) if(window.location.pathname.indexOf('share')!= -1){ $('h3').remove(); if($('.center')){ $('.center').append('<button class="ez-btn">免费下载</button>')//链接为share按钮位置,此处修改 }}else if(window.location.pathname.indexOf('share')== -1){if($('.topbar-container')){ $('.topbar-container').append('<button class="ez-btn">免费下载</button>')//链接为view按钮位置,此处修改 }} //删除多余元素,或者使其隐藏 if($('.top-right-fullScreen')[0]){ $('.top-right-fullScreen')[0].remove(); } if($('#doc_bottom_wrap')[0]){ $('#doc_bottom_wrap')[0].remove(); } if($('#html-reader-go-more')[0]){ $('#html-reader-go-more')[0].setAttribute('style','display:none'); } if($('.owner-desc-wrap')[0]){ $('.owner-desc-wrap')[0].setAttribute('style','display:none'); } if($('.header-wrap')[0]){ $('.header-wrap')[0].setAttribute('style','display:none'); } if($('.aside')[0]){ $('.aside')[0].setAttribute('style','display:none'); } if($('.tag-tips')[0]){ $('.tag-tips')[0].setAttribute('style','display:none'); } if($('.fix-searchbar-wrap')[0]){ $('.fix-searchbar-wrap')[0].remove(); } if($('.top-ads-banner-wrap')[0]){ $('.top-ads-banner-wrap')[0].remove(); } if($('#activity-tg')[0]){ $('#activity-tg')[0].remove(); } if($('.crubms-wrap')[0]){ $('.crubms-wrap')[0].setAttribute('style','display:none'); } if($('.doc-tag-wrap')[0]){ $('.doc-tag-wrap')[0].setAttribute('style','display:none'); } if($('.doc-value')[0]){ $('.doc-value')[0].setAttribute('style','display:none'); } if($('.doc-bottom-wrap')[0]){ $('.doc-bottom-wrap')[0].setAttribute('style','display:none'); } if($('#next_doc_box')[0]){ $('#next_doc_box')[0].setAttribute('style','display:none'); } if($('.left')[0]){ $('.left')[0].setAttribute('style','display:none'); } if($('.centerRight')[0]){ $('.centerRight')[0].setAttribute('style','display:none'); } if($('.ft')[0]){ $('.ft')[0].setAttribute('style','display:none'); } if($('#ft')[0]){ $('#ft')[0].setAttribute('style','display:none'); } //使主要内容居中 if($('#doc-main')[0]){ if($('[data-render]')[0]){ $('#doc-main')[0].setAttribute('style','margin-left:116px'); } } if($('.reader-tools-bar-center')[0]){ $('.reader-tools-bar-center')[0].setAttribute('style','margin-right:0px'); } var t = null $('.ez-btn').hover( function () { $('.ez-panel') .css({ top: $('.ez-btn').offset().top - 160 + 'px', left: $('.ez-btn').offset().left + 70 + 'px' }) .show() }, function () { //链接上经过,保持5秒 $('a').mouseover( function(){ if (t) window.clearTimeout(t) t = window.setTimeout(function () { $('.ez-panel').hide() },5*1000) } ) //移出panel $('.ez-panel').mouseout(function(){ if (t) window.clearTimeout(t) t = window.setTimeout(function () { $('.ez-panel').hide() },500) }) //其余情况 if (t) window.clearTimeout(t) t = window.setTimeout(function () { $('.ez-panel').hide() },1000) } ) $('.ez-btn').click(function () { if(window.location.pathname.indexOf('share')== -1){ window.open('/share/' + window.location.pathname.slice(6),'_blank'); }else{ if($('.tools-bar-small')[0]){ $('.tools-bar-small')[0].setAttribute('style','display:none'); } prePrint() }}) $('body').mousedown(function (e) { if (e.button == 2) { //imgHandle() } return true }) } var a = []; var b = []; var kong = []; var c = []; function saveRecover(){ b = $('[data-render="1"]'); for(var i = 0;i<b.length;i++){ if (a.indexOf(b[i].innerHTML) == -1){ if(b[i].style.cssText.indexOf('height') != -1){ //页面小于打印时页面1/2,就调整为1/2 if (parseFloat(b[i].style.height) < 1536 / 2) { //第一第二页减去标题 if(i<2){ b[i].style.height = '762px'; } else{ b[i].style.height = '777px'; } } //添加style,打印时不在同一页 else{ b[i].style.cssText+='page-break-after: always;' } //console.log(a); } a.push(b[i].innerHTML); } if (c.indexOf(b[i]) == -1){ c.push(b[i]); //console.log(c); } } } //main function function prePrint() { $('.ez-panel').remove() $('#bottom-download').remove(); // add by eko.zhan at 2019-12-14 17:35 //遍历css文件,将main的样式取消 $('head') .find('link') .each((index, item) => { if ( $(item) .attr('href') .indexOf('/common_toc/common/style/main') != -1 ) { $(item).remove() } }) $('.read-all').click() $('.header-wrapper').remove() $('.no-full-screen').remove() $('.lazy-load').remove() $('.reader-topbar').remove() //使打印出来页面居中 //非ppt if($('[data-render]')[0]){ $('.main')[0].setAttribute('style','margin-left:-70px') } //重新定义remove方法 jQuery.fn.extend({ remove: function () { return false } }) $(window).scrollTop(10); window.setTimeout(function () { saveRecover(); }, 1000) var _h = document.body.scrollHeight, _tmp = 700 var _t = window.setInterval(function () { $(window).scrollTop(_tmp) saveRecover(); _tmp = _tmp + 700 _h = document.body.scrollHeight if (_tmp > _h) { window.clearInterval(_t) window.setTimeout(function () { saveRecover(); kong = $("[data-render='']"); for (var i = 0; i < kong.length; i++) { kong[i].innerHTML = a[i]; //console.log(kong[i]) } doPrint(); }, 1000) } }, 300) } /** * 调用浏览器打印 */ function doPrint() { window.setTimeout(function () { window.print() if($('.tools-bar-small')[0]){ if(!$('.next-pageList')[0]){ $('.tools-bar-small')[0].setAttribute('style','display:block');//显示下边栏 } } if($('.main')[0]){ $('.main')[0].setAttribute('style','margin-left:120px')//页面居中 } }, 2000) } })()