Created
September 28, 2021 12:59
-
-
Save JordanAdams/2dc2a729ca868fee6a902244e1a1b673 to your computer and use it in GitHub Desktop.
UserScript - Humble Bundle All Keys
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
// ==UserScript== | |
// @name Humble Bundle All Keys | |
// @namespace https://github.com/jordanadams | |
// @version 0.1 | |
// @description Snags all your keys on Humble | |
// @author Jordan Adams | |
// @match https://www.humblebundle.com/home/keys | |
// @grant none | |
// ==/UserScript== | |
const findPrevPageButton = () => { | |
const icon = document.querySelector('.jump-to-page .hb-chevron-left'); | |
if (!icon) { | |
return null; | |
} | |
return icon.parentElement; | |
} | |
const findNextPageButton = () => { | |
const icon = document.querySelector('.jump-to-page .hb-chevron-right'); | |
if (!icon) { | |
return null; | |
} | |
return icon.parentElement; | |
} | |
const goToFirstPage = () => { | |
(function tick () { | |
const prev = findPrevPageButton(); | |
if (prev) { | |
prev.click(); | |
tick(); | |
} | |
})(); | |
} | |
const fetchKeys = () => { | |
const rows = Array.from(document.querySelectorAll('.unredeemed-keys-table tr')); | |
return rows | |
.filter(row => row.querySelector('.hb-steam')) | |
.map(row => { | |
const name = row.querySelector('.game-name h4').innerText; | |
const key = row.querySelector('.key-redeemer .keyfield-value').innerText; | |
return { name, key } | |
}) | |
} | |
const getAllKeys = () => { | |
goToFirstPage(); | |
let keys = []; | |
(function tick () { | |
keys = [...keys, ...fetchKeys()] | |
const nextPage = findNextPageButton(); | |
if (nextPage) { | |
nextPage.click(); | |
tick(); | |
} | |
})(); | |
console.log(keys) | |
return keys; | |
} | |
(function() { | |
'use strict'; | |
const mainWrapper = document.querySelector('.inner-main-wrapper'); | |
const container = document.createElement('div'); | |
const outputTable = document.createElement('table'); | |
const output = document.createElement('tbody'); | |
outputTable.append(output); | |
const button = document.createElement('button'); | |
button.innerText = 'Get All Keys'; | |
button.addEventListener('click', () => { | |
getAllKeys().forEach(x => { | |
const row = document.createElement('tr'); | |
row.innerHTML = `<td>${x.name}</td><td>${x.key}</td>`; | |
output.append(row); | |
}); | |
}); | |
container.append(button); | |
container.append(output); | |
mainWrapper.prepend(container); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment