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.

'); - $('#SynchDiv').append('

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('O C'); + $("#inventorylist tr:first").append('P B'); + $("#inventorylist tr:first").append('C R'); + + var MyRows = $('#inventorylist').find('tbody').find('tr'); + + for (var i = 0; i < MyRows.length; i++) + { + var appID = $(MyRows[i]).find('td:eq(1)').attr('id'); + appID = appID.substring(6); + var SetSize = $(MyRows[i]).find('td:eq(3)').text(); + SetSize = SetSize.substring(SetSize.length - 9, SetSize.length - 7); + if (CardAmounts[appID] === undefined) CardAmounts[appID] = 0; // If no cards in Inventory this throws up a problem. + var BadgesAbleToCreate = Math.floor(CardAmounts[appID]/SetSize); + var RemainingCards = CardAmounts[appID] - (BadgesAbleToCreate * SetSize); + $(MyRows[i]).append(''+CardAmounts[appID]+''); + $(MyRows[i]).append(''+BadgesAbleToCreate+''); + $(MyRows[i]).append(''+RemainingCards+''); + } + + $("#inventorylist").trigger("destroy"); + $("#inventorylist").tablesorter( + { + sortList: [[4,1]], + widgets: ["zebra"] + }); + + console.log("Finished Table Additions!"); + var SCEids = $('.even, .odd').map(function() // Filling array with all games in SCE Watchlist. { return this.id.substring(6); }).get(); - $('#SynchDiv').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 + '

'); + $('#SynchDiv').append('


Games in Watchlist but not in Steam Inventory: ' + InSCENotInSteamInv.length + '

'); if (InSCENotInSteamInv.length > 0) { @@ -198,3 +246,10 @@ function AddRemoveFromSCEWatchlist(add_or_remove, appIDs) $('#SynchDiv').append('

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]); +}