Greasy Fork is available in English.

SurePrintCsdn

try to print to pdf of CSDN!

Från och med 2024-03-29. Se den senaste versionen.

  1. // ==UserScript==
  2. // @name SurePrintCsdn
  3. // @namespace http://surewong.com/SurePrint
  4. // @version 0.1
  5. // @description try to print to pdf of CSDN!
  6. // @author SureWong
  7. // @match https://*.csdn.net/*
  8. // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  9. // @grant none
  10. // @license AGPL License
  11. // ==/UserScript==
  12. // 在弹出的打印页面中将页面设置成横,缩放50%,否则显示不全
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. // Your code here...
  18. var surePrintBtn = document.createElement('button')
  19. surePrintBtn.innerHTML = "准备打印pdf"
  20. surePrintBtn.className = "sure-print-pdf"
  21.  
  22. surePrintBtn.onclick = function (e) {
  23. document.querySelector("#side")?.remove();
  24. document.querySelector("#comment_title, #comment_list, #comment_bar, #comment_form, .announce, #ad_cen, #ad_bot")?.remove();
  25. document.querySelector(".nav_top_2011, #header, #navigator")?.remove();
  26. document.querySelector(".p4course_target, .comment-box, .recommend-box, #csdn-toolbar, #tool-box")?.remove();
  27. document.querySelector("aside")?.remove();
  28. document.querySelector(".tool-box")?.remove();
  29. document.querySelector(".csdn-side-toolbar")?.remove();
  30. document.querySelector(".more-toolbox")?.remove();
  31. document.querySelector(".template-box")?.remove();
  32. document.querySelector(".bottom-pub-footer")?.remove();
  33. document.querySelector(".pre-numbering")?.remove();
  34. document.querySelector("main").setAttribute('style', 'display: content;');
  35. document.querySelector("main").setAttribute('style', 'float: left;');
  36. window.print();
  37. // document.querySelector("tool-box")?.remove();
  38. }
  39.  
  40. var body = document.body
  41. var style = document.createElement('style')
  42. style.id = "sure-print-pdf"
  43. var css = `.sure-print-pdf{
  44. position: fixed;
  45. bottom: 5%;
  46. right: 1%;
  47. width: 70px;
  48. height: 70px;
  49. background: #add8e640;
  50. color: cornflowerblue;
  51. border-radius: 50%;
  52. font-size: 10px;
  53. z-index: 999;
  54. cursor: pointer;
  55. font-size: 10px;
  56. overflow: hidden;
  57. }`
  58. if (style.styleSheet) {
  59. style.styleSheet.cssText = css;
  60. } else {
  61. style.appendChild(document.createTextNode(css));
  62. }
  63. body.appendChild(surePrintBtn)
  64. body.appendChild(style)
  65.  
  66.  
  67. })();