SteamTrades - Have List Filter

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

目前为 2018-02-20 提交的版本,查看 最新版本

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