Humblebundle Steam library checker

Will check your steam library and color game title and add a steam link to tell you if you already own this game.

当前为 2018-12-04 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Humblebundle Steam library checker
  3. // @version 0.5
  4. // @description Will check your steam library and color game title and add a steam link to tell you if you already own this game.
  5. // @author Zeper
  6. // @match https://www.humblebundle.com/downloads?key=*
  7. // @match https://www.humblebundle.com/home/keys*
  8. // @match https://www.humblebundle.com/games/*
  9. // @match https://www.humblebundle.com/yogscast/*
  10. // @grant none
  11. // @run-at document-idle
  12. // @namespace https://greasyfork.org/users/191481
  13. // ==/UserScript==
  14.  
  15. var xhr = new XMLHttpRequest();
  16. var debug = true;
  17. //if(debug){console.log("");}
  18.  
  19. var Key = [];
  20. //where key will be stored
  21.  
  22. var Games = [];
  23. //where games will be stored
  24.  
  25. var App = [];
  26. //where all steam app will be stored
  27.  
  28. var curlocation = window.location.pathname.split("/");
  29. var ActualPageType;
  30. //type 0 is a non suported page (such as shop)
  31. //type 1 is https://www.humblebundle.com/downloads?key=*
  32. //type 2 is https://www.humblebundle.com/home/keys*
  33. //type 3 is https://www.humblebundle.com/games/*
  34. //type 4 is https://www.humblebundle.com/yogscast/*
  35.  
  36. var YourAPIKey = "";
  37. //Find your API key here https://steamcommunity.com/dev/apikey
  38.  
  39. var YourSteamID = "";
  40. //Find your steam ID on https://steamdb.info/calculator/
  41.  
  42. // YOUR GAME PRIVACY MUST BE SET TO EVERYONE
  43. // https://steamcommunity.com/my/edit/settings
  44.  
  45.  
  46. function parsekey(pagetype){
  47. Key = [];
  48. if (pagetype == 3 || pagetype == 4) {var GameField = document.getElementsByClassName("game-boxes");} else {var GameField = document.getElementsByClassName("keyfield-value");}
  49. for (var index in GameField) {
  50. if (GameField.hasOwnProperty(index)) {
  51. switch (pagetype){
  52. case 1:
  53. var Obj = GameField[index];
  54. var NameObj = Obj.parentNode.parentNode.parentNode.children[0];
  55. var IsSteamKey = Boolean(Obj.parentNode.parentNode.parentNode.parentNode.parentNode.getElementsByClassName("hb-steam")[0]);
  56. break;
  57. case 2:
  58. var Obj = GameField[index];
  59. var NameObj = Obj.parentNode.parentNode.parentNode.parentNode.parentNode.children[1].children[0];
  60. var IsSteamKey = Boolean(Obj.parentNode.parentNode.parentNode.parentNode.parentNode.getElementsByClassName("hb-steam")[0]);
  61. break;
  62. case 3:
  63. var Obj = GameField[index];
  64. var NameObj = Obj.getElementsByClassName("dd-image-box-text")[0];
  65. var IsSteamKey = Boolean(Obj.getElementsByClassName("hb-steam")[0]);
  66. break;
  67. case 4:
  68. var Obj = GameField[index];
  69. var NameObj = Obj.getElementsByClassName("dd-image-box-text")[0];
  70. var IsSteamKey = Boolean(Obj.getElementsByClassName("hb-steam")[0]);
  71. break;
  72. default:
  73. var Obj = new Object();
  74. var NameObj = new Object();
  75. var IsSteamKey = false;
  76. }
  77. var Name = NameObj.innerText;
  78. if (Obj.parentNode.className == "keyfield redeemed enabled"){
  79. var Reveal = true;
  80. } else {var Reveal = false;}
  81. Key.push({OBJ: Obj , NAMEOBJ: NameObj ,NAME: Name ,REAVEAL: Reveal ,STEAM: IsSteamKey ,STATUS: 0 });
  82. }
  83. }
  84. if(debug){console.log(Key);}
  85. }
  86.  
  87. function getownedgame(APIkey,steamid,callback,callback2){
  88. Games = [];
  89. xhr.open('GET', "https://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key="+APIkey+"&steamid="+steamid+"&include_appinfo=1&format=json", true);
  90. xhr.send();
  91. xhr.onreadystatechange = function () {
  92. if (xhr.readyState == 4 && xhr.status == 200) {
  93. var response = JSON.parse(xhr.response)
  94. for (var index in response.response.games){
  95. Games.push(response.response.games[index].name);
  96. }
  97. if(debug){console.log(Games);}
  98. callback();
  99. callback2();
  100. }
  101. }
  102. }
  103.  
  104. function comparekey2game(){
  105. for (var index in Key) {
  106. if (Key[index].STEAM){
  107. var KeyName = Key[index].NAME.toLowerCase().replace(/\s/g, "").replace(/([:℠™®©,_-])/g, "");
  108. for (var g in Games) {
  109. var GamesName = Games[g].toLowerCase().replace(/\s/g, "").replace(/([:℠™®©,_-])/g, "")
  110. if (KeyName == GamesName) {
  111. Key[index].NAMEOBJ.style["color"] = "red";
  112. Key[index].NAMEOBJ.title = 'This color mean that you already own the game.\n\nRelated game in your Steam library:\n"'+ Games[g] + '"';
  113. Key[index].STATUS = 4;
  114. if(debug){console.log("Game found "+ Games[g]+" ( "+KeyName+" == "+GamesName+" ) Status : "+Key[index].STATUS);}
  115. } else if (KeyName.includes(GamesName)){
  116. if ((Key[index].NAMEOBJ.title === Key[index].NAME || !Key[index].NAMEOBJ.title) && Key[index].STATUS < 3) {
  117. Key[index].NAMEOBJ.title = 'This color mean that you may already had a version of this game.\n\nRelated game in your Steam library:\n"'+ Games[g] + '"';
  118. } else {
  119. Key[index].NAMEOBJ.title = Key[index].NAMEOBJ.title +'\n"'+ Games[g] + '"';
  120. }
  121. if (Key[index].STATUS < 3) {
  122. Key[index].STATUS = 3;
  123. Key[index].NAMEOBJ.style["color"] = "orange";
  124. }
  125. if(debug){console.log("Game maybe found "+ Games[g]+" ( "+KeyName+" includes "+GamesName+" ) Status : "+Key[index].STATUS);}
  126. } else if (GamesName.includes(KeyName)){
  127. if ((Key[index].NAMEOBJ.title === Key[index].NAME || !Key[index].NAMEOBJ.title) && Key[index].STATUS < 2) {
  128. Key[index].NAMEOBJ.title = 'This color mean that you own games with similar names.\n\nRelated game in your Steam library:\n"'+ Games[g] + '"';
  129. } else {
  130. Key[index].NAMEOBJ.title = Key[index].NAMEOBJ.title +'\n"'+ Games[g] + '"';
  131. }
  132. if (Key[index].STATUS < 2) {
  133. Key[index].STATUS = 2;
  134. Key[index].NAMEOBJ.style["color"] = "fuchsia";
  135. }
  136. if(debug){console.log("Game maybe found "+ Games[g]+" ( "+GamesName+" includes "+KeyName+" ) Status : "+Key[index].STATUS);}
  137.  
  138. }
  139. }
  140. if (!Key[index].STATUS) {Key[index].STATUS = 1;}
  141. }
  142. }
  143. addsteamlink();
  144. }
  145.  
  146. function steamapp(){
  147. App = [];
  148. xhr.open('GET', "https://api.steampowered.com/ISteamApps/GetAppList/v2/", true);
  149. xhr.send();
  150. xhr.onreadystatechange = function () {
  151. if (xhr.readyState == 4 && xhr.status == 200) {
  152. var response = JSON.parse(xhr.response);
  153. App = response.applist.apps;
  154. if(debug){console.log(App);}
  155. addsteamlink();
  156. }
  157. }
  158. }
  159.  
  160. function addsteamlink(){
  161. for (var index in Key) {
  162. if (Key[index].STEAM){
  163. var KeyName = Key[index].NAME.toLowerCase().replace(/\s/g, "").replace(/([:℠™®©,_-])/g, "");
  164. Key[index].NAMEOBJ.setAttribute("onclick", "javascript:window.open('https://store.steampowered.com/search/?term=" + Key[index].NAME.replace(/\s/g, " ").replace(/([:℠™®©'",_-])/g, "")+"')");
  165. Key[index].NAMEOBJ.style["cursor"] = "pointer";
  166. for (var g in App) {
  167. var GamesName = App[g].name.toLowerCase().replace(/\s/g, "").replace(/([:℠™®©,_-])/g, "")
  168. if (KeyName == GamesName) {
  169. var storelink = "https://store.steampowered.com/app/" + App[g].appid;
  170. Key[index].NAMEOBJ.setAttribute("onclick", "javascript:window.open('"+storelink+"')");
  171. if(debug){console.log("Steam page link added for "+ Key[index].NAME +" : "+ storelink);}
  172. }
  173. }
  174. }
  175. }
  176. }
  177.  
  178. function init(){
  179. parsekey(ActualPageType);
  180. comparekey2game();
  181. }
  182.  
  183. const observer = new MutationObserver(function () {init();});
  184. if (curlocation[1] == "home") {curlocation = curlocation[1] + "/" + curlocation[2];} else { curlocation = curlocation[1]; }
  185. switch (curlocation){
  186. case "downloads":
  187. ActualPageType = 1;
  188. observer.observe(document.querySelector("div[class='key-container']"), {childList: true});
  189. break;
  190. case "home/keys":
  191. ActualPageType = 2;
  192. observer.observe(document.querySelector('tbody'), {childList: true});
  193. break;
  194. case "games":
  195. ActualPageType = 3;
  196. break;
  197. case "yogscast":
  198. ActualPageType = 4;
  199. break;
  200. default:
  201. ActualPageType = 0;
  202. }
  203.  
  204. getownedgame(YourAPIKey,YourSteamID,init,steamapp);