TF2 Center powah' counter

Count total hours played for each team.

当前为 2015-05-02 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        TF2 Center powah' counter
// @namespace   http://www.janhouse.lv/
// @description Count total hours played for each team.
// @include     http://tf2center.com/lobbies/*
// @version     2
// @grant       none
// ==/UserScript==

var $ = unsafeWindow.jQuery; // Use their jQuery

var skillThreshold=1500; // Players below 1000 played hours will get more red. Above it - more green.

function updateStats(){
    
    //console.log("tick");
    
    // Add info boxes
    $(".blue-team, .red-team").each(function(){
        if(!$(this).find(".statZ").length){
            //console.log("lost");
           $(this).find(".teamName").after("<span style='top: 15px;position: relative;left: 14px;font-size: 14px;color: #E8E5D5' class='statZ'></span>");
        }
    });
    
    // Calculate team powah'
    $(".blue-team, .red-team").each(function(){
        var count=0;
        var size=0
        //console.log("team");
        
        // Get stats for each player
        $(this).find(".playerSlot > .details > .statsContainer > .hours").next("span.darkgrey").each(function(){
           count=count+parseInt($(this).text().trim(), 10);
           size++;
        });
       
        // Color players based on play time
        $(this).find(".playerSlot.filled").each(function(){
            
            var hours=parseInt($(this).find(".details > .statsContainer > .hours").next("span.darkgrey").text().trim(), 10);
            
            // "Magic" "formula"
            if(hours < skillThreshold){
               $(this).css({"background-color": "rgba(255, 0, 0, "+(((-skillThreshold+hours)*-1) / 10000 )+")"});
            }else{
                $(this).css({"background-color": "rgba(0, 255, 0, "+(hours/20000)+")"});
            }
        });

        // Average powah'?
        var avg = count/size;
        var avgF=avg.toFixed(2);
        
        // Team average powah color
        if(avgF < skillThreshold){
            tColor="rgba(255, 0, 0, "+(((-skillThreshold+parseInt(avgF, 10))*-1) / 10000 )+")";
        }else{
            tColor="rgba(0, 255, 0, "+(avgF/13000)+")";
        }
        
        //console.log(count);
        $(this).find(".statZ").html("Powah: "+count+", Avg: <span style='background-color: "+tColor+"'>"+avgF+"</span>");

    });
    
}

$(document).ready(function() {  

    // Tweak css for nick background changes
    $("#mainContent").before("<style>.statsContainer .darkgrey{color: rgba(183, 183, 183, 0.8);} .playerSlot .details .name {color: rgba(233, 233, 233, 0.8);}</style>");

    // Do it once in 5 sec.
    var i = window.setInterval( function(){ 
       updateStats();
    }, 5000 );
    updateStats();
    
});