Last active
December 29, 2020 05:23
-
-
Save jaks97/68ed8ede8d493f369918c0956bbdb5ab to your computer and use it in GitHub Desktop.
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 Steam Mass Sell | |
// @namespace https://gist.github.com/jaks97/68ed8ede8d493f369918c0956bbdb5ab | |
// @version 0.1 | |
// @description Mass sell items on Steam using its own endpoint. | |
// @require https://code.jquery.com/jquery-3.3.1.min.js | |
// @require https://code.jquery.com/ui/1.12.1/jquery-ui.min.js | |
// @author jaks | |
// @match *://steamcommunity.com/*/inventory* | |
// @grant none | |
// ==/UserScript=={ | |
this.$ = this.jQuery = jQuery.noConflict(true); | |
(function () { | |
console.log($("#inventory_logos")); | |
$("#inventory_logos").append(`<a class="btn_green_white_innerfade btn_medium_wide" id="sell"><span>Pick items to sell</span></a>`); | |
$("#sell").click(selectItems); | |
$("head").append(`<style>.ui-selected{outline: 2px solid #00adee;} | |
.ui-selected .item{ background: #4e4e4e;} | |
</style>`); | |
})(); | |
var selectedItems = []; | |
function selectItems() { | |
$('#inventories').selectable({ | |
filter: ".itemHolder", | |
selected: function (e, ui) { | |
if (selectedItems.indexOf(ui.selected) === -1) // We ensure that items do not get duplicated | |
selectedItems.push(ui.selected); | |
$("#sell").html(`<span>Sell ${selectedItems.length} items</span>`); | |
}, | |
unselected: function (e, ui) { | |
selectedItems.splice(selectedItems.indexOf(ui.unselected), 1); | |
$("#sell").html(`<span>Sell ${selectedItems.length} items</span>`); | |
} | |
}); | |
$("#sell").html(`<span>Sell</span>`).click(sell); | |
} | |
function sell() { | |
if(selectedItems.length === 0) | |
return; | |
let items = []; | |
for (let i = 0; i < selectedItems.length; i++) { | |
if (items.some(item => item.market_hash_name == selectedItems[i].rgItem.description.market_hash_name)) { // We ensure that items do not get duplicated | |
items.filter(item => item.market_hash_name == selectedItems[i].rgItem.description.market_hash_name)[0].qty++; | |
} else { | |
items.push({ | |
market_hash_name: selectedItems[i].rgItem.description.market_hash_name, | |
qty: 1 | |
}); | |
} | |
} | |
let uri = "https://steamcommunity.com/market/multisell?appid=753&contextid=6"; | |
for (let i = 0; i < items.length; i++) { | |
uri += `&items[]=${encodeURIComponent(items[i].market_hash_name)}&qty[]=${items[i].qty}`; | |
} | |
console.log(items); | |
selectedItems = []; | |
window.open(uri, '_blank'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment