Steamlvlbot

Bot that will buy set of card.

  1. // ==UserScript==
  2. // @name Steamlvlbot
  3. // @version 0.21
  4. // @description Bot that will buy set of card.
  5. // @author Zeper
  6. // @match https://steamlvlup.com/
  7. // @match https://steamlvlup.com/inventory
  8. // @grant none
  9. // @namespace https://greasyfork.org/users/191481
  10. // ==/UserScript==
  11.  
  12. var NeverStop = false;
  13. if(localStorage.NeverStop === undefined) {localStorage.setItem("NeverStop", false);} else {NeverStop = JSON.parse(localStorage.getItem("NeverStop"));}
  14.  
  15. if(localStorage.PREV_USER_BALANCE === undefined) {} else {if(localStorage.PREV_USER_BALANCE != USER_BALANCE){localStorage.removeItem("PREV_USER_BALANCE");}else{localStorage.removeItem("PREV_USER_BALANCE");if(NeverStop){localStorage.setItem("IsBotOn", false);console.log("User balance same as previous, bot can't purchase... the bot will shutdown");}}}
  16.  
  17. var IsDebug = false;
  18. if(localStorage.IsDebug === undefined) {localStorage.setItem("IsDebug", false);} else {IsDebug = JSON.parse(localStorage.getItem("IsDebug"));}
  19.  
  20. var IsCustom = false;
  21. if(localStorage.IsCustom === undefined) {localStorage.setItem("IsCustom", false);} else {IsCustom = JSON.parse(localStorage.getItem("IsCustom"));}
  22.  
  23. var CustomName = "";
  24. if(localStorage.CustomName === undefined) {localStorage.setItem("CustomName", "");} else {if(localStorage.CustomName.length > 0) {CustomName = escape(escape(localStorage.getItem("CustomName")));}}
  25. if (IsDebug) {console.log("CustomName escaped twice:"+CustomName);}
  26.  
  27. var CustomHide = false;
  28. if(localStorage.CustomHide === undefined) {localStorage.setItem("CustomHide", false);} else {CustomHide = JSON.parse(localStorage.getItem("CustomHide"));}
  29.  
  30. var IsBotOn = false;
  31. if(localStorage.IsBotOn === undefined) {localStorage.setItem("IsBotOn", false);} else {IsBotOn = JSON.parse(localStorage.getItem("IsBotOn"));}
  32.  
  33. var GoodPrice = 230;
  34. if(localStorage.GoodPrice === undefined) {localStorage.setItem("GoodPrice", 230);} else {GoodPrice = JSON.parse(localStorage.getItem("GoodPrice"));}
  35.  
  36. var AutoWithdraw = false;
  37. if(localStorage.AutoWithdraw === undefined) {localStorage.setItem("AutoWithdraw", false);} else {AutoWithdraw = JSON.parse(localStorage.getItem("AutoWithdraw"));}
  38.  
  39. var DoWithdraw = false;
  40. if(localStorage.DoWithdraw === undefined) {localStorage.setItem("DoWithdraw", false);} else {DoWithdraw = JSON.parse(localStorage.getItem("DoWithdraw"));}
  41.  
  42. var xhr = new XMLHttpRequest();
  43.  
  44. function check() {
  45. if (IsCustom) {xhr.open('GET', "https://steamlvlup.com/shop/items?page=0&hide_exist="+CustomHide+"&page_size=10&name="+CustomName, true);}
  46. else {xhr.open('GET', "https://steamlvlup.com/shop/items?page=0&hide_exist=true&page_size=1337&sort_by=price&sort_type=asc", true);}
  47. xhr.send();
  48. xhr.onreadystatechange = function () {
  49. if (xhr.readyState == 4 && xhr.status == 200) {
  50. console.log("Looking for cards");
  51. var response = JSON.parse(xhr.responseText);
  52. if (response.count > 0) {
  53. if (IsDebug){console.log(response);}
  54. console.log("Set of card found");
  55. if (IsCustom) {
  56. if (response.items["0"].set_price <= GoodPrice){
  57. if (response.items["0"].count > 0) {
  58. if (response.items["0"].bg_lvl < 5 || !CustomHide) {
  59. console.log("Good price found for "+unescape(response.items["0"].name)+" at "+response.items["0"].set_price+" gems with "+response.items["0"].count+" in stock");
  60. if (USER_BALANCE < response.items["0"].set_price){console.log("Price seems too hight for actual balance ("+USER_BALANCE+"), trying to buy anyway");}
  61. BuyBadge(response.items["0"].appid,response.items["0"].border,response.items["0"].set_price);
  62. } else {console.log("Set found but badge lvl is already max");}
  63. } else {console.log("at a good price but not in stock");}
  64. } else {console.log("but at a price too high");}
  65. } else {
  66. if (response.items["0"].set_price <= GoodPrice && response.items["0"].bg_lvl < 5){
  67. console.log("Good price found for "+unescape(response.items["0"].name)+" at "+response.items["0"].set_price+" gems");
  68. if (USER_BALANCE < response.items["0"].set_price){console.log("Price seems too hight for actual balance ("+USER_BALANCE+"), trying to buy anyway");}
  69. BuyBadge(response.items["0"].appid,response.items["0"].border,response.items["0"].set_price);
  70. } else {console.log("No set of card found at a good price that you don't already own");}}
  71. } else {if(IsCustom) {console.log("No Set found, try another CustomName");} else {console.log("No Set found");}}
  72. }
  73. }
  74. }
  75.  
  76. function BuyBadge(badge, border, price){
  77. if (badge && border >= 0){
  78. var csrf = document.getElementsByName("csrf-token")[0].content;
  79. xhr.open('POST', "https://steamlvlup.com/buy/badge", true);
  80. xhr.setRequestHeader('X-CSRF-TOKEN', csrf);
  81. xhr.setRequestHeader('Content-Type', "application/x-www-form-urlencoded; charset=UTF-8");
  82. var data = "appid="+badge.toString()+"&border="+border.toString();
  83. xhr.send(data);
  84. xhr.onreadystatechange = function () {
  85. if (xhr.readyState == 4 && xhr.status == 200) {
  86. var response = JSON.parse(xhr.responseText);
  87. if (IsDebug){console.log(response);}
  88. var purchaseSuccess = response.success
  89. if (purchaseSuccess){
  90. console.log("Purchase Success !");
  91. update_balance(price, 'dec');
  92. if (AutoWithdraw) {window.location = window.location.origin+"/inventory";localStorage.setItem("DoWithdraw", true);} else {window.location.reload(true);}
  93. } else {
  94. console.log("Purchase Failed ("+response.msg+")");
  95. localStorage.setItem("PREV_USER_BALANCE", USER_BALANCE);
  96. console.log("Reloading to update user balance");
  97. window.location.reload(true);
  98. }
  99. }
  100. }
  101. }
  102. }
  103.  
  104. function withdraw(){
  105. xhr.open('GET', "https://steamlvlup.com/inventory/load?appid=&hide_un=false", true);
  106. xhr.send();
  107. xhr.onreadystatechange = function () {
  108. if (xhr.readyState == 4 && xhr.status == 200) {
  109. console.log("Loading inventory");
  110. var response = JSON.parse(xhr.responseText);
  111. if (IsDebug){console.log(response);}
  112. if (response.success && response.count > 0){
  113. localStorage.setItem("DoWithdraw", false);
  114. console.log("Withdraw all inventory");
  115. WS = new WebSocket(HOST + '?token=' + TOKEN + '&timestamp=' + TIMESTAMP + '&steamid=' + STEAMID);
  116. WS.onopen = function() {
  117. var count_sel = document.getElementsByClassName('inv_item');
  118. var Msg = {};
  119. Msg.token = T_TOKEN;
  120. Msg.command = "withdraw";
  121. Msg.stockid = local_stockid;
  122. var items = [];
  123. if(count_sel.length>0){for(var i=0; i<count_sel.length; i++){items[i]=count_sel[i].dataset.id;}}
  124. Msg.items = items;
  125. WS.send(JSON.stringify(Msg));
  126. console.log("Steam Offer sent !");
  127. window.location = window.location.origin;
  128. };
  129. } else {console.log("Inventory empty");window.location.reload(true);}
  130. }
  131. }
  132. }
  133.  
  134. if (IsBotOn) {
  135. if (window.location.href == window.location.origin+"/"){
  136. InitShop();
  137. }
  138.  
  139. if (window.location.href == window.location.origin+"/inventory" && DoWithdraw){
  140. withdraw();
  141. }
  142. }
  143.  
  144. function InitShop(){
  145. if (IsBotOn) {
  146. check();
  147. setTimeout(function () {InitShop();},30000);
  148. }
  149. }