Advertisement
__zero__

pdf dl

Apr 3rd, 2020
856
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.     Download multiple PDF from WebSite
  3.    
  4.     You need to disable Chrome PDF Viewer,
  5.     and unblock multiple file downloads in a Site
  6.    
  7. */
  8. var origin = document.getElementsByTagName("a");
  9. var a = Array.from(origin);
  10.  
  11. function sleep(milliseconds) {
  12.     /* https://www.sitepoint.com/delay-sleep-pause-wait/ */
  13.   const date = Date.now();
  14.   let currentDate = null;
  15.   do {
  16.     currentDate = Date.now();
  17.   } while (currentDate - date < milliseconds);
  18. }
  19.  
  20. a.forEach(function(elem, index)
  21. {
  22.     var pos;
  23.     if (elem.href.endsWith(".pdf"))
  24.     {
  25.         pos = a[index].href.lastIndexOf("/");
  26.         pos++;
  27.         origin[index].setAttribute("download", elem.href.substring(pos));
  28.         origin[index].target = "_blank";
  29.         console.log("click on", origin[index]);
  30.         origin[index].click();
  31.         console.log(elem.href.substring(pos), index);
  32.         sleep(2000);
  33.     }
  34. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement