Created
January 11, 2018 21:35
-
-
Save LittleHelicase/618e3f4321010f5806a05763584ba832 to your computer and use it in GitHub Desktop.
Download all the files via javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// download files via predicate function. Simply paste this into the developer console on a site to download files. It will download all of them at once! | |
function downloadAllFiles(predicate) { | |
var files = Array.prototype.slice.call(document.getElementsByTagName("a"), 0).filter((tag) => predicate(tag.href)).map((t) => t.href) | |
files.forEach((p) => { | |
var clickEvent = document.createEvent("MouseEvent") | |
clickEvent.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null) | |
var downloadButton = document.createElement("a") | |
downloadButton.href = p | |
downloadButton.download = p.slice(-p.lastIndexOf('/')) | |
downloadButton.dispatchEvent(clickEvent); | |
}) | |
} | |
// change the predicate here to specify which files you want to download. | |
downloadAllFiles((link) => link.slice(-4) === '.pdf') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment