Steam Auto Wishlist

Add All Steam App in your wishlist.

  1. // ==UserScript==
  2. // @name Steam Auto Wishlist
  3. // @namespace https://gf.qytechs.cn/users/191481
  4. // @version 0.31
  5. // @description Add All Steam App in your wishlist.
  6. // @author Zeper
  7. // @match https://store.steampowered.com/news
  8. // @grant GM_xmlhttpRequest
  9. // ==/UserScript==
  10.  
  11. var IsDebug = true;
  12. var xhr = new XMLHttpRequest();
  13. var AppList = [];
  14. var WishList = [];
  15. var LastAppAdded = 0;
  16. var LastAppFail = 0;
  17. var AppListIndex = 0;
  18. var ErrorCount = 0;
  19. var RetryOverError = 1; // At least 1 if you don't want to break the script
  20. var NetErrorCount = 0;
  21. var RetryOverNetError = 3; // At least 1 if you don't want to break the script
  22. var Loop = 0;
  23. var timestamp = 0;
  24. var minDelay = 2000; // min delay between each request in millisecond, to not spam steam server if you have a good internet connection
  25.  
  26. function FindIndexByAppID(value){
  27. return value == this;
  28. }
  29.  
  30. function arr_diff (a1, a2) {
  31.  
  32. var a = [], diff = [];
  33.  
  34. for (var i = 0; i < a1.length; i++) {
  35. a[a1[i]] = true;
  36. }
  37.  
  38. for (var i = 0; i < a2.length; i++) {
  39. if (a[a2[i]]) {
  40. delete a[a2[i]];
  41. } else {
  42. a[a2[i]] = true;
  43. }
  44. }
  45.  
  46. for (var k in a) {
  47. diff.push(k);
  48. }
  49.  
  50. return diff;
  51. }
  52.  
  53. function AddSucces( response ){
  54. var delay = 1;
  55. LastAppAdded = AppList[AppListIndex];
  56. console.log("App "+ LastAppAdded +" added to the whishlist !");
  57. localStorage.setItem("SCRIPT_WISHLIST_LAST_APP_ADDED", LastAppAdded);
  58. AppListIndex++;
  59. if (AppListIndex < AppList.length){
  60. if ((Date.now() - timestamp) < minDelay) {delay = minDelay}
  61. setTimeout(() => {AddAllAppToWishlist();}, delay);
  62. } else {
  63. console.log("All App added in the wishlist !");
  64. if (IsDebug){console.log("AppListIndex : "+AppListIndex);}
  65. if (Loop){location.reload();}
  66. }
  67. }
  68.  
  69. function AddFailed( response , NetworkError = 0){
  70. var delay = 1;
  71. if (!NetworkError) {ErrorCount++;} else {NetErrorCount++;}
  72. LastAppFail = AppList[AppListIndex];
  73. console.log("Failed to add "+ LastAppFail +" to the whishlist ("+response+")");
  74. localStorage.setItem("SCRIPT_WISHLIST_LAST_APP_FAIL", LastAppFail);
  75. if ((ErrorCount >= RetryOverError) || (NetErrorCount >= RetryOverNetError || NetErrorCount === 0)) {
  76. ErrorCount = 0;
  77. NetErrorCount = 0;
  78. AppListIndex++;
  79. }
  80. if (AppListIndex < AppList.length){
  81. if ((Date.now() - timestamp) < minDelay) {delay = minDelay}
  82. setTimeout(() => {AddAllAppToWishlist();}, delay);
  83. } else {
  84. console.log("All App added in the wishlist !");
  85. if (IsDebug){console.log("AppListIndex : "+AppListIndex);}
  86. if (Loop){location.reload();}
  87. }
  88. }
  89.  
  90. function AddAllAppToWishlist(){
  91. xhr.open('POST', "https://store.steampowered.com/api/addtowishlist", "true");
  92. xhr.setRequestHeader('X-Requested-With', "XMLHttpRequest");
  93. xhr.setRequestHeader('Content-Type', "application/x-www-form-urlencoded; charset=UTF-8");
  94. var data = "sessionid="+g_sessionID.toString()+"&appid="+AppList[AppListIndex].toString();
  95. xhr.send(data);
  96. timestamp = Date.now();
  97. xhr.onreadystatechange = function () {
  98. if (xhr.readyState == 4) {
  99. if(xhr.status == 200){
  100. var response = JSON.parse(xhr.responseText);
  101. if (IsDebug){console.log(response);}
  102. if (response.success){
  103. AddSucces(response.msg);
  104. } else {
  105. AddFailed(response.msg);
  106. }
  107. } else {
  108. AddFailed(xhr.status, 1);
  109. }
  110. }
  111. }
  112. }
  113.  
  114. function LoadLastAppID(){
  115. if (localStorage.getItem("SCRIPT_WISHLIST_LAST_APP_ADDED")) {LastAppAdded = parseInt(localStorage.getItem("SCRIPT_WISHLIST_LAST_APP_ADDED"));console.log("LastAppAdded : "+LastAppAdded);}
  116. if (localStorage.getItem("SCRIPT_WISHLIST_LAST_APP_FAIL")) {LastAppFail = parseInt(localStorage.getItem("SCRIPT_WISHLIST_LAST_APP_FAIL"));console.log("LastAppFail : "+LastAppFail);}
  117. if ( LastAppFail && AppList.includes(LastAppFail) ) {console.log("Loading LastAppindex From LastAppFail...");AppListIndex = AppList.findIndex(FindIndexByAppID,LastAppFail);if (AppListIndex >= AppList.length-1 || AppListIndex < 0){AppListIndex = 0;console.log("AppListIndex is at the end (or OOB) of the Applist.\nReboot of AppListIndex...");}}
  118. AddAllAppToWishlist();
  119. }
  120.  
  121. function GetWishList(){
  122. xhr.open('GET', "https://store.steampowered.com/dynamicstore/userdata", true);
  123. xhr.send();
  124. xhr.onreadystatechange = function () {
  125. if (xhr.readyState == 4) {
  126. if(xhr.status == 200){
  127. var response = JSON.parse(xhr.responseText);
  128. if (IsDebug){console.log(response);}
  129. if (response.rgWishlist){
  130. WishList = response.rgWishlist;
  131. if (IsDebug){console.log("Succes WishList:"+WishList);}
  132. AppList = arr_diff(AppList,WishList);
  133. if (IsDebug){console.log("App Not in Wish list:"+AppList);}
  134. LoadLastAppID();
  135. } else {
  136. console.log("Failed to get rgWishlist from the response");
  137. }
  138. } else {
  139. console.log("WishList request fail");
  140. }
  141. }
  142. }
  143. }
  144.  
  145. GM_xmlhttpRequest ( {
  146. method: "GET",
  147. url: "https://api.steampowered.com/ISteamApps/GetAppList/v2",
  148. onreadystatechange : function (response) {
  149. if (response.readyState == 4 && response.status == 200) {
  150. var JSONresponse = JSON.parse(response.responseText);
  151. if (IsDebug){console.log(JSONresponse);}
  152. for (var i = 0; i < JSONresponse.applist.apps.length; i++){
  153. AppList.push(JSONresponse.applist.apps[i].appid);
  154. }
  155. AppList.sort(function(a, b) {return a - b;});
  156. if (IsDebug){console.log(AppList);}
  157. GetWishList();
  158. }
  159. }
  160. } );

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址