Skip to content

Instantly share code, notes, and snippets.

@JamesSkemp
Forked from zuazo/hb_all_books_dl.js
Last active June 29, 2024 14:50
Show Gist options
  • Save JamesSkemp/dcce1f258e35997eb8ca714031ec414d to your computer and use it in GitHub Desktop.
Save JamesSkemp/dcce1f258e35997eb8ca714031ec414d to your computer and use it in GitHub Desktop.
Humble bundle book bundles - download all books at once
/*
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.
- General cleanup and modernization.
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
*/
(() => {
function download(url, i) {
const 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)
}
async function startSearching(delayInSeconds) {
// Delay after starting a download, in ms.
const downloadDelay = delayInSeconds * 1000;
const pattern = /(MOBI|PRC|ZIP|EPUB|PDF( ?\(H.\))?|CBZ|Download)$/i;
const nodes = document.getElementsByTagName('a');
const timer = ms => new Promise(res => setTimeout(res, ms))
for (const i in nodes) {
const 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);
}
}
}
// Pass the number of seconds you would like between starting downloads.
startSearching(3);
})();
/*
Bonus: Get book/game titles dumped to the console.
*/
(() => {
const gameInfo = document.getElementsByClassName("gameinfo");
const gameTitles = [];
for (const i in gameInfo) {
const game = gameInfo[i];
if (game && typeof game === 'object') {
const gameTitle = game.getElementsByClassName("title");
if (gameTitle) {
gameTitles.push(gameTitle[0].innerText);
}
}
}
console.log(gameTitles.sort().join('\r\n'));
console.log(`${gameTitles.length} items`);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment