CSDN 1-Click Downloader

1-Click Download CSDN pages to PDF

As of 2024-05-20. See the latest version.

  1. // ==UserScript==
  2. // @name CSDN 1-Click Downloader
  3. // @namespace https://github.com/ySpica
  4. // @version 1.1
  5. // @description 1-Click Download CSDN pages to PDF
  6. // @author Spica Yeung
  7. // @connect www.csdn.net
  8. // @match https://blog.csdn.net/*/article/details/*
  9. // @icon none
  10. // @grant none
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. // Add a button to the page
  18. const button = document.createElement('button');
  19. button.textContent = '↡';
  20. button.style.position = 'fixed';
  21. button.style.top = '50px';
  22. button.style.right = '5px';
  23. button.style.zIndex = 1000;
  24. button.style.padding = '5px 10px';
  25. button.style.background = 'white';
  26. button.style.border = '1px solid #ccc';
  27. button.style.cursor = 'pointer';
  28. document.body.appendChild(button);
  29.  
  30. // Add click event to the button
  31. button.onclick = function() {
  32. $("#side").remove();
  33. $("#comment_title, #comment_list, #comment_bar, #comment_form, .announce, #ad_cen, #ad_bot").remove();
  34. $(".nav_top_2011, #header, #navigator").remove();
  35. $(".p4course_target, .comment-box, .recommend-box, #csdn-toolbar, #tool-box").remove();
  36. $("aside").remove();
  37. $(".tool-box").remove();
  38. $("#toolBarBox").remove();
  39. $("main").css('display', 'block'); // Adjusting to 'block' instead of 'content' for proper display
  40. $("main").css('float', 'none'); // Adjusting to 'none' to center the content after other elements are removed
  41. $(".option-box").remove();
  42. $("body").css('min-width', '0');
  43. window.print();
  44. };
  45. })();