SHARE
TWEET

Untitled

a guest Sep 11th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. After purchasing a humble book bundle, go to your download page for that bundle.
  3. Open a console window for the page and paste in the below javascript
  4. */
  5.  
  6. function windowsNormalize(path) {
  7.   return path.replace( /[<>:"\/\\|?*]/g, '_' );
  8. }
  9.  
  10. function getTitle() {
  11.   var re = /^Humble\ Book\ Bundle\:\ (.*)\ \(/g;
  12.   return re.exec(document.title)[1];
  13. }
  14.  
  15. function showHashes() {
  16.   document.querySelectorAll('.dlmd5').forEach(md5 => {
  17.     if (md5.innerText.trim() == 'md5') {
  18.       md5.click();
  19.     }
  20.   });
  21. }
  22.  
  23. function gatherInfo() {
  24.   const data = [];
  25.   const bundleTitle = getTitle();
  26.   showHashes();
  27.   document.querySelectorAll('.row').forEach(row => {
  28.     const bookTitle = row.dataset.humanName;
  29.     [...row.querySelectorAll('.downloads .download')].forEach(dl => {
  30.       const downloadLink = dl.querySelector('.flexbtn a').href;
  31.       const filename = /\.com\/([^?]+)/.exec(downloadLink)[1];
  32.       data.push({
  33.         "bundleTitle": bundleTitle,
  34.         "bookTitle": bookTitle,
  35.         "filename": filename,
  36.         "downloadLink": downloadLink,
  37.       });
  38.     });
  39.   });
  40.   return data;
  41. }
  42.  
  43. function downloadBookBundle() {
  44.   const commands = []
  45.   const md5Sums = [];
  46.   const info = gatherInfo();
  47.   for (var i in info) {
  48.     bundleTitle = info[i]["bundleTitle"];
  49.     bookTitle = info[i]["bookTitle"];
  50.     filename = info[i]["filename"];
  51.     downloadLink = info[i]["downloadLink"];
  52.     commands.push(`curl --create-dirs -o "${windowsNormalize(bundleTitle)}/${windowsNormalize(bookTitle)}/${windowsNormalize(filename)}" "${downloadLink}"`);
  53.   };
  54.   console.log(commands.join(' && '));
  55. }
  56.  
  57. downloadBookBundle();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top