Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Download multiple PDF from WebSite
- You need to disable Chrome PDF Viewer,
- and unblock multiple file downloads in a Site
- */
- var origin = document.getElementsByTagName("a");
- var a = Array.from(origin);
- function sleep(milliseconds) {
- /* https://www.sitepoint.com/delay-sleep-pause-wait/ */
- const date = Date.now();
- let currentDate = null;
- do {
- currentDate = Date.now();
- } while (currentDate - date < milliseconds);
- }
- a.forEach(function(elem, index)
- {
- var pos;
- if (elem.href.endsWith(".pdf"))
- {
- pos = a[index].href.lastIndexOf("/");
- pos++;
- origin[index].setAttribute("download", elem.href.substring(pos));
- origin[index].target = "_blank";
- console.log("click on", origin[index]);
- origin[index].click();
- console.log(elem.href.substring(pos), index);
- sleep(2000);
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement