Skip to content

Instantly share code, notes, and snippets.

@masotime
Last active June 19, 2016 12:36
Show Gist options
  • Save masotime/b7206e6c5b728e84bb7cbba52750d7a4 to your computer and use it in GitHub Desktop.
Save masotime/b7206e6c5b728e84bb7cbba52750d7a4 to your computer and use it in GitHub Desktop.
Automated humble bundle comic downloading script because humble bundle sucks
function guessDownloadDuration($cbz, MBps) {
if ($cbz.length === 0) {
return 0;
}
const rawValue = $cbz.parent().find('.right-align').contents().get(0).textContent;
if (rawValue.includes('MB')) {
const sizeInMb = parseFloat(rawValue.split('MB')[0].trim());
const durationInMs = Math.round(sizeInMb / MBps * 1000);
return durationInMs
}
return 30 * 1000; // assume 30 seconds
}
function download() {
const $cbz = $('h4:contains("CBZ")');
let duration = 0;
if ($cbz.length > 0) {
duration = guessDownloadDuration($cbz, 1.5);
$cbz.click();
}
// regardless of whether it is found or not, do a setTimeout to advance to the next item
const $next = $('.subproduct-selector.selected').next();
console.log({ duration, $next });
if ($next.length > 0) {
setTimeout(() => {
$next.click();
download();
}, duration);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment