[ create a new paste ] login | about

Link: http://codepad.org/z7cxw2GX    [ raw code | fork ]

meigrafd - Plain Text, pasted on May 1:
if (typeof(String.prototype.strip) === "undefined") {
    String.prototype.strip = function() {
        return String(this).replace(/^\s+|\s+$/g, '');
    };
}

function isset(strVariableName) { 
    try { 
        eval( strVariableName );
    } catch( err ) { 
        if ( err instanceof ReferenceError ) 
            return false;
    }
    return true;
}

function sleep(millis, callback) {
    setTimeout(function() { callback(); } , millis);
}

//source of: http://www.html5tutorial.info/html5-range.php
function printValue(sliderID, textbox) {
    var x = document.getElementById(textbox);
    var y = document.getElementById(sliderID);
    x.value = y.value;
}


function mylog(message) {
    if (isset(DEBUG) && DEBUG == 1) {
        console.log(message);
        var logthingy;
        logthingy = document.getElementById("Log");
        if( logthingy.innerHTML.length > 5000 )
            logthingy.innerHTML = logthingy.innerHTML.slice(logthingy.innerHTML.length-5000);
        logthingy.innerHTML = logthingy.innerHTML+"<br/>"+message;
        logthingy.scrollTop = logthingy.scrollHeight*2;
    }
}

//----------------------------------------------------------------

/*
var telemetryTimer;
$(document).ready(function() {
    // start Main Timers
    telemetryTimer = setTimeout(get_telemetry, 1000);
});
*/

function Send(command) {
    $.ajax({
        type: "GET",
        url: "/cmd/" + command,
        async: true,
        dataType: "JSON",
        success: function(obj) {
            console.log("JSON Data: " + obj.ID + ":" + obj.value);
            document.getElementById(obj.ID).innerHTML = obj.value;
        },
    });
}

function get_telemetry() {
    $.getJSON("/data/")
    .fail(function() {
        console.log("Error processing get_telemetry");
        clearTimeout(telemetryTimer);
    })
    .done(function(data) {
        $.each(data, function(id,val) {
            if (document.getElementById(id) !== null) {
                console.log("JSON Data: " + id + ":" + val);

                if (id == "LoadAVGnum") {
                    document.getElementById(id).innerHTML = val + "%";
                } else if (id == "LoadAVGperc") {
                    document.getElementById(id).value = val;
                } else if (id == "RAMnum") {
                    document.getElementById(id).innerHTML = val + "MB";
                } else if (id == "RAMperc") {
                    document.getElementById(id).value = val;

                } else {
                    document.getElementById(id).innerHTML = val;
                }
            }
        })
        telemetryTimer = setTimeout(get_telemetry, 2000);
    });
}

function parseResponse(requestlist) {
    //mylog("Parsing: "+requestlist)
    for (var i=0; i<requestlist.length; i++) {
        var requestsplit = requestlist[i].strip().split(':')
        requestsplit[requestsplit.length] = "dummy";
        command = requestsplit[0];
        val = requestsplit[1];
        val2 = requestsplit[2];

        if (command == "LoadAVGnum") {
            document.getElementById("LoadAVGnum").innerHTML = val + "%";
        } else if (command == "LoadAVGperc") {
            document.getElementById("LoadAVGperc").value = val;
        } else if (command == "RAMnum") {
            document.getElementById("RAMnum").innerHTML = val + "MB";
        } else if (command == "RAMperc") {
            document.getElementById("RAMperc").value = val;
        }

    }
}


Create a new paste based on this one


Comments: