codemuffin

Humble Bundle Renamer - jQuery

Jan 1st, 2018
419
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Create an array to store our batch file lines
  2. var output = [];
  3.  
  4. // Build the array
  5. $('.js-all-downloads-holder .whitebox-redux .row').each(function(){
  6.     // Get name
  7.     var name = $(this).find('.gameinfo .title a:first-child').text().trim();
  8.    
  9.     // Replace illegal characters (you can change the "" in the second parameter to whatever you like, as with the first line)
  10.     name = name.replace(":", " -");
  11.     name = name.replace("?", "");
  12.     name = name.replace("*", "");
  13.     name = name.replace("|", "");
  14.    
  15.     // Get filenames & add them to the output array
  16.     $(this).find('.downloads .download .a').each(function() {
  17.         // Get single link URL
  18.         var url = $(this).attr('href');
  19.        
  20.         // Remove the query string from the URL
  21.         var urlQueryIndex = url.indexOf('?');
  22.         var urlSliced = url.slice(0, urlQueryIndex);
  23.        
  24.         // Remove the domain path
  25.         var filename = urlSliced.replace("https://dl.humble.com/", "");
  26.        
  27.         // Get the file extension (".pdf", etc)
  28.         var extensionIndex = urlSliced.lastIndexOf('.');
  29.         var extension = url.slice(extensionIndex, urlSliced.length);
  30.        
  31.         // Batch file renaming convention is "rename [old filename] [new filename]"
  32.         var oldFilename = filename;
  33.         var newFilename = name + extension;
  34.         var batLine = 'rename ' + oldFilename + ' "' + newFilename + '"';
  35.         output.push(batLine);
  36.     });
  37. });
  38.  
  39. // Create an empty textarea, and usage instructions
  40. $('.js-all-downloads-holder .whitebox-redux').prepend('<div style="margin-bottom: 20px;font-size: 18px;line-height: 25px;"><strong>Batch Renamer Instructions:</strong><ol><li>Copy and paste the text below into an empty text file named "renamer.txt"</li><li>Rename this file to "renamer.bat" (without quotes)</li><li>Put the file into a folder with all of your downloaded files (be sure to make backups first, just in case!)</li><li>Double-click the .bat file, and your files will be renamed!</li></ol></div><textarea class="batch-file-output" style="width: 100%; min-height: 500px;margin-bottom: 20px;"></textarea>');
  41.  
  42. // Output the array to the textarea
  43. $.each(output, function(index, value) {
  44.     console.warn(value);
  45.     $('.batch-file-output').append(value + "\n");
  46. });
Add Comment
Please, Sign In to add comment