// ==UserScript== // @name SmartEdu pdf download // @namespace http://tampermonkey.net/ // @version 1.0 // @description pdf download from SmartEdu // @author JackieZheng // @match https://basic.smartedu.cn/tchMaterial/detail?contentType=assets_document&contentId=* // @icon https://www.google.com/s2/favicons?sz=64&domain=smartedu.cn // @grant GM_addStyle // @license MIT // @downloadURL https://update.greasyfork.icu/scripts/509187/SmartEdu%20pdf%20download.user.js // @updateURL https://update.greasyfork.icu/scripts/509187/SmartEdu%20pdf%20download.meta.js // ==/UserScript== GM_addStyle("#downBtn{border-radius: 6px;width: 45px;margin: 5px auto;}"); GM_addStyle("#downBtn>a{width: 45px;margin: 0;padding: 2px 0 2px 0;}"); GM_addStyle("#downBtn>a>i{height: 30px;width: 30px;background: #f6f7f9;display: block;border-radius: 6px;margin: 3px auto 13px auto;"); (function() { window.setTimeout(()=>{ var matchReg = /(?<=file=).*?\.pdf/gi; let frameSrc=document.querySelector('iframe')?.src; let pdfUrl=frameSrc.match(matchReg)[0]; console.log(pdfUrl); let pdf=pdfUrl.replace('-private',''); console.log(pdf); document.querySelector('iframe').src=pdf; let toolBar=document.querySelector('div[class^=index-module_fn]'); let clsName=toolBar.childNodes[0].className; var downloadBtn = document.createElement("div"); downloadBtn.setAttribute("id", "downBtn"); downloadBtn.onclick = function() { let fileName = pdf.substring(pdf.lastIndexOf('/') + 1); downloadFile(pdf,decodeURI(fileName)) ; } // download="'+pdf+'" href="'+pdf+'" downloadBtn.innerHTML ='

下载PDF

'; toolBar.insertBefore(downloadBtn,toolBar.childNodes[0]) },5000); })(); function downloadFile(url, fileName) { fetch(url) .then(response => response.blob()) .then(blob => { const link = document.createElement('a'); link.href = URL.createObjectURL(blob); link.download = fileName; link.target = "_blank"; link.click(); }); }