Skip to content

Instantly share code, notes, and snippets.

@cocoastorm
Created April 9, 2021 05:44
Show Gist options
  • Save cocoastorm/a690a5bbc1ed788ba763c8bc236cd900 to your computer and use it in GitHub Desktop.
Save cocoastorm/a690a5bbc1ed788ba763c8bc236cd900 to your computer and use it in GitHub Desktop.
humble bundle export download links to a list
// ==UserScript==
// @name humble export downloads as a text file
// @version 1
// @match https://www.humblebundle.com/downloads*
// @grant none
// @require https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2.0.0/FileSaver.min.js
// ==/UserScript==
(function() {
'use strict';
function parseDownloadButtons() {
var selector = '.download-rows .download a';
var downloadButtons = document.querySelectorAll(selector);
var links = [];
for (var i = 0; i < downloadButtons.length; i++) {
var btn = downloadButtons.item(i);
var link = btn.href;
if (link !== undefined && link !== null) {
links.push(link);
}
}
return links;
}
function exportAsList(desiredFileType) {
var fileType = desiredFileType.toLowerCase();
var links = parseDownloadButtons();
if (desiredFileType !== undefined && desiredFileType !== null) {
links = links.filter(function (link) {
return link.indexOf(fileType) > 0;
});
}
var content = links.join("\n");
var txt = new Blob([content], { type: 'plain/text;charset=utf-8' });
saveAs(txt, "humble-download-links.txt");
}
function ourDownloadButton() {
var selector = '.js-all-downloads-holder .bulk-downloader';
var typeSelector = 'select.js-file-type-select';
var bulkDownloader = document.querySelector(selector);
var select = document.querySelector(selector + ' ' + typeSelector);
var fileType = select.value;
var ourBtn = document.createElement('button');
ourBtn.appendChild(document.createTextNode('Export as List'));
ourBtn.addEventListener('click', function () {
exportAsList(fileType);
});
bulkDownloader.appendChild(ourBtn);
}
// ready, set, go!
var isRegistered = false;
var run = setInterval(function () {
// already there, don't keep running this please
if (isRegistered) {
return;
}
// keep checking for bulk downloader <div>
var box = document.querySelector('.js-all-downloads-holder .bulk-downloader');
if (box === undefined || box === null) {
return false;
}
// once it's found register the button
clearInterval(run);
// set our excellent button
ourDownloadButton();
isRegistered = true;
}, 500);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment