Stake.com Wingman

Sends a percentage of your winnings to the vault

  1. // ==UserScript==
  2. // @name Stake.com Wingman
  3. // @description Sends a percentage of your winnings to the vault
  4. // @description Updated for the new UI
  5. // @description Tips through Stake appreciated: @satology (https://stake.com/?modal=user&name=satology)
  6. // @description My ref: https://stake.com/?c=95c56cf1
  7. // @description Based on @Dauersendung script which is outdated
  8. // @description Tested with crypto display only (meaning 'View in FIAT' should be disabled)
  9. // @description Setup percentage to be saved at SAVE_AMOUNT (at the beginning of the script)
  10. // @description Switching between cryptos might cause an unwanted deposit to the vault
  11. // @description Switch by adding ?currency=ltc (i.e.) to the URL
  12. // @description Running it in more than one tab might cause duplicated deposits to the vault
  13. // @version 1.4
  14. // @author satology
  15. // @match https://stake.com/*
  16. // @run-at document-end
  17. // @namespace Stake.com Wingman
  18. // ==/UserScript==
  19.  
  20. (function() {
  21. const SAVE_AMOUNT = 0.10 //Percentage of the winnings, in decimal (Examples: 50% => 0.50, 75% => 0.75, 15% => 0.15, 10% => 0.10)
  22. const DISPLAY_VAULT_TOTAL = true; // If true it will display the VAULT TOTAL. If false it will display the SUM of deposits made since opened
  23.  
  24. function getCookie(cname) {
  25. var name = cname + "=";
  26. var decodedCookie = decodeURIComponent(document.cookie);
  27. var ca = decodedCookie.split(';');
  28. for(var i = 0; i <ca.length; i++) {
  29. var c = ca[i];
  30. while (c.charAt(0) == ' ') {
  31. c = c.substring(1);
  32. }
  33. if (c.indexOf(name) == 0) {
  34. return c.substring(name.length, c.length);
  35. }
  36. }
  37. return "";
  38. }
  39.  
  40. class StakeApi {
  41. constructor() {
  42. this._accessToken = getCookie("session").replace(/"/g, '');
  43. // this._accessToken = localStorage.getItem('session').replace(/"/g, '');
  44. }
  45. async call(body) {
  46. return fetch("https://api.stake.com/graphql", {
  47. "credentials": "omit",
  48. "headers": {
  49. "content-type": "application/json",
  50. 'x-access-token': this._accessToken,
  51. 'x-lockdown-token': ""},
  52. "referrer": "https://stake.com/",
  53. "body": body,
  54. "method": "POST",
  55. "mode": "cors"
  56. });
  57. }
  58. async getBalances() {
  59. return this.call("{\"operationName\":\"UserVaultBalances\",\"variables\":{},\"query\":\"query UserVaultBalances {\\n user {\\n id\\n balances {\\n available {\\n amount\\n currency\\n __typename\\n }\\n vault {\\n amount\\n currency\\n __typename\\n }\\n __typename\\n }\\n __typename\\n }\\n}\\n\"}");
  60. }
  61. async depositToVault(currency, amount) {
  62. var data = {
  63. operationName: "CreateVaultDeposit",
  64. variables: {
  65. currency: currency,
  66. amount: amount
  67. },
  68. query: "mutation CreateVaultDeposit($amount: Float!, $currency: CurrencyEnum!) {\n createVaultDeposit(amount: $amount, currency: $currency) {\n id\n amount\n currency\n user {\n id\n balances {\n available {\n amount\n currency\n __typename\n }\n vault {\n amount\n currency\n __typename\n }\n __typename\n }\n __typename\n }\n __typename\n }\n}\n"
  69. };
  70. return this.call(JSON.stringify(data));
  71. }
  72. }
  73.  
  74. // let balanceSelector = 'header .styles__Cashier-puey40-2.dMSTdD .styles__Content-rlm06o-1.ixoRjG';
  75. let balanceSelector = '.navigation .balance-toggle .currency span.content span';
  76. var oldBal = '';
  77. let activeCurrency;
  78. const stakeApi = new StakeApi();
  79.  
  80. function getCurrency() {
  81. return getCookie("currency_currency").replace(/"/g, '');
  82. // return JSON.parse(localStorage.getItem("v2_currency")).currency;
  83. }
  84. function updateCurrency() {
  85. let c = getCurrency();
  86. if(c != activeCurrency) {
  87. activeCurrency = c;
  88. return true;
  89. }
  90. return false;
  91. }
  92.  
  93. class Wing {
  94. constructor() {
  95. this._element = document.createElement("span");
  96. this._element.id = "wingElm";
  97. this._element.innerText = "0.00000000";
  98. if (DISPLAY_VAULT_TOTAL) {
  99. this.setVaultBalance();
  100. }
  101.  
  102. // document.querySelector(".styles__Wrap-rlm06o-0.bGSyHm").insertBefore(this._element, null);
  103. document.querySelector(".navigation .balance-toggle .currency").insertBefore(this._element, null);
  104. this._element.title = "Deposited to vault";
  105. }
  106.  
  107. setVaultBalance() {
  108. stakeApi.getBalances().then((r) => r.json()).then((response) => {
  109. updateCurrency();
  110. let balance = response.data.user.balances.find(x => x.vault.currency == activeCurrency);
  111. if(balance) {
  112. this._element.innerText = balance.vault.amount.toFixed(8);
  113. }
  114. });
  115. }
  116.  
  117. update(amount) {
  118. console.log('updating');
  119. if (DISPLAY_VAULT_TOTAL) {
  120. this._element.innerText = amount.toFixed(8);
  121. } else {
  122. this._element.innerText = (parseFloat(this._element.innerText) + amount).toFixed(8);
  123. }
  124. }
  125.  
  126. reset() {
  127. console.log('reseting');
  128. if (DISPLAY_VAULT_TOTAL) {
  129. this.setVaultBalance();
  130. } else {
  131. this._element.innerText = "0.00000000";
  132. }
  133. }
  134. }
  135.  
  136. let wing;
  137. function init(){
  138. if (document.readyState === 'complete') {
  139. var oldBal = document.querySelector(balanceSelector).innerText;
  140. var curBalEle = document.querySelector(balanceSelector).innerText;
  141. wing = new Wing();
  142.  
  143. function tresor() {
  144. oldBal = curBalEle
  145. if (oldBal = curBalEle) {
  146.  
  147. function checkBalance() {
  148. var curBalEle = document.querySelector(balanceSelector);
  149. if(updateCurrency()) { // if currency was changed return
  150. wing.reset();
  151. oldBal = document.querySelector(balanceSelector).innerText;
  152. curBalEle = document.querySelector(balanceSelector).innerText;
  153. return;
  154. }
  155.  
  156. if(document.querySelectorAll(balanceSelector).length > 0) {
  157. curBalEle = document.querySelector(balanceSelector).innerText;
  158. if(curBalEle != '') {
  159. if (curBalEle > oldBal) {
  160. var depositAmount = ((curBalEle - oldBal) * SAVE_AMOUNT);
  161. if (depositAmount >= 1e-8) {
  162. oldBal = (parseFloat(curBalEle) - parseFloat(depositAmount)).toFixed(8);
  163. stakeApi.depositToVault(activeCurrency, depositAmount).then((r) => r.json()).then((response) => {
  164. if (DISPLAY_VAULT_TOTAL) {
  165. try {
  166. let cvd = response.data.createVaultDeposit;
  167. let balanceObject = cvd.user.balances.find(x => x.vault.currency == cvd.currency);
  168. wing.update(balanceObject.vault.amount);
  169. } catch (err) {
  170. console.log('Error trying to read vault balance');
  171. wing.update(depositAmount);
  172. }
  173. } else {
  174. wing.update(depositAmount);
  175. }
  176. });
  177. }
  178. }
  179. }
  180. }
  181. }
  182.  
  183. window.setInterval(checkBalance, 751); //timerspeed read send to tresor
  184. } else {
  185. tresor(); //if different balance run func tresor
  186. }
  187. }
  188. var myTimer = setTimeout(tresor, 5500);
  189. } else {
  190. setTimeout(init, 5000);
  191. }
  192. };
  193. init();
  194. })();

QingJ © 2025

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