-
-
Save obsti8383/38203720b51ce77159cc3c85a08e3bc0 to your computer and use it in GitHub Desktop.
Bookmarklet - download all PDFs in links on a page
This file contains 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
javascript:(() => { | |
const items = document.querySelectorAll('a'); | |
let delay = 0; | |
for (let index = 0; index < items.length; index++) { | |
const item = items[index]; | |
if (item.getAttribute('href') != null && item.getAttribute('href').endsWith('.pdf')){ | |
/* only write last part of link to download element (filename) */ | |
var downloadUri = item.getAttribute('href'); | |
var n = downloadUri.lastIndexOf('/'); | |
var result = downloadUri.substring(n + 1); | |
item.setAttribute('download', result); | |
setTimeout(() => item.click(), delay); | |
delay += 500; | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment