Last active
July 6, 2021 15:45
-
-
Save jabczyk/39df4c3576b572f9de6d47bb3b60365e to your computer and use it in GitHub Desktop.
Consumes all knick-knacks in Your steam inventory
This file contains hidden or 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
/** | |
* 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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for your work