Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- After purchasing a humble book bundle, go to your download page for that bundle.
- Open a console window for the page and paste in the below javascript
- */
- function windowsNormalize(path) {
- return path.replace( /[<>:"\/\\|?*]/g, '_' );
- }
- function getTitle() {
- var re = /^Humble\ Book\ Bundle\:\ (.*)\ \(/g;
- return re.exec(document.title)[1];
- }
- function showHashes() {
- document.querySelectorAll('.dlmd5').forEach(md5 => {
- if (md5.innerText.trim() == 'md5') {
- md5.click();
- }
- });
- }
- function gatherInfo() {
- const data = [];
- const bundleTitle = getTitle();
- showHashes();
- document.querySelectorAll('.row').forEach(row => {
- const bookTitle = row.dataset.humanName;
- [...row.querySelectorAll('.downloads .download')].forEach(dl => {
- const downloadLink = dl.querySelector('.flexbtn a').href;
- const filename = /\.com\/([^?]+)/.exec(downloadLink)[1];
- data.push({
- "bundleTitle": bundleTitle,
- "bookTitle": bookTitle,
- "filename": filename,
- "downloadLink": downloadLink,
- });
- });
- });
- return data;
- }
- function downloadBookBundle() {
- const commands = []
- const md5Sums = [];
- const info = gatherInfo();
- for (var i in info) {
- bundleTitle = info[i]["bundleTitle"];
- bookTitle = info[i]["bookTitle"];
- filename = info[i]["filename"];
- downloadLink = info[i]["downloadLink"];
- commands.push(`curl --create-dirs -o "${windowsNormalize(bundleTitle)}/${windowsNormalize(bookTitle)}/${windowsNormalize(filename)}" "${downloadLink}"`);
- };
- console.log(commands.join(' && '));
- }
- downloadBookBundle();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement