Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Create an array to store our batch file lines
- var output = [];
- // Build the array
- $('.js-all-downloads-holder .whitebox-redux .row').each(function(){
- // Get name
- var name = $(this).find('.gameinfo .title a:first-child').text().trim();
- // Replace illegal characters (you can change the "" in the second parameter to whatever you like, as with the first line)
- name = name.replace(":", " -");
- name = name.replace("?", "");
- name = name.replace("*", "");
- name = name.replace("|", "");
- // Get filenames & add them to the output array
- $(this).find('.downloads .download .a').each(function() {
- // Get single link URL
- var url = $(this).attr('href');
- // Remove the query string from the URL
- var urlQueryIndex = url.indexOf('?');
- var urlSliced = url.slice(0, urlQueryIndex);
- // Remove the domain path
- var filename = urlSliced.replace("https://dl.humble.com/", "");
- // Get the file extension (".pdf", etc)
- var extensionIndex = urlSliced.lastIndexOf('.');
- var extension = url.slice(extensionIndex, urlSliced.length);
- // Batch file renaming convention is "rename [old filename] [new filename]"
- var oldFilename = filename;
- var newFilename = name + extension;
- var batLine = 'rename ' + oldFilename + ' "' + newFilename + '"';
- output.push(batLine);
- });
- });
- // Create an empty textarea, and usage instructions
- $('.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>');
- // Output the array to the textarea
- $.each(output, function(index, value) {
- console.warn(value);
- $('.batch-file-output').append(value + "\n");
- });
Add Comment
Please, Sign In to add comment