Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 7h3kk1d/0fd15b3f95c0a172b76537145539266e to your computer and use it in GitHub Desktop.
Save 7h3kk1d/0fd15b3f95c0a172b76537145539266e to your computer and use it in GitHub Desktop.
Download HumbleBundle book bundles easier. Puts 'curl' statements on the page for you to copy.
/* 11/27/2017 - Tweaked for a page redesign.
* 1/6/2018 - Handle videos in book bundle.
*/
var pattern = /(MOBI|EPUB|PDF( ?\(H.\))?|CBZ)$/i;
var pattern2 = /(Download)$/;
var nodes = document.getElementsByTagName('a');
var downloadCmd = '';
for (i in nodes) {
var a = nodes[i];
if (a && a.text && pattern.test(a.text.trim())) {
var name = a.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.getAttribute("data-human-name");
name = name.replace(/\s+/g, '_'); /* change spaces to underscores */
name = name.replace(/'/g, ''); /* don't want single quotes */
name = name.replace(/:/g, '_-'); /* change : to _- for looks */
name = name.replace(/,/g, ''); /* don't need commas */
name = name.replace(/&/g, 'and'); /* taking out the pesky & */
name = name.replace(/!/g, ''); /* taking out the pesky ! */
if (a.text.trim() == 'PDF (HQ)') {
name += ".HQ.pdf";
} else {
name += "." + a.text.trim().toLowerCase();
}
downloadCmd += 'curl -o "' + name + '" "' + a.attributes['href'].value + "\"\n";
} else if (a && a.text && pattern2.test(a.text.trim())) {
/* videos in book bundle */
var name = a.attributes['href'].value
name = name.replace(/\.zip\?.*/, '.zip'); /* remove ?gamekey=... */
name = name.replace(/.*\//g, ''); /* remove http ... / */
downloadCmd += 'curl -o "' + name + '" "' + a.attributes['href'].value + "\"\n";
}
}
downloadCmd += "\n";
var output = document.createElement("pre");
output.textContent = downloadCmd;
document.getElementById("papers-content").prepend(output);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment