Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function go () {
- // get all the links from the grid on the current page
- const hrefs = Array.from(document.querySelectorAll('.ez-resource-grid a[href]')).map(a => a.href);
- // start the loading
- next(hrefs);
- }
- function next ([current, ...remaining]) {
- // open a new tab/window with the current href;
- const w = window.open(current, '_blank');
- // function to find the download button and "click" it.
- function triggerDownload () {
- try {
- w.querySelector('#download-button').click();
- }
- catch (e) {
- // something went wrong.
- }
- // if we haven't consumed all the links yet, start the next one.
- if (remaining.length) {
- next(remaining);
- // I tried adding a delay here thinking the account signup dialog
- // might be triggered by too many rapid requests, but it didn't
- // seem to matter.
- // setTimeout(() => next(remaining), 6000);
- }
- }
- // give the page a few seconds to load before attempting
- // to trigger the download. This should be replaced with
- // a ready event listener instead of a fixed delay, something
- // like:
- // w.document.addEventListener('readystatechange', triggerDownload)
- // but i'm tired and my first attempt didn't appear to work so i'm
- // throwing in this static delay hack instead.
- setTimeout(triggerDownload, 5000);
- }
- // kick it off
- go();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement