[操作疑難] [已解決] 新手請教windows sidebar gadget可否修改?

本帖最後由 sunny6382 於 2012-5-22 03:07 編輯

唔知有冇貼錯區,有的話請版主更正.
現有這sidebar gadget可顯示網速上下載,但只能顯示整數,請問可否將它改成能讀取到點數位,例如 1.23 MB
Thx


js file :

//////////////////////////////////////////////////////////
//
//  Network Performance Gadget
//
//////////////////////////////////////////////////////////

//
//  Globals
//
var server = GetObject( "winmgmts:" );
var refresher = new ActiveXObject("WbemScripting.SWbemRefresher");
var items = refresher.AddEnum( server, "Win32_PerfFormattedData_Tcpip_NetworkInterface").ObjectSet;
var maxSpeed = 0;

//
//  Initialize and start worker psudo thread
//
function Start()
{
   System.Gadget.settingsUI = "Settings.html";

   TX.innerText = "";
   RX.innerText = "";
   WorkerThread();
}

//
//  Where all the magic happens
//
function WorkerThread()
{
    // Set network card name
    NetworkCardName.innerText = System.Gadget.Settings.read("selectedItem");

    // Refresh WMI collection
    refresher.Refresh();
   
    // Get enumator from WMI item collection
    var e = new Enumerator( items );
   
    for(; !e.atEnd(); e.moveNext() )
    {
        // If user has not selected a network card default to the first one
        if( NetworkCardName.innerText == "" )
        {
            NetworkCardName.innerText = e.item().Name;
        }
   
        // Update data for currently selected network card
        if( e.item().Name == NetworkCardName.innerText )
        {
            // Compute input/output speeds in KB per second
            var inSpeed  = Math.round( e.item().BytesReceivedPersec / 1024 );
            var outSpeed = Math.round( e.item().BytesSentPersec / 1024 )
            
            // Push up the max speed bar if new record is acheived
            if( inSpeed > maxSpeed ) maxSpeed = inSpeed;
            if( outSpeed > maxSpeed ) maxSpeed = outSpeed;
            
            // Set text to MB or KB depending on value
            RX.innerText = (inSpeed  > 1024 ? ( Math.round( inSpeed / 1024 )  + " MB" ) : inSpeed  + " KB");
            TX.innerText = (outSpeed > 1024 ? ( Math.round( outSpeed / 1024 ) + " MB" ) : outSpeed + " KB");
            
            // Set the colored bar to the correct width based on current speed vr. max speed
            RXBar.style.width = (inSpeed == 0 && maxSpeed == 0) ? "0%" : ((inSpeed / maxSpeed)  * 100 + "%");
            TXBar.style.width = (outSpeed == 0 && maxSpeed == 0) ? "0%" : ((outSpeed / maxSpeed) * 100 + "%");
        }
    }       
   
    // Call us again
    if( System.Gadget.Settings.read("intervalItem") == "" )
    {
        setTimeout("WorkerThread()", 1000);
    } else {
        setTimeout("WorkerThread()", System.Gadget.Settings.read("intervalItem"));
    }
}
附件: 您需要登錄才可以下載或查看附件。沒有帳號?註冊

This isn't a 程式編寫 problem at all...

Anyway, look for Math.round.

TOP

回復 2# domeso
謝謝師兄回覆
Math.round.我都唔識.

TOP

回復 3# sunny6382


First result from Google search is the answer ma...

https://www.google.com.hk/search?q=Math.round

TOP

本帖最後由 sunny6382 於 2012-5-22 03:11 編輯

回復 4# domeso
其實我之前都google過Math.round,但因本身唔識,所以睇極都唔明.剛才再睇下,亂打亂撞終於改好了,唔該晒你師兄.
Thx alot

TOP

回復 5# sunny6382


    Simple isn't it?
Search is always good to learn, hahaha...

TOP

回復 6# domeso
anyway, many thanks !

TOP