diff --git a/Steam_Card_Exchange_Watchlist_Synchronizer.user.js b/Steam_Card_Exchange_Watchlist_Synchronizer.user.js index cf775a9..79ee500 100644 --- a/Steam_Card_Exchange_Watchlist_Synchronizer.user.js +++ b/Steam_Card_Exchange_Watchlist_Synchronizer.user.js @@ -1,17 +1,16 @@ // ==UserScript== // @name Steam Card Exchange Watchlist Synchronizer // @namespace Steam Card Exchange Watchlist Synchronizer -// @author DB +// @author Laurvin // @description Synchs with actual Steam Inventory -// @version 0.3 +// @version 0.5 // @icon http://i.imgur.com/XYzKXzK.png // @downloadURL https://github.com/Laurvin/Steam-Card-Exchange-Watchlist-Synchronizer/raw/master/Steam_Card_Exchange_Watchlist_Synchronizer.user.js -// @updateURL https://github.com/Laurvin/Steam-Card-Exchange-Watchlist-Synchronizer/raw/master/Steam_Card_Exchange_Watchlist_Synchronizer.user.js +// @updateURL https://github.com/Laurvin/Steam-Card-Exchange-Watchlist-Synchronizer/raw/master/Steam_Card_Exchange_Watchlist_Synchronizer.user.js // @include http://www.steamcardexchange.net/index.php?userlist // @include https://www.steamcardexchange.net/index.php?userlist // @grant GM_xmlhttpRequest -// @require http://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js -// @require https://raw.githubusercontent.com/Sighery/SRQ/master/SerialRequestsQueue.js +// @require https://github.com/Sighery/SRQ/releases/download/v0.1.0/SerialRequestsQueue-0.1.0.js // @run-at document-idle // ==/UserScript== @@ -19,6 +18,10 @@ var queue = new SRQ(); var Steamids = []; +var InventoryAmounts = {}; + +var CardAmounts = {}; + this.$ = this.jQuery = jQuery.noConflict(true); $(document).ready(function () { @@ -26,6 +29,7 @@ $(document).ready(function () }); function init() { + addHTMLElements(); } function addHTMLElements() @@ -36,9 +40,8 @@ function addHTMLElements() function SynchLists() { $('#inventory-content').prepend('
Synching, please be patient and keep in mind you need to be logged into Steam on this browser for this to work.
Loading Steam Inventory in 2,000 item chunks.
'); - $('#SynchDiv').append('Still loading...
'); - + $('#SynchDiv').append('Loading Steam Inventory in 2,000 item chunks. Loading from 0 onwards. There will be a few seconds pause at the end.'); + $('#SynchDiv').append('
Number of games with cards in Steam Inventory: 0
'); queue.add_to_queue( { "link": "http://steamcommunity.com/my/inventory/json/753/6", @@ -58,22 +61,36 @@ function inv_request_callback(requested_obj) { { var InvJSON = JSON.parse(requested_obj.response.responseText); + $.each(InvJSON.rgInventory, function (index, item) + { + if (hasOwnProperty(InventoryAmounts, item.classid+"_"+item.instanceid)) + { + InventoryAmounts[item.classid+"_"+item.instanceid] += 1; + } + else + { + InventoryAmounts[item.classid+"_"+item.instanceid] = 1; + } + }); + $.each(InvJSON.rgDescriptions, function (index, item) - { + { if (item.type.includes("Trading Card")) { if(Steamids.includes(item.market_fee_app)) { - // If it's in the array already, do nothing; we need each appID only once. + CardAmounts[item.market_fee_app] += InventoryAmounts[item.classid+"_"+item.instanceid]; } else { Steamids.push(item.market_fee_app); + CardAmounts[item.market_fee_app] = InventoryAmounts[item.classid+"_"+item.instanceid]; + // CardAmounts[item.market_fee_app] = 1; } } }); - $('#SteamInvTotals').text('Number of games with cards in Steam Inventory: ' + Steamids.length); + $('#SteamInvTotals').text(Steamids.length); if (InvJSON.more === true) { @@ -84,6 +101,7 @@ function inv_request_callback(requested_obj) { "timeout": 6000 }); + $('#SteamInvLoading').text('Loading from '+InvJSON.more_start+' onwards.'); InvJSON = null; queue.start(inv_request_callback); } @@ -92,17 +110,47 @@ function inv_request_callback(requested_obj) { InvJSON = null; $('#SteamInvLoading').text('All loaded!'); + console.log("Starting Table Additions!"); + $("#inventorylist tr:first").append('Number of games in SCE Watchlist: ' + SCEids.length + '
'); + $('#SynchDiv').append('Number of games in SCE Watchlist: ' + SCEids.length + '
'); var SCEids2 = new Set(SCEids); var InSteamInvNotInSCE = [...new Set([...Steamids].filter(x => !SCEids2.has(x)))]; - $('#SynchDiv').append('
Games in Steam Inventory but not in Watchlist: ' + InSteamInvNotInSCE.length + '
');
+ $('#SynchDiv').append('
Games in Steam Inventory but not in Watchlist: ' + InSteamInvNotInSCE.length + '
');
if (InSteamInvNotInSCE.length > 0)
{
@@ -116,7 +164,7 @@ function inv_request_callback(requested_obj) {
var Steamids2 = new Set(Steamids);
var InSCENotInSteamInv = [...new Set([...SCEids].filter(x => !Steamids2.has(x)))];
- $('#SynchDiv').append('
Games in Watchlist but not in Steam Inventory: ' + InSCENotInSteamInv.length + '
Games in Watchlist but not in Steam Inventory: ' + InSCENotInSteamInv.length + '
Processed all of ' + add_or_remove + ' list.
'); } } + +function hasOwnProperty(obj, prop) +{ + var proto = obj.__proto__ || obj.constructor.prototype; + return (prop in obj) && + (!(prop in proto) || proto[prop] !== obj[prop]); +}