@name FailCake GladosHomeE2
@inputs S:wirelink
@outputs Focus Website:string MaxPercent Percent LUpdate FPercent Update UpTime DATA:string
@persist St:array
@trigger all


## Thanks Bekka for Helping!

if (first()){
    runOnHTTP(1)
    runOnTick(1)

    Website = "http://www.aperturescience.com/glados@home/"
    S:egpClear()    
    hint("Made By FailCake",7)
    St[1,string]="Defense Grid Cpus = "
    St[2,string]="Killing Floor Cpus = "
    St[3,string]="Cogs Cpus = "
    St[4,string]="Rush Cpus = "
    St[5,string]="Toki Tori Cpus = "
    St[6,string]="Bit.Trip.Beat Cpus = "
    St[7,string]="1..2..3 Kick It = "
    St[8,string]="AudioSurf = "
    St[9,string]="The Wonderfull.. Cpus = "
    St[10,string]="Super Meat Boy = "
    St[11,string]="Amnesia = "
    St[12,string]="AAAAAA!! Cpus = "
    St[13,string]="THE BALL = "
    
    Focus = 13
    UpTime = 5000
    timer("redsa",1000)
    timer("ref",100)
}

Update+=0.01


if(clk("redsa")){
httpRequest(Website)  
DATA = httpData()
timer("ref",UpTime)
}


if(clk("ref")){    
    
    LUpdate = floor(Update,2)
    Update = 0
    UpTime = 20000
    
    ID = "potato_count"
    Potatos = DATA:explode("<div id="+ toChar(34) + ID + toChar(34) + ">")
    Potato = Potatos[2, string]
    Potato = Potato:explode("<")[1, string]
    Potato = Potato:trim()
    
    ID2 = "game_cpus"
    Times = DATA:explode("<div class="+ toChar(34) + ID2 + toChar(34) + ">")
    
    ID3 = "overall_progress_ctn"
    Times2 = DATA:explode("<div id="+ toChar(34) + ID3 + toChar(34) + ">")
    
    Left = Times2[2, string]
    Left = Left:explode("width:")[2, string]
    Left = Left:explode("px")[1, string]
    Left = Left:trim()
    Num = Left:toNumber()
    
   S:egpRoundedBoxOutline(16,vec2(250,345),vec2(350,20))
   S:egpColor(16,vec(255,255,255))

    S:egpText(29, "Last Updated : " + LUpdate + " Seconds Ago." , vec2(10,440))
    S:egpText(25, "Following : " + Website , vec2(10,460))
    S:egpText(28, "Made By FailCake", vec2(10,480))
    S:egpColor(28,vec(255,155,0))
    S:egpText(14, "---- Potato count: " + Potato + " ----", vec2(140,0)) 
    S:egpColor(14,vec(255,0,0))
    
    S:egpText(15, "---- Total Percent ----", vec2(180,300)) 
    S:egpColor(15,vec(255,0,0))
    
    MaxPercent = 494
    Percent = Num/494*100
    FPercent = Percent/100*345
    
    timer("ref",UpTime)
if(Percent <= MaxPercent){
    S:egpRoundedBox(17,vec2(FPercent/1.3,345),vec2(FPercent,17))
    S:egpColor(17,vec(255,80,0))  
    S:egpText(19,floor(Percent,2) + "%",vec2(240,335))
    S:egpColor(19,vec(1,1,1))   
}
   
    for(I=1,13){

    CPU = Times[I+1, string]
    CPU = CPU:explode("</div>")[1, string]
    CPU = CPU:trim()

    S:egpText(I, St[I,string] + CPU, vec2(10,I*20)) 

    if(CPU == "COMPUTATIONS COMPLETE"){
    S:egpColor(I,vec(0,255,0)) 
    }else{
    if(Focus != I){
    S:egpColor(I,vec(255,255,255))
}else{
S:egpColor(I,vec(255,255,0))
} 
}
    }


}


