humble-bundle-download-scripts/hb_all_books_dl.js

43 lines
1.8 KiB
JavaScript

/*
Forked from https://gist.github.com/zuazo/a91ecbb97b90ef3ef9ce8caf361199a2
Which was forked from https://gist.github.com/p0kR/95e05e689be4e59b1b8fb6e383b9e25a
After purchasing a humble book bundle, go to your download page for that bundle.
Open a console window on the page and paste in the below JavaScript.
JamesSkemp fork changes:
- Fix ZIP file downloads.
- Add Chrome URLs to setting pages.
- Add configurable delay between downloads.
note that if you are in chrome, chrome will not download the pdfs for you by default, to fix this
Settings (chrome://settings) --> Advanced --> Privacy and security --> Content settings --> PDF documents --> Download PDF files instead of automatically opening them in Chrome --> Turn ON
chrome://settings/content/pdfDocuments
Settings (chrome://settings) --> Advanced --> Downloads --> Ask where to save each file before downloading --> Turn OFF
chrome://settings/downloads
*/
var pattern = /(MOBI|PRC|ZIP|EPUB|PDF( ?\(H.\))?|CBZ|Download)$/i;
var nodes = document.getElementsByTagName('a');
// Delay after starting a download, in ms.
const downloadDelay = 3000;
const timer = ms => new Promise(res => setTimeout(res, ms))
async function startSearching() {
for (i in nodes) {
var a = nodes[i];
if (a && a.text && pattern.test(a.text.trim())) {
download(a.attributes['href'].value, i);
// Wait x milliseconds before looking for additional downloads.
await timer(downloadDelay);
}
}
}
function download(url, i) {
var iframe = document.createElement('iframe');
iframe.id = "dl_iframe_" + i;
iframe.style.display = "none";
document.getElementsByTagName('body')[0].appendChild(iframe);
iframe.src = url;
console.log('iframe set to', url)
}
startSearching();