Forked from Woody2143/humble_bundle_file_downloader.js
Last active
March 25, 2020 08:58
-
-
Save tlc/96292166c7253f86565f0d18e5f8ec41 to your computer and use it in GitHub Desktop.
Download HumbleBundle book bundles easier. Puts 'curl' statements on the page for you to copy.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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