百度文库(wenku)在线下载PDF格式文件

百度文库文档页面打印PDF,chrome浏览器最好能安装一下 adblock 插件,下载后的pdf文件可以在 https://pdf2docx.com/zh/ 上转换成docx

  1. // ==UserScript==
  2. // @name 百度文库(wenku)在线下载PDF格式文件
  3. // @namespace http://ekozhan.com
  4. // @version 0.2.0
  5. // @description 百度文库文档页面打印PDF,chrome浏览器最好能安装一下 adblock 插件,下载后的pdf文件可以在 https://pdf2docx.com/zh/ 上转换成docx
  6. // @author eko.zhan, HelloCodeMing
  7. // @match *://wenku.baidu.com/view/*
  8. // @grant unsafeWindow
  9. // @license GPL-2.0
  10. // @icon https://www.baidu.com/cache/icon/favicon.ico
  11. // ==/UserScript==
  12.  
  13. ; (function () {
  14. 'use strict'
  15. //等待3秒页面加载完毕后再单击阅读更多按钮
  16. window.setTimeout(function () {
  17. insert()
  18. }, 300)
  19.  
  20. //insert print btn
  21. function insert() {
  22. if ($('#btnPrintStyle').length == 0) {
  23. $('head').append(
  24. [
  25. '<style id="btnPrintStyle">',
  26. '.ez-btn{background-color: #f7603e;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;}',
  27. '.ez-btn:hover{background-color:#ff4e26;}',
  28. '.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;}',
  29. '.ez-panel{z-index:2021;display:none;position: absolute;width: 300px;font-size:14px;background: #ffffff;color: #ff4e26; border-radius: 4px; border: 1px solid #ff4e26; padding: 6px; margin: 2px;}',
  30. '#doc-header-test .doc-value{margin-right: 10px !important;padding-right: 10px;}',
  31. '@media print {body {display: block !important;}}',
  32. '</style>'
  33. ].join(' ')
  34. )
  35. }
  36. $('.topbar-container').append('<button class="ez-btn">免费下载</button>')
  37. $('body').append(
  38. [
  39. '<div class="ez-panel">',
  40. '常见问题:<br/>',
  41. '1、<a href="https://gf.qytechs.cn/zh-CN/forum/discussion/46222/x" target="_blank">点击免费下载后,如何打印成pdf文件?</a>',
  42. '<br/>2、<a href="https://gf.qytechs.cn/zh-CN/forum/discussion/44509/x" target="_blank">文字重叠重影该如何解决?</a>',
  43. '<br/>3、<a href="https://gf.qytechs.cn/zh-CN/forum/discussion/47744/x" target="_blank">图片空白,或者图片只有一半的情况如何处理?</a>',
  44. '<br/>4、<a href="https://gf.qytechs.cn/zh-CN/forum/discussion/46249/x" target="_blank">页数超过100页的文档该如何打印成pdf?</a>',
  45. '<br/>5、<a href="https://gf.qytechs.cn/zh-CN/forum/discussion/47743/x" target="_blank">打印出来的pdf文件里文字断裂,或者图片表格上下页分开如何处理?</a>',
  46. '<div>'
  47. ].join('')
  48. )
  49. var t = null
  50. $('.ez-btn').hover(
  51. function () {
  52. $('.ez-panel')
  53. .css({
  54. top: $('.ez-btn').offset().top + 'px',
  55. left: $('.ez-btn').offset().left + 70 + 'px'
  56. })
  57. .show()
  58. },
  59. function () {
  60. if (t) window.clearTimeout(t)
  61. t = window.setTimeout(function () {
  62. $('.ez-panel').hide()
  63. }, 10 * 1000)
  64. }
  65. )
  66. $('.ez-btn').click(function () {
  67. prePrint()
  68. })
  69. $('body').mousedown(function (e) {
  70. if (e.button == 2) {
  71. //imgHandle()
  72. }
  73. return true
  74. })
  75. }
  76. //main function
  77. function prePrint() {
  78. $('.ez-panel').remove()
  79. // add by eko.zhan at 2019-12-14 17:35
  80. $('head')
  81. .find('link')
  82. .each((index, item) => {
  83. if (
  84. $(item)
  85. .attr('href')
  86. .indexOf('/common_toc/common/style/main') != -1
  87. ) {
  88. $(item).remove()
  89. }
  90. })
  91.  
  92. $('.read-all').click()
  93. $('.header-wrapper').remove()
  94. $('.no-full-screen').remove()
  95. $('.lazy-load').remove()
  96. $('.reader-topbar').remove()
  97.  
  98. jQuery.fn.extend({
  99. remove: function () {
  100. return false
  101. }
  102. })
  103. var _h = document.body.scrollHeight,
  104. _tmp = 0
  105. var _t = window.setInterval(function () {
  106. $(window).scrollTop(_tmp)
  107. _tmp = _tmp + 700
  108. _h = document.body.scrollHeight
  109. if (_tmp > _h) {
  110. window.clearInterval(_t)
  111. doPrint()
  112. }
  113. }, 300)
  114. }
  115.  
  116. /**
  117. * 图片处理,将 div background img 处理成 img 标签,利用 img clip:rect style 来处理图片
  118. * 暂时未找到 img clip:rect 的规律
  119. * //FIXME
  120. */
  121. function imgHandle() {
  122. $('div.reader-pic-item').each(function (i, item) {
  123. var _style = $(item)[0].style
  124. var _imgUrl = _style.backgroundImage.substring(
  125. 5,
  126. _style.backgroundImage.length - 2
  127. )
  128.  
  129. var imgPanel = '<img src="' + _imgUrl + '"/>'
  130. $(item)[0].style.backgroundImage = null
  131.  
  132. var p = document.createElement('p')
  133. $($(item)[0].attributes).each(function (i, attr) {
  134. $(p).attr(attr.nodeName, attr.nodeValue)
  135. })
  136. $(p).append(imgPanel)
  137. $(item)
  138. .parent()
  139. .html(p)
  140. })
  141. }
  142.  
  143. /**
  144. * 调用浏览器打印
  145. */
  146. function doPrint() {
  147. //imgHandle()
  148. window.setTimeout(function () {
  149. window.print()
  150. }, 3000)
  151. }
  152. })()

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址