保存CSDN文章为PDF

去掉其他元素,只保留文章内容,方便阅读

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         保存CSDN文章为PDF
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  去掉其他元素,只保留文章内容,方便阅读
// @author       jonas
// @match        https://blog.csdn.net/*/article/details/*
// @icon         https://iconfont.alicdn.com/s/a0a60ea8-d86f-483a-a2ee-cf3d9549cbad_origin.svg
// @grant        unsafeWindow
// ==/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);
})();