Skip to content

Instantly share code, notes, and snippets.

@qinlili23333
Created August 2, 2022 09:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qinlili23333/ea6ed58f8374f85339ed0cbbd4ce8f60 to your computer and use it in GitHub Desktop.
Save qinlili23333/ea6ed58f8374f85339ed0cbbd4ce8f60 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name 机械工业下载器
// @namespace https://qinlili.bid
// @version 0.1
// @description 劫持PDFJS下载
// @author 琴梨梨
// @match https://dcd.cmanuf.com/ebook/web/index.html*
// @grant none
// @run-at document-start
// ==/UserScript==
(function() {
'use strict';
const dlFile = (link, name) => {
let eleLink = document.createElement('a');
eleLink.download = name;
eleLink.style.display = 'none';
eleLink.href = link;
document.body.appendChild(eleLink);
eleLink.click();
document.body.removeChild(eleLink);
};
let originConsole=console.log;
originConsole("Launching...");
//劫持Uptodown的谷歌play按钮
(function (appendChild) {
Node.prototype.appendChild = function (node) {
if (node.src&&node.src.indexOf("pdf_viewer.min.js")>0 ){
alert("Hook Success!");
originConsole("Ready...");
let originGet=pdfjsLib.getDocument;
pdfjsLib.getDocument=doc=>{
originConsole(doc);
dlFile(URL.createObjectURL(new Blob([doc.data])),Date.now()+".pdf")
return originGet(doc);
}
return appendChild.call(this, node);
} else {
return appendChild.call(this, node);
}
};
})(Node.prototype.appendChild);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment