Skip to content

Instantly share code, notes, and snippets.

@jabczyk
Last active July 6, 2021 15:45
Show Gist options
  • Save jabczyk/39df4c3576b572f9de6d47bb3b60365e to your computer and use it in GitHub Desktop.
Save jabczyk/39df4c3576b572f9de6d47bb3b60365e to your computer and use it in GitHub Desktop.
Consumes all knick-knacks in Your steam inventory
/**
* Knick Knack Steam Bot
*
* Consumes all knick-knacks in Your steam inventory
*
* - Go to https://steamcommunity.com/my/inventory#753_6
* - Wait for inventory to load
* - Press F12
* - Paste the code in console tab
*
* (C) 2018
* https://steamcommunity.com/id/TolekCacek
* https://steamcommunity.com/tradeoffer/new/?partner=182084797&token=CKjX42cj
*/
/* global document, ShowTagFilters
g_strProfileURL, g_sessionID, $J,
ShowBlockingWaitDialog, ShowAlertDialog */
const NAME = 'Knick Knack Bot'
const FOOTER = '<br><small>by /id/TolekCacek</small>'
const DELAY = 0
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms))
function loadAllKnickKnacks() {
ShowTagFilters()
document.querySelector('input[tag_name="item_class_6"]').click()
const itemLinks = document.getElementsByClassName("inventory_item_link")
let ids = []
for(let i in itemLinks) {
const link = itemLinks[i]
if(typeof link !== 'object')
break
if(link.parentNode.parentNode.style.display === 'none')
continue
const id = link.href.split('_')[2]
ids.push(id)
}
return ids
}
async function consumeKnickKnack(assetid) {
const url = g_strProfileURL + '/ajaxactivateconsumable/'
const params = {
sessionid: g_sessionID,
appid: 991980,
item_type: 127,
assetid,
actionparams: JSON.stringify({
"action": "consume_winter2018",
"message": "#Badge_Winter2018_ConsumeLipBalm"
})
}
try {
await $J.post(url, params)
return true
} catch (err) {
return false
}
}
function showConsumingModal(total, consumed, errors) {
const content = `
Consuming knick-knack ${consumed}/${total} (Errors: ${errors})
${FOOTER}`
ShowBlockingWaitDialog(NAME, content)
}
function showEndModal(total, consumed, errors) {
const content = `
Consumed ${consumed}/${total} knick-knacks (Errors: ${errors})
${FOOTER}`
ShowAlertDialog(NAME, content)
}
async function consumeAll() {
const ids = loadAllKnickKnacks()
let consumed = 0
let errors = 0
for(let i in ids) {
const success = await consumeKnickKnack(ids[i])
if(success)
consumed++
else
errors++
showConsumingModal(ids.length, consumed, errors)
await sleep(DELAY)
}
showEndModal(ids.length, consumed, errors)
}
consumeAll()
@gggauravgandhi
Copy link

Works well, sometimes throws the error. Thanks

@Rosenstein
Copy link

Throws an error in console:
POST https://steamcommunity.com/id/******/ajaxactivateconsumable/ 400 (Bad Request)

@Pandiora
Copy link

Pandiora commented Jan 8, 2019

@Rosenstein: It throws an error because of this: item_type: 127, (there are much more item-types) The error could happen anyway for different reasons -> like to fast requests in a row, also might be known as spam. Sometimes success: 16 and a 400 HTTP-Error gets thrown, but if we try it again, the item is consumable. So no idea why this error occurs, some special people would call it "Steam Fuckup". You can find a different fork out there that actually works (better).

@m-alice
Copy link

m-alice commented Feb 3, 2019

Thanks for your work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment