Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. function go () {
  2. // get all the links from the grid on the current page
  3. const hrefs = Array.from(document.querySelectorAll('.ez-resource-grid a[href]')).map(a => a.href);
  4.  
  5. // start the loading
  6. next(hrefs);
  7. }
  8.  
  9. function next ([current, ...remaining]) {
  10. // open a new tab/window with the current href;
  11. const w = window.open(current, '_blank');
  12.  
  13. // function to find the download button and "click" it.
  14. function triggerDownload () {
  15. try {
  16. w.querySelector('#download-button').click();
  17. }
  18. catch (e) {
  19. // something went wrong.
  20. }
  21.  
  22. // if we haven't consumed all the links yet, start the next one.
  23. if (remaining.length) {
  24. next(remaining);
  25.  
  26. // I tried adding a delay here thinking the account signup dialog
  27. // might be triggered by too many rapid requests, but it didn't
  28. // seem to matter.
  29. // setTimeout(() => next(remaining), 6000);
  30. }
  31. }
  32.  
  33. // give the page a few seconds to load before attempting
  34. // to trigger the download. This should be replaced with
  35. // a ready event listener instead of a fixed delay, something
  36. // like:
  37. // w.document.addEventListener('readystatechange', triggerDownload)
  38. // but i'm tired and my first attempt didn't appear to work so i'm
  39. // throwing in this static delay hack instead.
  40. setTimeout(triggerDownload, 5000);
  41. }
  42.  
  43. // kick it off
  44. go();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement