Advertisement
Guest User

GG + 360 degree date calculator

a guest
Oct 6th, 2023
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name       GG + 360 degree date calculator
  3. // @version    0.2
  4. // @include        http://tagpro-*.koalabeast.com:*
  5. // @include        http://tangent.jukejuice.com:*
  6. // @include        http://maptest*.newcompte.fr:*
  7. // @include      *://tagpro-test.koalabeast.com/game
  8. // @match         *://*.koalabeast.com/game
  9. // @grant           GM_xmlhttpRequest
  10. // @author  NEUhusky
  11. // ==/UserScript==
  12.  
  13. //Variables to change
  14. var shareWins = false; // Set to true if you want the script to share estimation after *every* win (not recommended but your choice). Otherwise, script will use shareFrequency variable
  15. var shareFrequency = 10; // Estimation will be shared roughly once every X games based on this variable. (ex: setting it to 10 means 1/10 = 10% chance it will be shared on any given win, 5 would be 1/5 = 20% chance, etc.)
  16. var neededWins = 20261; // Set to a different number if you want to calculate reaching a different degree, win requirements can be found here- https://docs.google.com/spreadsheets/d/1pjyS2-tK2ElusfeR54mTmWHy-EX1gx-F124qO_p1zOs/edit#gid=0
  17. var sendGGs = true; // Set to false if you have a separate script and don't want this one to send gg after games
  18.  
  19. var base = window.location.protocol + "//" + window.location.hostname;
  20. var url;
  21. var currentWins = 0;
  22. var winsThisR300 = 0;
  23. var savesThisR300 = 0;
  24. var totalWinsThisR300 = 0;
  25. var R300DayCount = 0;
  26. var daysUntil360 = 0;
  27.  
  28. GM_xmlhttpRequest({
  29.     method: "GET",
  30.     url:    base,
  31.     onload: function(response) {
  32.       var obj = $.parseHTML(response.responseText);
  33.       url = $(obj).find('a[href^="/profile"]').attr("href");
  34.       if (url !== undefined) {
  35.  
  36.           GM_xmlhttpRequest({
  37.               method: 'GET',
  38.               url: base + url,
  39.               onload: function(response) {
  40.                   if (!response.responseText) {
  41.                       return;
  42.                   }
  43.                   currentWins = $(response.responseText).find('#all-stats').find('tbody').find('tr').eq(3).find('td').eq(4).text().trim(); // All Time Wins
  44.                   winsThisR300 = $(response.responseText).find('#rolling').find('tbody').find('tr').eq(3).find('td').eq(1).text().trim(); // Wins In Current R300 (doesn't include saves)
  45.                   savesThisR300 = $(response.responseText).find('#rolling').find('tbody').find('tr').eq(6).find('td').eq(1).text().trim(); // Saves in Current R300
  46.                   totalWinsThisR300 = Number(winsThisR300) + Number(savesThisR300); // Total Wins in Current R300
  47.                   neededWins = neededWins - currentWins - 1; // Remaining wins needed to reach 360 (assuming a win this game)
  48.               },
  49.               onerror: function(response) {
  50.                   console.log('Error: ');
  51.                   console.log(response);
  52.               }
  53.           })
  54.       }
  55.     }
  56. });
  57.  
  58. GM_xmlhttpRequest({
  59.     method: "GET",
  60.     url:    base,
  61.     onload: function(response) {
  62.       var obj = $.parseHTML(response.responseText);
  63.       url = $(obj).find('a[href^="/profile"]').attr("href");
  64.       url = url.replace("profile", "profile_rolling");
  65.       if (url !== undefined) {
  66.  
  67.           GM_xmlhttpRequest({
  68.               method: 'GET',
  69.               url: url,
  70.               headers: {
  71.                   'Content-Type': 'application/json'
  72.               },
  73.               onload: function(response) {
  74.                   if (!response.responseText) {
  75.                       return;
  76.                   }
  77.                   var R300Games = JSON.parse(response.responseText); // Get current R300 game data
  78.                   var oldestGame = R300Games[R300Games.length - 1].played; // Grab date of oldest played game currently in R300
  79.                   var current = new Date();
  80.                   R300DayCount = (current.getTime() - Date.parse(oldestGame)) / 86400000; // Returns how many days ago the oldest game was
  81.               },
  82.               onerror: function(response) {
  83.                   console.log('Error: ');
  84.                   console.log(response);
  85.               }
  86.           })
  87.       }
  88.     }
  89. });
  90.  
  91. tagpro.ready(function() {
  92.     tagpro.socket.on('end', function(data) {
  93.         var lastMessage = 0;
  94.         var active = false;
  95.         function chat(chatMessage) {
  96.             var limit = 500 + 10;
  97.             var now = new Date();
  98.             var timeDiff = now - lastMessage;
  99.             if (timeDiff > limit) {
  100.                 tagpro.socket.emit("chat", chatMessage);
  101.                 lastMessage = new Date();
  102.             } else if (timeDiff >= 0 && !active) {
  103.                 active = true;
  104.                 setTimeout(function(chatMessage) { chat(chatMessage); active = false }, limit - timeDiff, chatMessage);
  105.             }
  106.         }
  107.  
  108.         daysUntil360 = neededWins / (totalWinsThisR300 / R300DayCount); // Calculate days needed until 360 degrees by dividing wins needed by wins achieved per day based on current R300 rates
  109.         var ETA = new Date();
  110.         ETA.setDate(ETA.getDate() + daysUntil360); // Calculate date of achieving 360
  111.         var gg = {"message": "gg", "toAll": true};
  112.         var winningMessage = {"message": 'gg! ' + neededWins + ' wins til 360. ETA (win rate + play amount)- ' + ETA.toLocaleDateString() + ' :\')', "toAll": true};
  113.         var shareModulo = new Date();
  114.         shareModulo = shareModulo % shareFrequency;
  115.         var winningTeam = 0;
  116.         if(data.winner == "red") { winningTeam = 1; }
  117.         else if (data.winner == "blue") {winningTeam = 2; }
  118.         if ((tagpro.players[tagpro.playerId].team == winningTeam) && ((shareModulo == 0) || shareWins)) {
  119.             setTimeout(chat, 100, winningMessage);
  120.         }
  121.         else if (sendGGs) { setTimeout(chat, 100, gg); }
  122.     });
  123. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement