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.

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