[new] CSDN article one click printing and PDF output (Automatic full text reading and full refreshing mode)

Posted by hostfreak on Thu, 16 Dec 2021 16:14:50 +0100

1, Function and usage

Usage: press "F12" to enter the developer tool, copy the following js to the console, and press enter to print with one click.

Function:

1. Auto expand read full text
2. Delete the top bar, side bar, related article display, browsing information, advertising, likes and other redundant information. True all fresh mode.
3. Auto output print preview
4. Automatically scale the printed page to avoid cutting the content at the edge of the page. (added on October 31, 2020)

Latest method: (October 31, 2020)

Method 1: removal method

Updated content: 1. Remove the copyright information column at the bottom. 2. Add automatic scaling of the printed page. 3. Remove redundant and invalid content.

Note: if you find that there is a title at the top of each page during print preview, please refer to step 3 below to remove the check box of "header and footer"

(function(){
	'use strict';
	var articleBox = $("div.article_content");
	articleBox.removeAttr("style");
	$("#btn-readmore").parent().remove();
	$("#side").remove();
	$("#comment_title, #comment_list, #comment_bar, #comment_form, .announce, #ad_cen, #ad_bot").remove();
	$(".nav_top_2011, #header, #navigator").remove();
	$(".csdn-side-toolbar,.template-box,.reward-user-box,.blog-footer-bottom").remove();
	$(".p4course_target, .comment-box, .recommend-box, #csdn-toolbar, #tool-box,#dmp_ad_58, .more-toolbox, .article-info-box, .btn-readmore, .pub-footer-new").remove();
	$("aside").remove();
	$(".tool-box").remove();
	$("main").css('display','content'); 
	$("main").css('float','left'); 
	$("#mainBox").width("100%");		
	document.getElementsByTagName('body')[0].style.zoom=0.8;
	window.print();
})();

Method 2: HTML reconstruction method (added on October 31, 2020)

This method has the same function as method 1, the code is more concise, the web page is automatically restored after printing, and the subsequent addition of other redundant modules in CSDN will not be affected.

(function doPrint(){      
	'use strict';
	var articleBox = $("div.article_content");
	articleBox.removeAttr("style");
	var head_str = "";       
	var foot_str = "";   
	var older = document.body.innerHTML;       
	var title= document.getElementsByClassName('article-title-box')[0].innerHTML; 
	var main_body = document.getElementsByClassName('article_content')[0].innerHTML;
	document.body.innerHTML = head_str + title + main_body + foot_str;
	$("#mainBox").width("100%");
	document.getElementsByTagName('body')[0].style.zoom=0.8;     
	window.print();
	document.body.innerHTML = older;
	return false;
})();

3, Other issues

1. Save as PDF. Change the printer to "save as PDF".

2. More settings. (2020 / 10 / 30 method has added automatic setting in the code)

(1) In some articles, some words at the edge of the page will be cut off.

  • Select "None" for "margin".
  • Use zoom (for example, set "80%") to reduce the overall size so that it will not exceed the page.


(2) You can close headers, footers, etc.

4, Optimization part

In this method, the following information is added, modified and deleted, and the real full refreshing printout is realized:

(1) Automatically "expand reading full text" and automatically print the full text.)

(2) The whole page of the new version will move to the right.

(3) Browsing information in the article header:

(4) Like information at the bottom of the article and advertising information at the bottom:

(5) The "report top" box on the right of the article.

(6) Information bar at the bottom

(7) Copyright information bar at the bottom

I don't know if the module name has been changed and the information bar has reappeared. Update here to remove the copyright information bar at the bottom

(8) Auto zoom print page

It is found that the content has been cropped during print preview. You have to manually modify the zoom scale. It is too troublesome. Here, the automatic zoom setting is updated. (method reference: Zoom print.)