SteamTrades - Have List Filter

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

目前为 2016-11-07 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name SteamTrades - Have List Filter
  3. // @namespace Royalgamer06
  4. // @version 1.1
  5. // @description Check if you own the games from someone's have list (instant Compare2Steam)
  6. // @author Royalgamer06
  7. // @match https://www.steamtrades.com/trade/*
  8. // @grant GM_xmlhttpRequest
  9. // @grant GM_setValue
  10. // @grant GM_getValue
  11. // @grant GM_setClipboard
  12. // @support https://www.steamgifts.com/discussion/fN8vR/userscript-steamgifts-trades-have-list-filter-compare2steam-alternative
  13. // ==/UserScript==
  14.  
  15. //If you want to set your/another SteamID64 manually, state it here between brackets. (For example, to check owned games from someone else)
  16. var manual_steamID = "";
  17.  
  18. //Set your steam sync interval in hours. (Set to 0 if you want to force a sync)
  19. var sync_interval = 6;
  20.  
  21. //Set link to search game to SteamDB instead of the Steam Store? (SteamDB finds removed games from the steam store and gives better results overall)
  22. var steamdb_instead = false;
  23.  
  24. //Do not touch below :)
  25. $(document).ready(function() {
  26. $(".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" +
  27. "Warning: It may become unresponsive for a while.'>Filter</a>)");
  28. $("#filter").click(function() {
  29. $("#filter").removeAttr("style").html("<i class='fa fa-spin fa-circle-o-notch' />");
  30. if (manual_steamID.length == 17) {
  31. syncHandler(manual_steamID);
  32. } else if (GM_getValue("steamID") !== undefined) {
  33. syncHandler(GM_getValue("steamID"));
  34. } else {
  35. if ($(".nav_avatar").length > 0) {
  36. var steamID = $(".nav_avatar").attr("href").split("user/")[1];
  37. if (steamID.length == 17) {
  38. GM_setValue("steamID", steamID);
  39. syncHandler(steamID);
  40. } else {
  41. alert("[Have List Filter] ERROR: Invalid SteamID. Refresh the page to try again, or set manual SteamID");
  42. }
  43. } else {
  44. alert("[Have List Filter] ERROR: Could not fetch SteamID automatically. Refresh the page to try again, or set manual SteamID");
  45. }
  46. }
  47. });
  48. });
  49.  
  50. function syncHandler(steamID) {
  51. var now = new Date().valueOf();
  52. var last = GM_getValue("lastsync");
  53. if (last === undefined) {
  54. GM_setValue("lastsync", now);
  55. syncHandler(steamID);
  56. } else if ((now - last) / 3600000 > sync_interval || GM_getValue("ownedSteamGames") === undefined || GM_getValue("wlSteamGames") === undefined) {
  57. GM_xmlhttpRequest({
  58. method: "GET",
  59. url: "http://steamcommunity.com/profiles/" + steamID + "/games/?xml=1",
  60. onload: function(gdata) {
  61. var xml = $.parseXML(gdata.responseText);
  62. var ownedSteamGames = [];
  63. $("name", xml).each(function() {
  64. ownedSteamGames.push($(this).text().toLowerCase().replace(/\:|\-|\–|\\|\/|\™|\®| |\'|\.|\?|\!/g, ""));
  65. });
  66. GM_setValue("ownedSteamGames", ownedSteamGames.join("-"));
  67. GM_xmlhttpRequest({
  68. method: "GET",
  69. url: "http://steamcommunity.com/profiles/" + steamID + "/wishlist",
  70. onload: function(wldata) {
  71. var wlSteamGames = [];
  72. $("#wishlist_items h4", wldata.responseText).each(function() {
  73. wlSteamGames.push($(this).text().toLowerCase().replace(/\:|\-|\–|\\|\/|\™|\®| |\'|\.|\?|\!/g, ""));
  74. });
  75. GM_setValue("wlSteamGames", wlSteamGames.join("-"));
  76. GM_setValue("lastsync", now);
  77. console.log("[Have List Filter] Synced with steam!");
  78. filterHaveList(ownedSteamGames, wlSteamGames);
  79. }
  80. });
  81. }
  82. });
  83. } else {
  84. var ownedSteamGames = GM_getValue("ownedSteamGames");
  85. var wlSteamGames = GM_getValue("wlSteamGames");
  86. filterHaveList(ownedSteamGames.split("-"), wlSteamGames.split("-"));
  87. }
  88. }
  89.  
  90. function filterHaveList(ownedSteamGames, wlSteamGames) {
  91. var have = document.getElementsByClassName("have")[0].innerText.split("\n");
  92. var have_unowned = "";
  93. var have_unowned_raw = "";
  94. have.forEach(function(game) {
  95. if (game.length > 1 && game.length < 80) {
  96. // Ignoring everything between and including brackets, and also these symbols: :, -, –, \, /, ™, ®, , ', ., ? and ! (Better suggestions? Please contact me)
  97. if ($.inArray(game.toLowerCase().replace(/( *\[[^)]*\] *)|( *\([^)]*\) *)|\=.*|\:|\-|\–|\\|\/|\™|\®| |\'|\.|\?|\!/g, ""), wlSteamGames) > -1) { //Game is wishlisted
  98. //console.log (game + ": wishlisted");
  99. $(".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> " + game));
  100. }
  101. if ($.inArray(game.toLowerCase().replace(/( *\[[^)]*\] *)|( *\([^)]*\) *)|\=.*|\:|\-|\–|\\|\/|\™|\®| |\'|\.|\?|\!/g, ""), ownedSteamGames) > -1) { //Game is owned
  102. //console.log (game + ": owned");
  103. $(".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> " + game));
  104. } else { //Game is not owned or unknown game
  105. //console.log (game + ": not owned");
  106. $(".have").html($(".have").html().replace(game.replace(/( *\[[^)]*\] *)|( *\([^)]*\) *)|\=.*/g,""),
  107. "<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> " +
  108. game.replace(/( *\[[^)]*\] *)|( *\([^)]*\) *)|\=.*/g,"") + " <a href='" +
  109. (steamdb_instead ? "https://steamdb.info/search/?a=app&q=" : "https://store.steampowered.com/search/?term=") +
  110. encodeURIComponent(game.replace(/( *\([^)]*\) *)/g,"")) +
  111. "' target='_blank'><i class='fa icon-grey fa-external-link' title='Search game on " +
  112. (steamdb_instead ? "SteamDB" : "Steam") +
  113. "'></i></a> "));
  114. have_unowned += game.replace(/(\"|\')|\=.*/g, '') + "&#013;";
  115. have_unowned_raw += game + "\n";
  116. }
  117. }
  118. });
  119. $(".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...");
  120. $("#clip").click(function() {
  121. GM_setClipboard(have_unowned_raw);
  122. alert("Successfully copied unowned have-list games to clipboard!");
  123. });
  124. }