SerlitePD

Primedice 4 Bet Logger

Jan 8th, 2017
766
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. //  PD4 Bet Logger
  3. //  Created by Serlite
  4. //
  5. //  - Stores successful bets in browser local storage for future reference
  6. //  - Provides utilities to log and clear bets (no UI at the moment, must be called through console)
  7. //      - If you want to save your bets offline, run logSavedBets() in the console, then paste the output into a text file
  8. //        (in supported modern browsers, the output is copied automatically to your clipboard)
  9. */
  10.  
  11. var userBetLogKey = "userBetLog";
  12. var currentBetLog;
  13.  
  14. var retrievedBets = localStorage[userBetLogKey];
  15. if (retrievedBets != null) {
  16.     currentBetLog = JSON.parse(retrievedBets);
  17. }
  18. if (currentBetLog == null){
  19.     currentBetLog = [];
  20. }
  21.  
  22. (function(open) {
  23.     XMLHttpRequest.prototype.open = function(method, url, async, user, pass) {
  24.         this.addEventListener("readystatechange", function() {
  25.             if (this.readyState == 4 && this.responseURL.indexOf("https://api.primedice.com/api/bet") != -1) {
  26.                 var responseObject = JSON.parse(this.response);
  27.  
  28.                 // Ensure bet is not stored duplicate times, in case listener is erroneously attached multiple times by user
  29.                 if (currentBetLog.length == 0 || currentBetLog[currentBetLog.length - 1].id != responseObject.bet.id){
  30.                     currentBetLog.push(responseObject.bet);
  31.                     localStorage[userBetLogKey] = JSON.stringify(currentBetLog);
  32.                 }
  33.             }
  34.         }, false);
  35.  
  36.         open.call(this, method, url, async, user, pass);
  37.     };
  38.  
  39. })(XMLHttpRequest.prototype.open);
  40.  
  41. function clearSavedBets(){
  42.     currentBetLog = [];
  43.     localStorage[userBetLogKey] = null;
  44. }
  45.  
  46. function logSavedBets(){
  47.     var loggedBetString = "";
  48.     for (var i = 0; i < currentBetLog.length; i++){
  49.         loggedBetString += formatSavedBet(currentBetLog[i]) + "\n";
  50.     }
  51.  
  52.     console.log(loggedBetString);
  53.     copy(loggedBetString);
  54. }
  55.  
  56. function formatSavedBet(bet){
  57.     return "id: " + bet.id
  58.         + " | " + "time: " + new Date(bet.timestamp).toUTCString()
  59.         + " | " + "bet: " + (bet.amount / 100000000).toFixed(8)
  60.         + " | " + "payout: " + bet.multiplier + "x"
  61.         + " | " + "game: " + bet.condition + " " + bet.target.toFixed(2)
  62.         + " | " + "roll: " + bet.roll.toFixed(2)
  63.         + " | " + "profit: " + (bet.profit / 100000000).toFixed(8)
  64.         + " | " + (bet.win ? "WIN" : "LOSS");
  65. }
Advertisement
Add Comment
Please, Sign In to add comment