Skip to content

Instantly share code, notes, and snippets.

@obsti8383
Forked from vdsabev/download.js
Last active January 23, 2023 17:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save obsti8383/38203720b51ce77159cc3c85a08e3bc0 to your computer and use it in GitHub Desktop.
Save obsti8383/38203720b51ce77159cc3c85a08e3bc0 to your computer and use it in GitHub Desktop.
Bookmarklet - download all PDFs in links on a page
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