TF2 Center powah' counter

Count total hours played for each team.

  1. // ==UserScript==
  2. // @name TF2 Center powah' counter
  3. // @namespace http://www.janhouse.lv/
  4. // @description Count total hours played for each team.
  5. // @include http://tf2center.com/lobbies/*
  6. // @version 2
  7. // @grant none
  8. // ==/UserScript==
  9.  
  10. var $ = unsafeWindow.jQuery; // Use their jQuery
  11.  
  12. var skillThreshold=1500; // Players below 1000 played hours will get more red. Above it - more green.
  13.  
  14. function updateStats(){
  15. //console.log("tick");
  16. // Add info boxes
  17. $(".blue-team, .red-team").each(function(){
  18. if(!$(this).find(".statZ").length){
  19. //console.log("lost");
  20. $(this).find(".teamName").after("<span style='top: 15px;position: relative;left: 14px;font-size: 14px;color: #E8E5D5' class='statZ'></span>");
  21. }
  22. });
  23. // Calculate team powah'
  24. $(".blue-team, .red-team").each(function(){
  25. var count=0;
  26. var size=0
  27. //console.log("team");
  28. // Get stats for each player
  29. $(this).find(".playerSlot > .details > .statsContainer > .hours").next("span.darkgrey").each(function(){
  30. count=count+parseInt($(this).text().trim(), 10);
  31. size++;
  32. });
  33. // Color players based on play time
  34. $(this).find(".playerSlot.filled").each(function(){
  35. var hours=parseInt($(this).find(".details > .statsContainer > .hours").next("span.darkgrey").text().trim(), 10);
  36. // "Magic" "formula"
  37. if(hours < skillThreshold){
  38. $(this).css({"background-color": "rgba(255, 0, 0, "+(((-skillThreshold+hours)*-1) / 10000 )+")"});
  39. }else{
  40. $(this).css({"background-color": "rgba(0, 255, 0, "+(hours/20000)+")"});
  41. }
  42. });
  43.  
  44. // Average powah'?
  45. var avg = count/size;
  46. var avgF=avg.toFixed(2);
  47. // Team average powah color
  48. if(avgF < skillThreshold){
  49. tColor="rgba(255, 0, 0, "+(((-skillThreshold+parseInt(avgF, 10))*-1) / 10000 )+")";
  50. }else{
  51. tColor="rgba(0, 255, 0, "+(avgF/13000)+")";
  52. }
  53. //console.log(count);
  54. $(this).find(".statZ").html("Powah: "+count+", Avg: <span style='background-color: "+tColor+"'>"+avgF+"</span>");
  55.  
  56. });
  57. }
  58.  
  59. $(document).ready(function() {
  60.  
  61. // Tweak css for nick background changes
  62. $("#mainContent").before("<style>.statsContainer .darkgrey{color: rgba(183, 183, 183, 0.8);} .playerSlot .details .name {color: rgba(233, 233, 233, 0.8);}</style>");
  63.  
  64. // Do it once in 5 sec.
  65. var i = window.setInterval( function(){
  66. updateStats();
  67. }, 5000 );
  68. updateStats();
  69. });