Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Humble Monthly Key Redeemer
- // @version 2025-02-20
- // @description This script will claim all keys and copy them to a csv file for you
- // @author u/Sceptylos
- // @match https://www.humblebundle.com/membership/*
- // @icon https://www.google.com/s2/favicons?sz=64&domain=tampermonkey.net
- // @grant unsafeWindow
- // ==/UserScript==
- (function() {
- 'use strict';
- function createButton() {
- let btn = document.createElement("button");
- btn.innerText = "Start Auto-Claim";
- btn.style.position = "fixed";
- btn.style.bottom = "20px";
- btn.style.right = "20px";
- btn.style.padding = "10px 15px";
- btn.style.background = "#28a745";
- btn.style.color = "white";
- btn.style.border = "none";
- btn.style.borderRadius = "5px";
- btn.style.cursor = "pointer";
- btn.style.zIndex = "9999";
- btn.style.fontSize = "16px";
- btn.addEventListener("click", processChoices);
- document.body.appendChild(btn);
- }
- function convertToCSV(arr) {
- const header = Object.keys(arr[0]).join(","); // CSV header (game,key)
- const rows = arr.map(obj => Object.values(obj).join(",")); // Convert each object to CSV row
- return [header, ...rows].join("\n");
- }
- function downloadCSV(filename, csvData) {
- const blob = new Blob([csvData], { type: "text/csv" });
- const link = document.createElement("a");
- link.href = URL.createObjectURL(blob);
- link.download = filename;
- document.body.appendChild(link);
- link.click();
- document.body.removeChild(link);
- }
- async function processChoices() {
- let master = [];
- let keys = [];
- let gotScammed = [];
- function sleep(ms) {
- return new Promise(resolve => setTimeout(resolve, ms));
- }
- async function openChoice(choice) {
- return new Promise((resolve) => {
- let name = choice.querySelector('.content-choice-title')?.innerText.trim();
- console.log(`Opening modal for: ${name}`);
- let openButton = choice.querySelector('.js-open-choice-modal');
- if (openButton) openButton.click();
- let attempts = 0;
- let checkModal = setInterval(async function () {
- let modal = document.querySelector('.humblemodal-modal--open');
- if (modal) {
- clearInterval(checkModal);
- console.log(`✅ Modal detected for: ${name}`);
- var keyField = modal.querySelector('.keyfield-value')?.innerText.trim();
- // If the game hasn't been redeemed yet, redeem it
- if (keyField?.includes("GET GAME ON STEAM")) {
- modal.querySelector('.js-keyfield').click();
- console.log(`⚠️ Trying to redeem key for ${name}, sleeping script for 30s to give the page time to load key`);
- await sleep(30000);
- keyField = modal.querySelector('.keyfield-value')?.innerText.trim();
- }
- // Sort and figure out if we got our key or if we were scammed
- console.log(`🔑 Extracted key: "${keyField}"`);
- if (keyField?.includes("Keys are temporarily exhausted")) {
- gotScammed.push(name);
- console.log(`❌ Got scammed for: ${name}`);
- keyField = "Exhausted";
- } else if (keyField) {
- keys.push(`${name} :: ${keyField}`);
- } else {
- console.log(`⚠️ No key found for: ${name}`);
- }
- master.push({'game': name, 'key': keyField});
- // Close modal
- let closeButton = modal.querySelector('.js-close-modal');
- if (closeButton) {
- closeButton.click();
- console.log(`Closing modal for: ${name}`);
- } else {
- console.log(`⚠️ Close button not found for: ${name}`);
- }
- // Wait for modal to close before resolving
- let closeCheck = setInterval(() => {
- if (!document.querySelector('.humblemodal-modal--open')) {
- clearInterval(closeCheck);
- console.log(`✅ Modal closed for: ${name}`);
- resolve();
- }
- }, 500);
- }
- if (attempts++ > 50) { // Give up after ~5 seconds
- clearInterval(checkModal);
- console.log(`⚠️ Modal did not appear for: ${name}, skipping...`);
- master.push({'game': name, 'key': 'Retry later'});
- resolve();
- }
- }, 500);
- });
- }
- let choices = document.querySelectorAll('.content-choice');
- for (let i = 0; i < choices.length; i++) {
- await openChoice(choices[i]); // Wait for each choice to complete
- await new Promise((r) => setTimeout(r, 1000)); // Small delay
- }
- console.log(' - - - - - - - - OUTPUT - - - - - - - ');
- console.log("✅ Keys found:", keys);
- console.log("❌ Got scammed:", gotScammed);
- // Once all choices are processed, create & download CSV
- const csvContent = convertToCSV(master);
- const pathParts = window.location.pathname.split("/"); // Get parts of the URL path
- const csv_name = pathParts[pathParts.length - 1]; // Last part is "april-2024"
- downloadCSV("humblemonthly" + csv_name + ".csv", csvContent);
- }
- // Add the button when the page loads
- window.addEventListener('load', createButton);
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement