Last active
January 28, 2024 07:07
-
-
Save saiki-k/44ef442c9690e8d0862926604dd50731 to your computer and use it in GitHub Desktop.
Humble Keys' Extractor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const excludedTitles = ['A title I already own', 'Got this other title too']; | |
const { includedKeysCombined, csv } = run(excludedTitles); | |
copy(includedKeysCombined); | |
function scrapeTitlesAndKeys() { | |
const result = []; | |
// Get all elements with classes "key-redeemer" (Normal key pages), and "multiselect-nonimage-content" (Choice key pages) | |
const elements = document.querySelectorAll('.key-redeemer, .multiselect-nonimage-content'); | |
// Iterate through each element and extract title and key | |
elements.forEach((element) => { | |
const keyElement = element.querySelector('.keyfield-value'); | |
let titleElement; | |
// Check if the element has class "key-redeemer" | |
if (element.classList.contains('key-redeemer')) { | |
titleElement = element.querySelector('.heading-text h4'); | |
} | |
// Check if the element has class "multiselect-nonimage-content" | |
else if (element.classList.contains('multiselect-nonimage-content')) { | |
titleElement = element.querySelector('.multiselect-title'); | |
} | |
// Check if both title and key elements exist | |
if (titleElement && keyElement) { | |
const title = titleElement.textContent.trim(); | |
const key = keyElement.textContent.trim(); | |
// Push an object with title and key into the result array | |
result.push({ title, key }); | |
} | |
}); | |
return result; | |
} | |
function filterTitlesAndKeys(titlesAndKeys, excludedTitles = []) { | |
// Convert excludedTitles to lowercase for case-insensitive comparison | |
const lowercasedExcludedTitles = excludedTitles.map((title) => title.trim().toLowerCase()); | |
// Initialize arrays to store included and excluded items | |
const includedItems = []; | |
const excludedItems = []; | |
// Iterate through titles and keys | |
titlesAndKeys.forEach((item) => { | |
const lowercaseTitle = item.title.toLowerCase(); | |
// Check if the title should be excluded | |
if (lowercasedExcludedTitles.includes(lowercaseTitle)) { | |
excludedItems.push(item); | |
} else { | |
includedItems.push(item); | |
} | |
}); | |
return { includedItems, excludedItems }; | |
} | |
function run(excludedTitles = [], sectionSeparator = '***\n\n\n\n') { | |
// Run scrapeTitlesAndKeys to get the titles and keys | |
const allItems = scrapeTitlesAndKeys(); | |
// Run filterTitlesAndKeys to get the included and excluded items | |
const { includedItems, excludedItems } = filterTitlesAndKeys(allItems, excludedTitles); | |
// Create a CSV string from an array of objects with title and key | |
const createCSV = (titlesAndKeys) => `Title,Key\n${titlesAndKeys.map((item) => Object.values(item)).join('\n')}`; | |
const data = { | |
allItems, | |
includedItems, | |
excludedItems, | |
csv: { | |
allItems: createCSV(allItems), | |
includedItems: createCSV(includedItems), | |
excludedItems: createCSV(excludedItems), | |
}, | |
includedKeysCombined: includedItems.map((item) => item.key).join('\n'), | |
}; | |
// Print all the titles, and their keys in a table | |
console.log(`${data.allItems.length} keys have been scraped from the page.`); | |
console.table(data.allItems); | |
// Print the CSV of all the titles and keys | |
console.log(`${sectionSeparator}The CSV of all the titles and keys:`); | |
console.log(data.csv.allItems); | |
if (data.excludedItems.length >= 1) { | |
console.log(`${sectionSeparator}Following keys were excluded:`); | |
console.log(data.excludedItems.map((item) => `${item.title}\n${item.key}\n`).join('\n')); | |
} | |
if (data.includedItems.length >= 1) { | |
console.log(`${sectionSeparator}Following included titles' keys form the result string:`); | |
console.log(data.includedItems.map((item) => item.title).join('\n')); | |
console.log('The keys for the above included games in order are:'); | |
console.log(data.includedKeysCombined); | |
} | |
return data; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey fellow Humble Bundlers! ๐ฎ๐
This console script is meant for Humble Bundle key pages. It gathers all keys from a Humble Bundle key page, excluding the titles you specify, and compiles them into a single string that is copied to your clipboard. This makes redeeming a bunch of keys a breeze, especially if you have Augmented Steam installed (because who doesn't?).
With the Augmented Steam browser extension installed, after running this script, you can effortlessly redeem all your keys at once on the Steam key activator page (https://store.steampowered.com/account/registerkey) by pasting the clipboard content into the provided text area.
The
copy
function (line 5) (for copying content to clipboard) only works on Chromium based browsers, AFAIK!How to use
copy
function, on line 5).csv
extension (saykeys.csv
), suitable for opening with software like Excel for further organization.Behind the scenes
.key-redeemer
) and choice (.multiselect-nonimage-content
) Humble Bundle key pages.Feel free to tweak and modify the script based on your needs. Happy key redeeming! ๐๐