- Loads JSZip library from CDN
- Finds all PDF links on the page
- Fetches each PDF file
- Adds them all to a single ZIP file
- Downloads the ZIP file as
pdfs.zip
// Load JSZip library
const script = document.createElement('script');
script.src = 'https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js';
script.onload = async function() {
console.log('JSZip loaded, collecting PDFs...');
// Find all PDF links
const pdfLinks = Array.from(document.querySelectorAll('a'))
.filter(link => link.href.toLowerCase().includes('.pdf'))
.map(link => link.href);
console.log(`Found ${pdfLinks.length} PDF files`);
if (pdfLinks.length === 0) {
console.log('No PDF files found on this page');
return;
}
// Create zip file
const zip = new JSZip();
// Download each PDF and add to zip
for (let i = 0; i < pdfLinks.length; i++) {
try {
console.log(`Downloading ${i + 1}/${pdfLinks.length}: ${pdfLinks[i]}`);
const response = await fetch(pdfLinks[i]);
const blob = await response.blob();
const filename = pdfLinks[i].split('/').pop().split('?')[0] || `document_${i}.pdf`;
zip.file(filename, blob);
} catch (error) {
console.error(`Failed to download ${pdfLinks[i]}:`, error);
}
}
// Generate and download zip
console.log('Creating ZIP file...');
const zipBlob = await zip.generateAsync({type: 'blob'});
const a = document.createElement('a');
a.href = URL.createObjectURL(zipBlob);
a.download = 'pdfs.zip';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
console.log('Done! Check your downloads folder for pdfs.zip');
};
document.head.appendChild(script);