您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Greasy Fork is available in English.
52pojie、CSDN页面文章一键保存为PDF
当前为
// ==UserScript== // @name SaveToPDF // @namespace https://www.null119.cn // @version 0.2 // @description 52pojie、CSDN页面文章一键保存为PDF // @author null119 // @match https://www.52pojie.cn/thread-* // @match https://blog.csdn.net/*/*/details/* // @icon https://gitee.com/null119/mypic/raw/master/img/202202140807071.png // @grant none // ==/UserScript== (function() { "use strict"; var host,url window.onload=function(){ var up,nxg1,newa,nimg,ndiv,allshow; url=window.location.href; up="//.*?\\.(.*?)\\." host=url.match(up)[1]; if(host==="52pojie"){ nxg1 = document.getElementById("post_reply"); if (nxg1) { nimg=document.createElement("img"); nimg.src="https://gitee.com/null119/mypic/raw/master/img/202202140612986.png"; newa = document.createElement("a"); newa.id="HtmToPDF"; newa.href="javascript:SaveToPDF();"; newa.title="收藏"; newa.appendChild(nimg); nxg1.parentNode.insertBefore(newa,nxg1.nextSibling); } } if(host==="csdn"){ setTimeout(1500); nxg1 = document.getElementsByClassName("opt-letter-watch-box"); if (nxg1) { newa = document.createElement("a"); newa.setAttribute("class","personal-watch bt-button"); newa.id="HtmToPDF"; newa.href="javascript:SaveToPDF();"; newa.text="收藏"; ndiv=document.createElement("div"); ndiv.setAttribute("class","opt-letter-watch-box"); ndiv.appendChild(newa); nxg1[1].parentNode.insertBefore(ndiv,nxg1[1].nextSibling); allshow=document.getElementById("btn-readmore-zk"); if(allshow){ allshow.click() }; var zk=document.getElementsByClassName("look-more-preCode contentImg-no-view"); if(zk.length>0){ console.log(zk.length-1); for (var j = 0; j<zk.length; j++) { (function (j) { setTimeout(function () { zk[j].click(); console.log(j+'.click'); },j * 100); })(j); } } } } }; window.SaveToPDF=function(){ var htmldoc,test,idstr,sprnstr,eprnstr,instart,s_a,e_a,bdhtml,prnhtml,title sprnstr="LS1zdGFydHByaW50LS0="; eprnstr="LS1lbmRwcmludC0t"; htmldoc=document.documentElement.outerHTML; if(host==="52pojie"){ test="comment_(\\d+)"; idstr="postmessage_"+htmldoc.match(test)[1]; instart=document.getElementById(idstr); title=document.getElementById("thread_subject").innerText; }; if(host==="csdn"){ instart=document.getElementById("article_content"); title=document.getElementById("articleContentId").innerText; } s_a=document.createElement("a"); s_a.text=atob(sprnstr); s_a.style.display = "none"; instart.parentNode.insertBefore(s_a,instart); e_a=document.createElement("a"); e_a.text=atob(eprnstr); e_a.style.display = "none"; instart.parentNode.insertBefore(e_a,instart.nextSibling); bdhtml=window.document.body.innerHTML; prnhtml=bdhtml.substr(bdhtml.indexOf(atob(sprnstr))+14); prnhtml=prnhtml.substring(0,prnhtml.indexOf(atob(eprnstr))); const newWin = window.open(""); newWin.document.body.innerHTML = '<html><h1><a href="'+url+'">'+title+"</a></h1>"+prnhtml+"</html>"; newWin.document.close(); newWin.focus(); setTimeout(() => { newWin.print(); newWin.close(); }, 300); }; })();