SteamTrades - Have List Filter

Check if you own the games from someone's have list (instant Compare2Steam)

  1. // ==UserScript==
  2. // @name SteamTrades - Have List Filter
  3. // @icon https://cdn.steamtrades.com/img/favicon.ico
  4. // @namespace Revadike
  5. // @version 1.7
  6. // @description Check if you own the games from someone's have list (instant Compare2Steam)
  7. // @support https://www.steamgifts.com/discussion/fN8vR/
  8. // @author Revadike
  9. // @match https://www.steamtrades.com/trade/*
  10. // @grant GM_xmlhttpRequest
  11. // @grant GM_setValue
  12. // @grant GM_getValue
  13. // @grant GM_setClipboard
  14. // @connect revadike.ga
  15. // @require https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js
  16. // ==/UserScript==
  17.  
  18. //If you want to set your/another SteamID64 manually, state it here between brackets. (For example, to check owned games from someone else)
  19. var manual_steamID = "";
  20.  
  21. //Set your steam sync interval in hours. (Set to 0 if you want to force a sync)
  22. var sync_interval = 6;
  23.  
  24. //Set links of game to SteamDB instead of the Steam Store? (SteamDB finds removed games from the steam store and gives better results overall)
  25. var steamdb_instead = true;
  26.  
  27. //Use steam web integration too?
  28. var swi = false;
  29.  
  30. //Do not touch below :)
  31. this.$ = this.jQuery = jQuery.noConflict(true);
  32. $(document).ready(function() {
  33. $(".have").parent().find(".trade_heading").first().html("I have... (<a href='javascript:void(0)' id='filter' style='text-decoration:underline;color:rgb(120,169,71)' title='Check have-list for owned games. \n" +
  34. "Warning: It may become unresponsive for a while.'>Filter</a>)");
  35. $("#filter").click(function() {
  36. $("#filter").removeAttr("style").html("<i class='fa fa-spin fa-circle-o-notch' />");
  37. if (manual_steamID.length == 17) {
  38. syncHandler(manual_steamID);
  39. } else if (GM_getValue("steamID") !== undefined) {
  40. syncHandler(GM_getValue("steamID"));
  41. } else {
  42. if ($(".nav_avatar").length > 0) {
  43. var steamID = $(".nav_avatar").attr("href").split("user/")[1];
  44. if (steamID.length == 17) {
  45. GM_setValue("steamID", steamID);
  46. syncHandler(steamID);
  47. } else {
  48. alert("[Have List Filter] ERROR: Invalid SteamID. Refresh the page to try again, or set manual SteamID");
  49. }
  50. } else {
  51. alert("[Have List Filter] ERROR: Could not fetch SteamID automatically. Refresh the page to try again, or set manual SteamID");
  52. }
  53. }
  54. });
  55. });
  56.  
  57. function syncHandler(steamID) {
  58. var now = Date.now();
  59. var last = GM_getValue("lastsync");
  60. if (last === undefined) {
  61. GM_setValue("lastsync", now);
  62. syncHandler(steamID);
  63. } else if ((now - last) / 3600000 > sync_interval || GM_getValue("ownedSteamGames") === undefined || GM_getValue("wlSteamGames") === undefined || GM_getValue("appids") === undefined) {
  64. GM_xmlhttpRequest({
  65. method: "GET",
  66. url: "https://revadike.ga/steamowned/?steamid=" + steamID + "&include_played_free_games=1&include_appinfo=1",
  67. onload: function(data) {
  68. var json = JSON.parse(data.responseText);
  69. var ownedSteamGames = [];
  70. var appids = {};
  71. json.response.games.forEach(function(game) {
  72. var ownedSteamGame = game.name.toLowerCase().replace(/\:|\-|\–|\\|\/|\™|\®| |\'|\.|\?|\!/g, "");
  73. ownedSteamGames.push(ownedSteamGame);
  74. appids[ownedSteamGame] = game.appid;
  75. });
  76. GM_setValue("ownedSteamGames", ownedSteamGames.join("-"));
  77. GM_xmlhttpRequest({
  78. method: "GET",
  79. url: "https://revadike.ga/steamwishlist/?steamid=" + steamID,
  80. onload: function(data) {
  81. var json = JSON.parse(data.responseText);
  82. var wlSteamGames = [];
  83. for (var appid in json) {
  84. var wlSteamGame = json[appid].name.toLowerCase().replace(/\:|\-|\–|\\|\/|\™|\®| |\'|\.|\?|\!/g, "");
  85. wlSteamGames.push(wlSteamGame);
  86. appids[wlSteamGame] = appid;
  87. }
  88. GM_setValue("wlSteamGames", wlSteamGames.join("-"));
  89. GM_setValue("appids", JSON.stringify(appids));
  90. GM_setValue("lastsync", now);
  91. console.log("[Have List Filter] Synced with steam!");
  92. filterHaveList(ownedSteamGames, wlSteamGames, appids);
  93. }
  94. });
  95. }
  96. });
  97. } else {
  98. var ownedSteamGames = GM_getValue("ownedSteamGames");
  99. var wlSteamGames = GM_getValue("wlSteamGames");
  100. var appids = GM_getValue("appids");
  101. filterHaveList(ownedSteamGames.split("-"), wlSteamGames.split("-"), JSON.parse(appids));
  102. }
  103. }
  104.  
  105. function filterHaveList(ownedSteamGames, wlSteamGames, appids) {
  106. var have;
  107. if (!document.getElementsByClassName("have")[0].getElementsByTagName('table').length) {
  108. have = document.getElementsByClassName("have")[0].innerText.split("\n");
  109. } else {
  110. have = $('.have tr td:first-child').map(function(a,b){return $(b).text(); }).toArray();
  111. }
  112. var have_unowned = "";
  113. var have_unowned_raw = "";
  114. have.forEach(function(g) {
  115. let game = g;
  116. setTimeout(function() {
  117. if (game.length > 1 && game.length < 80) {
  118. // Ignoring everything between and including brackets, and also these symbols: :, -, –, \, /, ™, ®, , ', ., ? and ! (Better suggestions? Please contact me)
  119. var comparable = game.toLowerCase().replace(/( *\[[^)]*\] *)|( *\([^)]*\) *)|\=.*|\:|\-|\–|\\|\/|\™|\®| |\'|\.|\?|\!/g, "");
  120. if ($.inArray(comparable, ownedSteamGames) > -1) { //Game is owned
  121. //console.log (game + ": owned");
  122. $(".have").html($(".have").html().replace(game, "<i class='fa icon-green fa-check-circle' style='color:green;' title='You own this game on steam'></i> <a href=\"https://" +
  123. (steamdb_instead ? "steamdb.info" : "store.steampowered.com") + "/app/" + appids[comparable] + "/\" target=\"_blank\">" + game + "</a>"));
  124. } else { //Game is not owned or unknown game
  125. //console.log (game + ": not owned");
  126. if ($.inArray(comparable, wlSteamGames) > -1) { //Game is wishlisted
  127. //console.log (game + ": wishlisted");
  128. $(".have").html($(".have").html().replace(game, "<i class='fa icon-purple fa-heart' style='color:purple;' title='You have this game wishlisted on steam'></i> <a href=\"https://" +
  129. (steamdb_instead ? "steamdb.info" : "store.steampowered.com") + "/app/" + appids[comparable] + "/\" target=\"_blank\">" + game + "</a>"));
  130. } else {
  131. $(".have").html($(".have").html().replace(game.replace(/( *\[[^)]*\] *)|( *\([^)]*\) *)|\=.*/g,""),
  132. "<i class='fa icon-red fa-times-circle' style='color:red;' title='You do not own this game on steam, or unknown game: \nPlease check manually'></i> " +
  133. game.replace(/( *\[[^)]*\] *)|( *\([^)]*\) *)|\=.*/g,"") + " <a href='" +
  134. (steamdb_instead ? "https://steamdb.info/search/?a=app&q=" : "https://store.steampowered.com/search/?term=") +
  135. encodeURIComponent(game.replace(/( *\([^)]*\) *)/g,"")) +
  136. "' target='_blank'><i class='fa icon-grey fa-external-link' title='Search game on " +
  137. (steamdb_instead ? "SteamDB" : "Steam") +
  138. "'></i></a> "));
  139. have_unowned += game.replace(/(\"|\')|\=.*/g, '') + "&#013;";
  140. have_unowned_raw += game + "\n";
  141. }
  142. }
  143. }
  144. }, 0);
  145. });
  146. $(".trade_heading").first().html("<i id='clip' data-clipboard-text='" + have_unowned + "' class='icon_to_clipboard fa fa-fw fa-copy' style='cursor: pointer' title='Copy unowned/unknown games to clipboard'></i> I have...");
  147. $("#clip").click(function() {
  148. GM_setClipboard(have_unowned_raw);
  149. alert("Successfully copied unowned have-list games to clipboard!");
  150. });
  151. if (swi) $(".have a:not(.swi)").each(function() { $(this).toggleClass(); });
  152. }