Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save husjon/2851d9c2cb0fd4f90c9949eb481b4e29 to your computer and use it in GitHub Desktop.
Save husjon/2851d9c2cb0fd4f90c9949eb481b4e29 to your computer and use it in GitHub Desktop.
Get list of keys from Humble Bundle Library page
/*
* Run on https://www.humblebundle.com/home/library
* Global variable `gamekeys` is available on the Library page
*
*/
Promise.all(gamekeys.map(key => {
return new Promise((resolve, reject) => {
$.ajax({
url: `https://www.humblebundle.com/api/v1/order/${key}?all_tpkds=true`
}).done(data => resolve(data))
})
}))
.then(results => {
let keys = []
results.forEach(result => {
keys = keys.concat(result.tpkd_dict.all_tpks.map(tpk => {
return {
name: tpk.human_name,
key_type: tpk.key_type_human_name,
redeemed: tpk.redeemed_key_val
}
}))
})
return keys
})
.then(keys => keys.sort((a ,b) => (a.name < b.name) ? -1 : 1))
.then(keys => {
keys.forEach(key => {
console.log(`"${key.name}", ${key.key_type}, ${key.redeemed}`)
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment