通常我遇到好的文章会通过网页打印将其保存成PDF,但是在CSDN保存的时候排版有点乱,于是写了个油侯脚本把文章提出来
// ==UserScript==
// @name 保存CSDN文章为PDF
// @namespace http://tampermonkey.net/
// @version 0.1
// @description 去掉其他元素,只保留文章内容,方便阅读
// @author sersan
// @match https://blog.csdn.net/*/article/details/*
// ==/UserScript==
(function()
{
'use strict';
var article = document.getElementsByClassName("blog-content-box");
var barContent = document.getElementsByClassName("bar-content");
function openWin()
{
window.document.body.innerHTML=article[0].innerHTML;
window.print();
location.reload();
/*var myWindow = window.open('','','width=1200,height=600');
myWindow.document.write(article[0].innerHTML);
myWindow.print();*/
}
var download = document.createElement("input");
download.type = "button";
download.style.position = 'fixed';
download.style.height = '32px';
download.style.width = '82px';
download.style.button = '10px';
download.style.right = '10px';
download.style.color = '#fff';
download.style.backgroundColor="#E33E33";
download.style.borderRadius="5px"; ;
download.setAttribute("class","button");
download.setAttribute("value","下载此文章");
download.addEventListener('click', function(ev){download.remove();window.setTimeout(openWin(),2000)})
barContent[0].appendChild(download);
})();