// ==UserScript== // @name Stake.com Wingman // @description Sends a percentage of your winnings to the vault // @description Updated for the new UI // @description Tips through Stake appreciated: @satology (https://stake.com/?modal=user&name=satology) // @description My ref: https://stake.com/?c=95c56cf1 // @description Based on @Dauersendung script which is outdated // @description Tested with crypto display only (meaning 'View in FIAT' should be disabled) // @description Setup percentage to be saved at SAVE_AMOUNT (at the beginning of the script) // @description Switching between cryptos might cause an unwanted deposit to the vault // @description Switch by adding ?currency=ltc (i.e.) to the URL // @description Running it in more than one tab might cause duplicated deposits to the vault // @version 1.4 // @author satology // @match https://stake.com/* // @run-at document-end // @namespace Stake.com Wingman // @downloadURL none // ==/UserScript== (function() { const SAVE_AMOUNT = 0.10 //Percentage of the winnings, in decimal (Examples: 50% => 0.50, 75% => 0.75, 15% => 0.15, 10% => 0.10) 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 function getCookie(cname) { var name = cname + "="; var decodedCookie = decodeURIComponent(document.cookie); var ca = decodedCookie.split(';'); for(var i = 0; i r.json()).then((response) => { updateCurrency(); let balance = response.data.user.balances.find(x => x.vault.currency == activeCurrency); if(balance) { this._element.innerText = balance.vault.amount.toFixed(8); } }); } update(amount) { console.log('updating'); if (DISPLAY_VAULT_TOTAL) { this._element.innerText = amount.toFixed(8); } else { this._element.innerText = (parseFloat(this._element.innerText) + amount).toFixed(8); } } reset() { console.log('reseting'); if (DISPLAY_VAULT_TOTAL) { this.setVaultBalance(); } else { this._element.innerText = "0.00000000"; } } } let wing; function init(){ if (document.readyState === 'complete') { var oldBal = document.querySelector(balanceSelector).innerText; var curBalEle = document.querySelector(balanceSelector).innerText; wing = new Wing(); function tresor() { oldBal = curBalEle if (oldBal = curBalEle) { function checkBalance() { var curBalEle = document.querySelector(balanceSelector); if(updateCurrency()) { // if currency was changed return wing.reset(); oldBal = document.querySelector(balanceSelector).innerText; curBalEle = document.querySelector(balanceSelector).innerText; return; } if(document.querySelectorAll(balanceSelector).length > 0) { curBalEle = document.querySelector(balanceSelector).innerText; if(curBalEle != '') { if (curBalEle > oldBal) { var depositAmount = ((curBalEle - oldBal) * SAVE_AMOUNT); if (depositAmount >= 1e-8) { oldBal = (parseFloat(curBalEle) - parseFloat(depositAmount)).toFixed(8); stakeApi.depositToVault(activeCurrency, depositAmount).then((r) => r.json()).then((response) => { if (DISPLAY_VAULT_TOTAL) { try { let cvd = response.data.createVaultDeposit; let balanceObject = cvd.user.balances.find(x => x.vault.currency == cvd.currency); wing.update(balanceObject.vault.amount); } catch (err) { console.log('Error trying to read vault balance'); wing.update(depositAmount); } } else { wing.update(depositAmount); } }); } } } } } window.setInterval(checkBalance, 751); //timerspeed read send to tresor } else { tresor(); //if different balance run func tresor } } var myTimer = setTimeout(tresor, 5500); } else { setTimeout(init, 5000); } }; init(); })();