目标网站:aHR0cHM6Ly93d3cuZG9jODguY29tLw==
简介
本着有好东西不能偷偷用的原则,分享一个神奇的书签脚本,下载目标网站公开免费的在线文档1:1高清,书签脚本如何使用自行学习。
知识
以下代码可在不刷新页面的情况更新地址栏参数
const url = new URL(window.location.href);
url.searchParams.set('状态', '666');
history.pushState({}, '', url.href);
使用
添加好书签脚本,打开你要下载文档地址,点击一次书签脚本观察地址栏参数变化自动下载。
代码
源码未混淆只是做了压缩
javascript:(async()=>{"use strict";let loading=false;const script=document.createElement("script");script.src="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-M/jspdf/2.4.0/jspdf.umd.min.js";script.fetchpriority="high";script.addEventListener("load",(()=>{console.log("外部库加载完成!");loading=true}));document.body.appendChild(script);await new Promise(((resolve,reject)=>{const interval=setInterval((()=>{if(loading){clearInterval(interval);resolve(true)}}),100)}));const CLASS_NAME_LIST="#pageContainer .inner_page";const title=document.title;console.log(title);let timer=null;const jsPDF=jspdf.jsPDF;const doc=new jsPDF({orientation:"l",unit:"px",compress:true,hotfixes:["px_scaling"]});function updateState(params){const url=new URL(window.location.href);url.searchParams.set("状态",params);history.pushState({},"",url.href)}updateState("开始预览");function updateProgress(current,total){let p=current/total*100;let ps=p.toFixed(0)>100?100:p.toFixed(0);console.log("当前进度",ps);let url=new URL(window.location.href);url.searchParams.set("p",ps);history.pushState({},"",url.href)}function addDataPage(data,i,width,height){let dir="p";if(width>height){dir="l"}doc.addPage([width,height],dir);doc.addImage(data,"JPEG",0,0,width,height,i,"FAST");if(doc.internal.pages[1].length===2){doc.deletePage(1)}}function traverseSaveCanvas(){const nodes=document.querySelectorAll(CLASS_NAME_LIST);const len=nodes.length;for(let i=0;i<len;i++){const item=nodes[i];let previousElementSibling=item.previousElementSibling.previousElementSibling;let t=previousElementSibling.innerText;if(t.length!==0){continue}updateProgress(i+1,len);addDataPage(item,i,item.width,item.height)}console.log("处理完成",length);updateState("正在下载");doc.save(`${title}.pdf`,{returnPromise:true}).then((res=>{console.log(res)}))}function isElementInViewport(element){const rect=element.getBoundingClientRect();const windowHeight=window.innerHeight;if(rect.top<=0&&rect.top>=-rect.height){return true}else if(rect.bottom>=0&&rect.bottom<=rect.height){return true}else{return false}}function clearTimer(){if(timer){clearInterval(timer)}}function previewPage(){const nodes=document.querySelectorAll(CLASS_NAME_LIST);const len=nodes.length;let finish=true;for(let i=0;i<len;i++){let node=nodes[i];let previousElementSibling=node.previousElementSibling.previousElementSibling;let fs=node.getAttribute("fs");let t=previousElementSibling.innerText;if(t.length!==0){node.scrollIntoView({behavior:"smooth"});finish=false;updateProgress(i+1,len);break}}if(finish){updateState("开始下载");traverseSaveCanvas();clearTimer()}else{console.log("还没有")}return finish}function continueLoad(){let eb=document.querySelector("#continueButton");if(eb){eb.click()}}timer=setInterval((()=>{continueLoad();let end=previewPage();console.log("定时器")}),500)})();
示例
