Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- // PD4 Bet Logger
- // Created by Serlite
- //
- // - Stores successful bets in browser local storage for future reference
- // - Provides utilities to log and clear bets (no UI at the moment, must be called through console)
- // - If you want to save your bets offline, run logSavedBets() in the console, then paste the output into a text file
- // (in supported modern browsers, the output is copied automatically to your clipboard)
- */
- var userBetLogKey = "userBetLog";
- var currentBetLog;
- var retrievedBets = localStorage[userBetLogKey];
- if (retrievedBets != null) {
- currentBetLog = JSON.parse(retrievedBets);
- }
- if (currentBetLog == null){
- currentBetLog = [];
- }
- (function(open) {
- XMLHttpRequest.prototype.open = function(method, url, async, user, pass) {
- this.addEventListener("readystatechange", function() {
- if (this.readyState == 4 && this.responseURL.indexOf("https://api.primedice.com/api/bet") != -1) {
- var responseObject = JSON.parse(this.response);
- // Ensure bet is not stored duplicate times, in case listener is erroneously attached multiple times by user
- if (currentBetLog.length == 0 || currentBetLog[currentBetLog.length - 1].id != responseObject.bet.id){
- currentBetLog.push(responseObject.bet);
- localStorage[userBetLogKey] = JSON.stringify(currentBetLog);
- }
- }
- }, false);
- open.call(this, method, url, async, user, pass);
- };
- })(XMLHttpRequest.prototype.open);
- function clearSavedBets(){
- currentBetLog = [];
- localStorage[userBetLogKey] = null;
- }
- function logSavedBets(){
- var loggedBetString = "";
- for (var i = 0; i < currentBetLog.length; i++){
- loggedBetString += formatSavedBet(currentBetLog[i]) + "\n";
- }
- console.log(loggedBetString);
- copy(loggedBetString);
- }
- function formatSavedBet(bet){
- return "id: " + bet.id
- + " | " + "time: " + new Date(bet.timestamp).toUTCString()
- + " | " + "bet: " + (bet.amount / 100000000).toFixed(8)
- + " | " + "payout: " + bet.multiplier + "x"
- + " | " + "game: " + bet.condition + " " + bet.target.toFixed(2)
- + " | " + "roll: " + bet.roll.toFixed(2)
- + " | " + "profit: " + (bet.profit / 100000000).toFixed(8)
- + " | " + (bet.win ? "WIN" : "LOSS");
- }
Advertisement
Add Comment
Please, Sign In to add comment