Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name TagPro Rank Userscript
- // @namespace http://www.reddit.com/user/-omicron-/
- // @description Displays ranks on users ingame based on tagpro-stats.com data
- // @include http://tagpro-*.koalabeast.com:*
- // @include http://tangent.jukejuice.com:*
- // @include http://maptest.newcompte.fr:*
- // @include http://justletme.be:*
- // @license GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html
- // @author OmicroN
- // @version 0.5
- // ==/UserScript==
- (function() {
- function contentEval(source)
- {
- // Check for function input.
- if ('function' == typeof source) {
- // Execute this function with no arguments, by adding parentheses.
- // One set around the function, required for valid syntax, and a
- // second empty set calls the surrounded function.
- source = '(' + source + ')();'
- }
- // Create a script node holding this source code.
- var script = document.createElement('script');
- script.setAttribute("type", "application/javascript");
- script.textContent = source;
- // Insert the script node into the page, so it will run, and immediately
- // remove it to clean up.
- document.body.appendChild(script);
- document.body.removeChild(script);
- }
- // The actual script functionality
- function rankScript()
- {
- // Stores the playerid/names of players who have already been parsed/ranked shown
- ranked = [];
- // Simple function to get the length of an object
- function objectLength(obj)
- {
- var result = 0;
- for(var prop in obj) {
- if (obj.hasOwnProperty(prop)) {
- result++;
- }
- }
- return result;
- }
- // Stores the options for user to customize the script
- rankoptions = []
- /*
- The identifier to use to pull either the actual number
- or rank for the various different stats available
- See http://www.tagpro-stats.com/profile.php?userid=20338
- Number Rank
- Win Percent | win-percent | win-percent-rank
- Wins | wins | wins-rank
- Losses | losses | losses-rank
- Games | games | games-rank
- Hours |
- Minutes/Game | minute-game | minute-game-rank
- Disconnects | dcs | dcs-rank
- Grabs | grabs | grabs-rank
- Grabs/Game | grab_game | grab-game-rank
- Grabs/Hour | grab-hour | grab-hour-rank
- Drops | drops | drops-rank
- Drops/Game | drop-game | drop-game-rank
- Drops/Hour | drop-hour | drop-hour-rank
- Popped | popped | popped-rank
- Pops/Game | pop-game | pop-game-rank
- Pops/Hour | pop-hour | pop-hour-rank
- Tags | tags | tags-rank
- Tags/Game | tag-game | tag-game-rank
- Tags/Hour | tag-hour | tag-hour-rank
- Returns | returns | returns-rank
- Returns/Game | return-game | return-game-rank
- Returns/Hours | return-hour | return-hour-rank
- Captures | captures | captures-rank
- Captures/Game | cap-game | cap-game-rank
- Captures/Hour | cap-hour | cap-hour-rank
- Captures/Grab | caps-grab | caps-grab-rank
- Tags/Pop | tag-pop | tag-pop-rank
- Non-Return Tags | nrtags | nrtags-rank
- Support | support | support-rank
- Hold | hold | hold-rank
- Prevent | prevent | prevent-rank
- */
- rankoptions['query'] = 'win-percent';
- // Timespan to pull data from 'all' for all time or 'month' for monthly stats.
- rankoptions['timespan'] = 'month';
- // HTML HEX color of the injected stats text for authorized/non authorized users
- rankoptions['color-auth'] = '#FDD017'; // Default #FDD017 (gold)
- rankoptions['color-nonauth'] = '#CCCCCC'; // Default #FFFFFF (white)
- // Position to place stat text relative to top left corner of player name
- // limited to a x/width of 200 and y/height of 45
- rankoptions['position'] = {x: 50, y: 27};
- // Function to wait until game is loaded before pulling stats for players
- function waitUntilGameLoaded()
- {
- // Check if game is loaded and players are inside
- if(typeof tagpro.players !== "undefined" && objectLength(tagpro.players) > 0)
- {
- // Variable to hold the name/value pair playerids and names
- var querystring = "";
- // Loop through all current players in the game and build querystring variable
- for (var pID in tagpro.players)
- {
- // Add player to ranked array so we don't pull stats for them again this game
- ranked[pID] = tagpro.players[pID].name;
- querystring += "player[" + pID + "]=" + encodeURIComponent(tagpro.players[pID].name) + "&";
- }
- // Use the options and the list of players in the game and make an AJAX get request to stats query page/site
- $.get('http://reanimated.net/stats2.php?query=' + rankoptions['query'] + '×pan=' + rankoptions['timespan'] + '&' + querystring, function(data) {
- // Parse returned results as JSON, results are returned key/value of playerid/requested stat
- var results = $.parseJSON(data);
- // Loop through the results and draw the requested stat next to each players ball using the options set above in the script
- for (pID in results)
- {
- tagpro.prettyText(results[pID].replace('N/A', ''), rankoptions['position'].x, rankoptions['position'].y, tagpro.players[pID].auth ? rankoptions['color-auth'] : rankoptions['color-nonauth'], !1, !1, tagpro.players[pID].cache.context);
- }
- });
- // Create a listener on the tagpro socket object for the 'p' event which is used for
- // various aspects of the game but also used when a new player joins the game
- tagpro.socket.on('p', function(data) {
- // Check if the u object exist in the data sent over the p event
- if (typeof data.u !== "undefined")
- {
- // Another check to see if the u object contains a name property which should be enough
- // to indicate we have the object we want for when a new person joins the match
- if (typeof data.u[0].name !== "undefined")
- {
- // For some reason when a user joins the users info is passed 3 times through the p event so we don't want waste resources and
- // time pulling stats for a user that has already had stats pulled from the first time the object passed through the pipe, so
- // we check if our ranked object which we use to store players that have been parsed doesn't contain this player that joined
- if (typeof ranked[data.u[0].id] === "undefined")
- {
- // Player just joine game and hasn't had stats pulled so add them to the list of users already parsed
- ranked[data.u[0].id] = data.u[0].name;
- // Use the options and new players id/name and make an AJAX get request to stats query page/site
- $.get('http://reanimated.net/stats2.php?query=' + rankoptions['query'] + '×pan=' + rankoptions['timespan'] + '&player[' + data.u[0].id + ']=' + encodeURIComponent(data.u[0].name), function(data2) {
- // Parse returned results as JSON, results are returned key/value of playerid/requested stat
- var results = $.parseJSON(data2);
- // Loop through the results and draw the requested stat next to each players ball using the options set above in the script
- for (pID in results)
- {
- tagpro.prettyText(results[pID].replace('N/A', ''), rankoptions['position'].x, rankoptions['position'].y, tagpro.players[pID].auth ? rankoptions['color-auth'] : rankoptions['color-nonauth'], !1, !1, tagpro.players[pID].cache.context);
- }
- });
- }
- }
- }
- // This whole code block is similar to the one above except when your spectating a game a new player joins for some reason there
- // is no u object assocated with the passed data and instead is passed as an array in the first key so we check that first key to
- if (typeof data[0] !== "undefined")
- {
- // See if a player name property exist inside of it to identify if we have the right object we're looking for
- if (typeof data[0].name !== "undefined")
- {
- // For some reason when a user joins the users info is passed 3 times through the p event so we don't want waste resources and
- // time pulling stats for a user that has already had stats pulled from the first time the object passed through the pipe, so
- // we check if our ranked object which we use to store players that have been parsed doesn't contain this player that joined
- if (typeof ranked[data[0].id] === "undefined")
- {
- // Player just joine game and hasn't had stats pulled so add them to the list of users already parsed
- ranked[data[0].id] = data[0].name;
- $.get('http://reanimated.net/stats2.php?query=' + rankoptions['query'] + '×pan=' + rankoptions['timespan'] + '&player[' + data[0].id + ']=' + encodeURIComponent(data[0].name), function(data2) {
- // Parse returned results as JSON, results are returned key/value of playerid/requested stat
- var results = $.parseJSON(data2);
- for (pID in results)
- {
- // Loop through the results and draw the requested stat next to each players ball using the options set above in the script
- tagpro.prettyText(results[pID].replace('N/A', ''), rankoptions['position'].x, rankoptions['position'].y, tagpro.players[pID].auth ? rankoptions['color-auth'] : rankoptions['color-nonauth'], !1, !1, tagpro.players[pID].cache.context);
- }
- });
- }
- }
- }
- });
- }
- else
- {
- // Loop the function to check for game to be loaded every second
- setTimeout(function(){
- waitUntilGameLoaded();
- }, 1000);
- }
- }
- // Call the function to check if game is loaded, players are inside, and execute our custom code
- waitUntilGameLoaded();
- }
- // Inject script into page
- contentEval(rankScript);
- })();
Add Comment
Please, Sign In to add comment