Forked from Maximilian-L/community-market-wishlist-script.user.js
Last active
September 16, 2015 17:35
-
-
Save korden32/8610c76cadeadb550fc7 to your computer and use it in GitHub Desktop.
Allows you to add Steam Commuity Market items to a wishlist tab to keep track of items that you might want to purchase at a later point of time.
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 Community Market Wishlist | |
// @description Allows you to add Steam Commuity Market items to a wishlist tab to keep track of items that you might want to purchase at a later point of time. | |
// @match *steamcommunity.com/market* | |
// @grant none | |
// ==/UserScript== | |
//Adjust the following variable's value to your currency's code (see list below) | |
var marketCurrency = 3; // 1 = $; 2 = £; 3 = €; 5 = pуб; 7 = R$; 8 = ¥; 9 = kr; 10 = Rp; 11 = RM; 12 = P; 13 = S$; 14 = ฿; 17 = TL; 19 = Mex$; 20 = CDN$; 22 = NZ$ | |
//Adjust the following variable's value to your currency's sign (see list above) | |
var currencySign = '€'; | |
//Adjust the following variable's value to change the speed of animations. | |
var animationSpeed = 600; //Animation speed in ms. Setting this to zero will disable animations. (Default: 600) | |
$J(document).ready(function(){ | |
if($J(location).attr('href') == 'http://steamcommunity.com/market/' || $J(location).attr('href') == 'https://steamcommunity.com/market/' || $J(location).attr('href') == 'http://steamcommunity.com/market' || $J(location).attr('href') == 'https://steamcommunity.com/market' || $J(location).attr('href') == 'http://steamcommunity.com/market/#myhistory' || $J(location).attr('href') == 'https://steamcommunity.com/market/#myhistory'){ | |
var itemId = 0; | |
if(localStorage.getItem('marketWishlist') !== null){ | |
jQuery.each(jQuery.parseJSON(localStorage.getItem('marketWishlist')), function(){ | |
itemId++; | |
}); | |
} | |
bFirstCheck = true; | |
bIsClickFromListings = true; | |
$J('.market_tab_well_tabs:first').append('<a id="wishlistButton" class="market_tab_well_tab market_tab_well_tab_inactive">' + | |
'<span class="market_tab_well_tab_left"></span>' + | |
'<span class="market_tab_well_tab_contents">Wishlisted Items<span id="entryCounter_tab" class="my_market_header_count"> (' + itemId + ')</span></span>' + | |
'<span class="market_tab_well_tab_right"></span>' + | |
'<span class="market_tab_well_tab_preload"></span>' + | |
'</a>'); | |
$J('#wishlistButton').click(showWishlist); | |
$J('#tabMyMarketHistory') | |
.off() | |
.click(showHistory); | |
}else if($J(location).attr('href').indexOf('steamcommunity.com/market/listings/') > -1){ | |
var alreadyWishlisted = false; | |
var marketWishlistJson = jQuery.parseJSON(localStorage.getItem('marketWishlist')); | |
var itemURL = $J(location).attr('href'); | |
try{ | |
jQuery.each(jQuery.parseJSON(localStorage.getItem('marketWishlist')), function(){ | |
if (itemURL.indexOf($(this).itemURL) != -1){ | |
alreadyWishlisted = true; | |
return false; | |
} | |
}); | |
}catch(e){} | |
$J('#largeiteminfo_item_name').after('<button id="addToWishlistBtn" class="btn_green_white_innerfade btn_medium market_commodity_buy_button">+ Add To Wishlist</button>\ | |
<button id="removeFromWishlistBtn" class="btn_green_white_innerfade btn_medium market_commodity_buy_button">- Remove From Wishlist</button>'); | |
$J('#addToWishlistBtn').click(addItemToWishlist); | |
$J('#removeFromWishlistBtn').click(removeItemFromWishlist); | |
$J(alreadyWishlisted ? '#addToWishlistBtn' : '#removeFromWishlistBtn').hide(); | |
} | |
if($J(location).attr('href').indexOf('#myhistory') > -1){ | |
$J('#wishlistButton') | |
.off('click') | |
.on('click', function(){$J('#tabMyMarketHistory').removeClass('market_tab_well_tab_active');$J('#tabMyMarketHistory').addClass('market_tab_well_tab_inactive'); showWishlist();}); | |
} | |
animationSpeedBackup = animationSpeed; | |
animationSpeed = 0; | |
$J('#' + localStorage.getItem('marketWishlistLastPage')).click(); | |
animationSpeed = animationSpeedBackup; | |
}); | |
function showWishlist(){ | |
if(bFirstCheck === false){ | |
showWishlist_noLoad(); | |
}else{ | |
$J('#myListings').after('<div id="wishlistedItemsContent">' + | |
'<br/>' + | |
'<h3 class="my_market_header">' + | |
'<span class="my_market_header_active"> Item Wishlist</span><span class="my_market_header_count" id="itemWishlistCounter"> (0)</span>' + | |
'</h3>' + | |
'<div id="wishlistBox" class="market_listing_table_message" style="margin: 1em;"></div>' + | |
'</div>'); | |
$J('#wishlistBox').before('<div class="search_controls" align="right" style="margin-top: -2em; margin-right: 1em;">' + | |
'<div class="gray_bevel for_text_input" style="margin-left: 1em;"><input size="20" placeholder="Maximum price" value="" id="filterSettings"></div>' + | |
' <button class="btn_green_white_innerfade btn_medium" id="doFilterBtn"><span>Filter</span></button>' + | |
'</form></div>'); | |
$J('#doFilterBtn').click(filterListings); | |
var itemId = 0; | |
try{ | |
jQuery.each(jQuery.parseJSON(localStorage.getItem('marketWishlist')), function(){ | |
itemId++; | |
var itemPrice = "Fetching..."; | |
var itemName = $(this).itemName; | |
var itemURL = $(this).itemURL; | |
var imgUrl = $(this).imgUrl; | |
var gameName = $(this).gameName; | |
$J('#wishlistBox').append('<a class="market_listing_row_link" href="' + itemURL + '" id="resultlink_' + itemId + '">\ | |
<div class="market_listing_row market_recent_listing_row market_listing_searchresult wishlistItemContainer" id="' + itemId + '">\ | |
<img id="result_' + itemId + '_image" src="http://steamcommunity-a.akamaihd.net/economy/image/' + imgUrl + '/62fx62f" style="border-color: #D2D2D2;" class="market_listing_item_img" alt="">\ | |
<div class="market_listing_right_cell priceDiv">\ | |
<span class="market_table_value">\ | |
Starting at:<br>\ | |
<span style="color:white" id="itemPriceSpan_' + itemId + '">' + itemPrice + '</span>\ | |
</span>\ | |
</div>\ | |
<div class="market_listing_item_name_block">\ | |
<span class="market_listing_item_name" style="color: #D2D2D2;" id="itemName' + itemId +'" >' + itemName + '</span>\ | |
<br>\ | |
<span class="market_listing_game_name">' + gameName + '</span>\ | |
</div>\ | |
<a id="removeEntry' + itemId + '" class="item_market_action_button removeEntryButton">\ | |
<span class="item_market_action_button_contents">Remove</span>\ | |
</a>\ | |
</div>\ | |
</a>'); | |
$J('#removeEntry' + itemId).click(function(){removeEntry($J(this).parent().attr("id"));}); | |
var jsonUrl = '//steamcommunity.com/market/priceoverview/?currency=' + marketCurrency + '&appid=' + itemURL.split('/')[5] + '&market_hash_name=' + itemURL.split('/')[6]; | |
getItemPrice(jsonUrl, itemId); | |
}); | |
}catch(e){} | |
if(itemId === 0){ | |
$J('#wishlistBox').text('You don\'t currently have any items wishlisted.'); | |
}else{ | |
$J('#wishlistBox').prepend('<div class="market_listing_table_header">' + | |
'<span class="market_listing_right_cell market_listing_my_price market_sortable_column" id="priceTable">  PRICE<span class="market_sort_arrow" id="sortTypeIndicator" style=""></span></span>' + | |
'<span><span class="market_listing_header_namespacer"></span>NAME</span>' + | |
'</div>'); | |
$J('#itemWishlistCounter').html(' (' + itemId + ') <button id="clearWishlist">Clear All</button>'); | |
$J('#priceTable').click(sortListings); | |
$J('#clearWishlist').click(clearWishlist); | |
$J('button').css('color', 'black'); | |
} | |
$J('.priceDiv').css({'position' : 'relative', 'width' : '90px', 'padding-top' : '1.75em', 'font-size' : '85.7%'}); | |
$J('#wishlistedItemsContent') | |
.hide() | |
.slideDown(animationSpeed); | |
$J('#sideBar, #sellListings, #tabContentsMyMarketHistory, #tabContentsMyListings, #myListings').slideUp(animationSpeed); | |
$J('img[src="//steamcommunity-a.akamaihd.net/public/images/login/throbber.gif"]').remove(); | |
$J('#wishlistButton') | |
.off('click') | |
.removeClass('market_tab_well_tab_inactive') | |
.addClass('market_tab_well_tab_active'); | |
$J('#tabMyListings') | |
.off('click') | |
.on('click', function(){ | |
$J('#wishlistedItemsContent').slideUp(animationSpeed, showListings); | |
}) | |
.removeClass('market_tab_well_tab_active') | |
.addClass('market_tab_well_tab_inactive'); | |
$J('#tabMyMarketHistory') | |
.off('click') | |
.click(showHistory) | |
.removeClass('market_tab_well_tab_active') | |
.addClass('market_tab_well_tab_inactive'); | |
bFirstCheck = false; | |
bIsClickFromListings = false; | |
} | |
} | |
function addItemToWishlist(){ | |
var newdata = {}; | |
var itemURL= $J(location).attr('href').split('?filter=')[0]; | |
var name = $J('h1.hover_item_name').text(); | |
var imgSource = $J('.market_listing_largeimage > img').attr('src').match(/image\/(.+)\//)[1]; | |
var gameName = $J('#largeiteminfo_game_name').text(); | |
newdata[name] = {"itemName" : name, "imgUrl" : imgSource, "itemURL" : itemURL, "gameName" : gameName}; | |
var oldJson = JSON.parse(localStorage.getItem('marketWishlist')); | |
localStorage.setItem('marketWishlist', JSON.stringify(oldJson ? $J.extend(true, oldJson, newdata) : newdata)); | |
$J('#addToWishlistBtn').hide(); | |
$J('#removeFromWishlistBtn').show(); | |
} | |
function clearWishlist(){ | |
ShowConfirmDialog('Clear All Listings', 'Are you sure that you want to delete all items from your wishlist?\nThis action cannot be undone!').done(function(){ | |
localStorage.removeItem('marketWishlist'); | |
$J('#itemWishlistCounter').html(' (0) <button id="clearWishlist">Clear All</button>'); | |
$J('#clearWishlist').click(clearWishlist); | |
$J('#wishlistBox').slideUp(animationSpeed, function(){ | |
$J('#wishlistBox') | |
.text('You don\'t currently have any items wishlisted.') | |
.slideDown(animationSpeed); | |
$J('#clearWishlist').slideUp(animationSpeed); | |
}); | |
$J('#entryCounter_tab').html(' (0)'); | |
}); | |
} | |
function removeItemFromWishlist(){ | |
var name = $J('h1.hover_item_name').text(); | |
var wishlistJson = jQuery.parseJSON(localStorage.getItem('marketWishlist')); | |
delete wishlistJson[name]; | |
localStorage.setItem('marketWishlist', JSON.stringify(wishlistJson)); | |
$J('#addToWishlistBtn').show(); | |
$J('#removeFromWishlistBtn').hide(); | |
} | |
function getItemPrice(url, itemId){ | |
$J.getJSON(url, function(data) { | |
$J('#itemPriceSpan_' + itemId).html((data.lowest_price !== undefined) ? data.lowest_price : "No listings"); | |
}); | |
} | |
function removeEntry(itemId){ | |
var itemName = $J('#itemName' + itemId).text(); | |
var wishlistJson = jQuery.parseJSON(localStorage.getItem('marketWishlist')); | |
delete wishlistJson[itemName]; | |
localStorage.setItem('marketWishlist', JSON.stringify(wishlistJson)); | |
$J('#' + itemId).slideUp(animationSpeed, updateCounter); | |
} | |
function updateCounter(){ | |
var itemId = 0; | |
jQuery.each(jQuery.parseJSON(localStorage.getItem('marketWishlist')), function(){ | |
itemId++; | |
}); | |
if(itemId === 0){ | |
$J('#wishlistBox').slideUp(animationSpeed, function(){ | |
$J('#wishlistBox') | |
.text('You don\'t currently have any items wishlisted.') | |
.slideDown(animationSpeed); | |
$J('#clearWishlist').slideUp(animationSpeed, function(){ | |
$J('#itemWishlistCounter').html(' (0)'); | |
$J('#entryCounter_tab').html(' (0)'); | |
}); | |
}); | |
}else{ | |
$J('#itemWishlistCounter').html(' (' + itemId + ') <button id="clearWishlist">Clear All</button>'); | |
$J('#entryCounter_tab').html(' (' + itemId + ')'); | |
$J('#clearWishlist').click(clearWishlist); | |
$J('button').css('color', 'black'); | |
} | |
} | |
function showWishlist_noLoad(){ | |
$J('#sideBar, #sellListings, #tabContentsMyListings, #myListings, #tabContentsMyMarketHistory').slideUp(animationSpeed); | |
$J('#wishlistedItemsContent').slideDown(animationSpeed); | |
$J('#wishlistButton') | |
.off('click') | |
.removeClass('market_tab_well_tab_inactive') | |
.addClass('market_tab_well_tab_active'); | |
$J('#tabMyListings') | |
.off('click') | |
.on('click', function(){ | |
$J('#wishlistedItemsContent').slideUp(animationSpeed, showListings); | |
}) | |
.removeClass('market_tab_well_tab_active') | |
.addClass('market_tab_well_tab_inactive'); | |
$J('#tabMyMarketHistory') | |
.off('click') | |
.click(showHistory) | |
.removeClass('market_tab_well_tab_active') | |
.addClass('market_tab_well_tab_inactive'); | |
bIsClickFromListings = false; | |
} | |
function showHistory(){ | |
if(bIsClickFromListings === true){ | |
$J('#tabContentsMyListings').show(); | |
$J('#tabContentsMyMarketHistory').hide(); | |
$J('#tabContentsMyListings').slideUp(animationSpeed, function(){ | |
$J('#tabContentsMyMarketHistory').slideDown(animationSpeed); | |
}); | |
}else{ | |
$J('#wishlistedItemsContent').slideUp(animationSpeed, function(){ | |
$J("#myListings").show(); | |
$J("#tabContentsMyListings, #tabContentsMyMarketHistory").hide(); | |
$J('#tabContentsMyMarketHistory, #sellListings, #sideBar').slideDown(animationSpeed); | |
}); | |
} | |
$J('#tabMyMarketHistory') | |
.off('click') | |
.removeClass('market_tab_well_tab_inactive') | |
.addClass('market_tab_well_tab_active'); | |
$J('#tabMyListings') | |
.off() | |
.on('click', function(){ | |
$J('#tabContentsMyListings').hide(); | |
$J('#tabContentsMyMarketHistory').show(); | |
$J('#tabContentsMyMarketHistory').slideUp(animationSpeed, showListings); | |
}) | |
.removeClass('market_tab_well_tab_active') | |
.addClass('market_tab_well_tab_inactive'); | |
$J('#wishlistButton') | |
.off('click') | |
.click(showWishlist) | |
.removeClass('market_tab_well_tab_active') | |
.addClass('market_tab_well_tab_inactive'); | |
} | |
function showListings(){ | |
$J('#myListings, #sideBar, #tabContentsMyListings, #sellListings').slideDown(animationSpeed); | |
$J('#tabMyListings') | |
.off('click') | |
.removeClass('market_tab_well_tab_inactive') | |
.addClass('market_tab_well_tab_active'); | |
$J('#wishlistButton') | |
.off('click') | |
.click(showWishlist) | |
.removeClass('market_tab_well_tab_active') | |
.addClass('market_tab_well_tab_inactive'); | |
$J('#tabMyMarketHistory') | |
.off('click') | |
.click(showHistory) | |
.removeClass('market_tab_well_tab_active') | |
.addClass('market_tab_well_tab_inactive'); | |
bIsClickFromListings = true; | |
} | |
$J(window).unload(function(){ | |
localStorage.setItem('marketWishlistLastPage', $J('.market_tab_well_tab_active').attr('id')); | |
}); | |
function sortListings(){ | |
if ($J('#sortTypeIndicator').text() != '▲' && $J('#sortTypeIndicator').text() != '▼'){ | |
$J('#sortTypeIndicator').text('▲'); | |
sortLowToHigh(); | |
} | |
else if($J('#sortTypeIndicator').text() == '▲'){ | |
$J('#sortTypeIndicator').text('▼'); | |
sortHighToLow(); | |
} | |
else if($J('#sortTypeIndicator').text() == '▼'){ | |
$J('#sortTypeIndicator').text('▲'); | |
sortLowToHigh(); | |
} | |
} | |
function sortLowToHigh(){ | |
ShowDialog('Feature not yet available', 'The ability to sort items by their price will be added soon!'); | |
} | |
function sortHighToLow(){ | |
ShowDialog('Feature not yet available', 'The ability to sort items by their price will be added soon!'); | |
} | |
function sortNumber(num1, num2){ | |
return num1 - num2; | |
} | |
function filterListings(){ | |
if ($J('#filterSettings').val() !== ''){ | |
var maxPrice = parseFloat($J('#filterSettings').val().replace(',', '.').replace(currencySign, '')); | |
}else{ | |
$J('.wishlistItemContainer').each(function(index){ | |
$J('#' + (index + 1)).show(); | |
}); | |
return; | |
} | |
$J('.wishlistItemContainer').each(function(index){ | |
$J('#' + (index + 1)).hide(); | |
if(parseFloat($J(this).find('#itemPriceSpan_' + (index + 1)).text()) !== '' && parseFloat($J(this).find('#itemPriceSpan_' + (index + 1)).text().replace(',', '.').replace(currencySign, '')) <= parseFloat(maxPrice)){ | |
$J('#' + (index + 1)).show(); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment