Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name GG + 360 degree date calculator
- // @version 0.2
- // @include http://tagpro-*.koalabeast.com:*
- // @include http://tangent.jukejuice.com:*
- // @include http://maptest*.newcompte.fr:*
- // @include *://tagpro-test.koalabeast.com/game
- // @match *://*.koalabeast.com/game
- // @grant GM_xmlhttpRequest
- // @author NEUhusky
- // ==/UserScript==
- //Variables to change
- 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
- 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.)
- 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
- var sendGGs = true; // Set to false if you have a separate script and don't want this one to send gg after games
- var base = window.location.protocol + "//" + window.location.hostname;
- var url;
- var currentWins = 0;
- var winsThisR300 = 0;
- var savesThisR300 = 0;
- var totalWinsThisR300 = 0;
- var R300DayCount = 0;
- var daysUntil360 = 0;
- GM_xmlhttpRequest({
- method: "GET",
- url: base,
- onload: function(response) {
- var obj = $.parseHTML(response.responseText);
- url = $(obj).find('a[href^="/profile"]').attr("href");
- if (url !== undefined) {
- GM_xmlhttpRequest({
- method: 'GET',
- url: base + url,
- onload: function(response) {
- if (!response.responseText) {
- return;
- }
- currentWins = $(response.responseText).find('#all-stats').find('tbody').find('tr').eq(3).find('td').eq(4).text().trim(); // All Time Wins
- 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)
- savesThisR300 = $(response.responseText).find('#rolling').find('tbody').find('tr').eq(6).find('td').eq(1).text().trim(); // Saves in Current R300
- totalWinsThisR300 = Number(winsThisR300) + Number(savesThisR300); // Total Wins in Current R300
- neededWins = neededWins - currentWins - 1; // Remaining wins needed to reach 360 (assuming a win this game)
- },
- onerror: function(response) {
- console.log('Error: ');
- console.log(response);
- }
- })
- }
- }
- });
- GM_xmlhttpRequest({
- method: "GET",
- url: base,
- onload: function(response) {
- var obj = $.parseHTML(response.responseText);
- url = $(obj).find('a[href^="/profile"]').attr("href");
- url = url.replace("profile", "profile_rolling");
- if (url !== undefined) {
- GM_xmlhttpRequest({
- method: 'GET',
- url: url,
- headers: {
- 'Content-Type': 'application/json'
- },
- onload: function(response) {
- if (!response.responseText) {
- return;
- }
- var R300Games = JSON.parse(response.responseText); // Get current R300 game data
- var oldestGame = R300Games[R300Games.length - 1].played; // Grab date of oldest played game currently in R300
- var current = new Date();
- R300DayCount = (current.getTime() - Date.parse(oldestGame)) / 86400000; // Returns how many days ago the oldest game was
- },
- onerror: function(response) {
- console.log('Error: ');
- console.log(response);
- }
- })
- }
- }
- });
- tagpro.ready(function() {
- tagpro.socket.on('end', function(data) {
- var lastMessage = 0;
- var active = false;
- function chat(chatMessage) {
- var limit = 500 + 10;
- var now = new Date();
- var timeDiff = now - lastMessage;
- if (timeDiff > limit) {
- tagpro.socket.emit("chat", chatMessage);
- lastMessage = new Date();
- } else if (timeDiff >= 0 && !active) {
- active = true;
- setTimeout(function(chatMessage) { chat(chatMessage); active = false }, limit - timeDiff, chatMessage);
- }
- }
- daysUntil360 = neededWins / (totalWinsThisR300 / R300DayCount); // Calculate days needed until 360 degrees by dividing wins needed by wins achieved per day based on current R300 rates
- var ETA = new Date();
- ETA.setDate(ETA.getDate() + daysUntil360); // Calculate date of achieving 360
- var gg = {"message": "gg", "toAll": true};
- var winningMessage = {"message": 'gg! ' + neededWins + ' wins til 360. ETA (win rate + play amount)- ' + ETA.toLocaleDateString() + ' :\')', "toAll": true};
- var shareModulo = new Date();
- shareModulo = shareModulo % shareFrequency;
- var winningTeam = 0;
- if(data.winner == "red") { winningTeam = 1; }
- else if (data.winner == "blue") {winningTeam = 2; }
- if ((tagpro.players[tagpro.playerId].team == winningTeam) && ((shareModulo == 0) || shareWins)) {
- setTimeout(chat, 100, winningMessage);
- }
- else if (sendGGs) { setTimeout(chat, 100, gg); }
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement