Skip to content

Commit

Permalink
Update Steam_Card_Exchange_Watchlist_Synchronizer.user.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Laurvin authored May 4, 2017
1 parent 6b839cb commit d9fb88c
Showing 1 changed file with 69 additions and 14 deletions.
83 changes: 69 additions & 14 deletions Steam_Card_Exchange_Watchlist_Synchronizer.user.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,35 @@
// ==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==

var queue = new SRQ();

var Steamids = [];

var InventoryAmounts = {};

var CardAmounts = {};

this.$ = this.jQuery = jQuery.noConflict(true);
$(document).ready(function ()
{
init();
});
function init()
{

addHTMLElements();
}
function addHTMLElements()
Expand All @@ -36,9 +40,8 @@ function addHTMLElements()
function SynchLists()
{
$('#inventory-content').prepend('<div class="content-box-normal" style="line-height: 20px;" id="SynchDiv"><p>Synching, please be patient and keep in mind you need to be logged into Steam on this browser for this to work.</p></div>');
$('#SynchDiv').append('<p id="SteamInvTotals">Loading Steam Inventory in 2,000 item chunks.</p>');
$('#SynchDiv').append('<p id="SteamInvLoading">Still loading...</p>');

$('#SynchDiv').append('<p>Loading Steam Inventory in 2,000 item chunks. <span id="SteamInvLoading">Loading from 0 onwards.</span> There will be a few seconds pause at the end.');
$('#SynchDiv').append('<p>Number of games with cards in Steam Inventory: <strong><span id="SteamInvTotals">0</span></strong></p>');
queue.add_to_queue(
{
"link": "http://steamcommunity.com/my/inventory/json/753/6",
Expand All @@ -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)
{
Expand All @@ -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);
}
Expand All @@ -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('<th title="Owned Cards">O C</th>');
$("#inventorylist tr:first").append('<th title="Possible Badges to be created">P B</th>');
$("#inventorylist tr:first").append('<th title="Cards remaining after crafting badges">C R</th>');

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('<td>'+CardAmounts[appID]+'</td>');
$(MyRows[i]).append('<td>'+BadgesAbleToCreate+'</td>');
$(MyRows[i]).append('<td>'+RemainingCards+'</td>');
}

$("#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('<p>Number of games in SCE Watchlist: ' + SCEids.length + '</p>');
$('#SynchDiv').append('<p>Number of games in SCE Watchlist: <strong>' + SCEids.length + '</strong></p>');

var SCEids2 = new Set(SCEids);
var InSteamInvNotInSCE = [...new Set([...Steamids].filter(x => !SCEids2.has(x)))];

$('#SynchDiv').append('<p><br />Games in Steam Inventory but not in Watchlist: ' + InSteamInvNotInSCE.length + '<br /</p>');
$('#SynchDiv').append('<p><br />Games in Steam Inventory but not in Watchlist: <strong>' + InSteamInvNotInSCE.length + '</strong><br /</p>');

if (InSteamInvNotInSCE.length > 0)
{
Expand All @@ -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('<p><br />Games in Watchlist but not in Steam Inventory: ' + InSCENotInSteamInv.length + '<br /></p>');
$('#SynchDiv').append('<p><br />Games in Watchlist but not in Steam Inventory: <strong>' + InSCENotInSteamInv.length + '</strong><br /></p>');

if (InSCENotInSteamInv.length > 0)
{
Expand Down Expand Up @@ -198,3 +246,10 @@ function AddRemoveFromSCEWatchlist(add_or_remove, appIDs)
$('#SynchDiv').append('<p>Processed all of <span style="color:' + IDcolor + ';">' + add_or_remove + '</span> list.</p>');
}
}

function hasOwnProperty(obj, prop)
{
var proto = obj.__proto__ || obj.constructor.prototype;
return (prop in obj) &&
(!(prop in proto) || proto[prop] !== obj[prop]);
}

0 comments on commit d9fb88c

Please sign in to comment.