Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var resizeTimeout=null;
- var version="0.300";
- function init()
- {
- if (arguments.callee.done)
- {
- return;
- }
- arguments.callee.done = true;
- if (_timer)
- {
- clearInterval(_timer);
- }
- document.title = "\xb5Torrent WebUI v"+version;
- window.onresize = function(e)
- {
- if (browser.isIE && (resizing==false))
- {
- if (resizeTimeout!=null)
- {
- window.clearTimeout(resizeTimeout);
- }
- resizeTimeout=window.setTimeout("resizeUI()",500);
- }
- else
- {
- resizeUI();
- }
- };
- if (browser.isIE && !browser.isIE7x)
- {
- $("List").style.width="99%";
- }
- utWebUI.init();
- var _2=new Array();
- var _3= [ {"text":"Name","width":"200px","type":TYPE_STRING},
- {"text":"Status","width":"100px","type":TYPE_STRING},
- {"text":"Size","width":"60px","type":TYPE_NUMBER},
- {"text":"Done","width":"80px","type":TYPE_NUMBER},
- {"text":"Downloaded","width":"100px","type":TYPE_NUMBER},
- {"text":"Uploaded","width":"80px","type":TYPE_NUMBER},
- {"text":"Ratio","width":"60px","type":TYPE_NUMBER},
- {"text":"DL","width":"60px","type":TYPE_NUMBER},
- {"text":"UL","width":"60px","type":TYPE_NUMBER},
- {"text":"ETA","width":"60px","type":TYPE_NUMBER},
- {"text":"Label","width":"60px","type":TYPE_STRING},
- {"text":"Peers","width":"60px","type":TYPE_NUMBER},
- {"text":"Seeds","width":"60px","type":TYPE_NUMBER},
- {"text":"Avail.","width":"60px","type":TYPE_NUMBER},
- {"text":"#","width":"30px","type":TYPE_NUMBER,
- "align":ALIGN_LEFT},
- {"text":"Remaining","width":"90px","type":TYPE_NUMBER}];
- var ol=$("List");
- utWebUI.trtTable.format = FormatTL;
- utWebUI.trtTable.create(ol,_3);
- utWebUI.trtTable.reverse = utWebUI.trtSortR;
- Update();
- resizeUI();
- }
- if (document.addEventListener)
- {
- document.addEventListener("DOMContentLoaded",init,false);
- }
- if (/WebKit/i.test(navigator.userAgent))
- {
- var _timer = setInterval( function(){
- if (/loaded|complete/.test(document.readyState))
- {
- init();
- }
- },10);
- }
- window.onload = init;
- function resizeUI()
- {
- resizing = true;
- window.clearTimeout(resizeTimeout);
- var ww = getWindowWidth(),wh = getWindowHeight();
- utWebUI.trtTable.resize(ww-13,wh-13);
- resizing=false;
- }
- function Update()
- {
- utWebUI.getTorrents("list=1");
- tdl = 0;
- tul = 0;
- }
- function UpdateStatus()
- {
- if ((tdl == 0) && (tul == 0))
- {
- return;
- }
- var s = "Download: " + ffs(tdl)+"/s | Upload: "+ffs(tul)+"/s";
- if(utWebUI.bSpdDis==1)
- {
- window.status=s;
- window.defaultStatus=s;
- }
- else
- {
- if (utWebUI.bSpdDis==2)
- {
- document.title="\xb5Torrent WebUI v"+version+" - "+s;
- }
- }
- }
- function FormatTL(_7,_8)
- {
- if (_8==null)
- {
- _7[2]=ffs(_7[2],2);
- _7[3]=(_7[3]/10)+"%";
- _7[4]=ffs(_7[4]);
- _7[5]=ffs(_7[5]);
- _7[6]=(_7[6]==-1)?"\u221e":round(_7[6]/1000,3);
- _7[7]=ffs(_7[7])+"/s";
- _7[8]=ffs(_7[8])+"/s";
- _7[9]=(_7[9]<=-1)?"\u221e":ft(_7[9]);
- _7[13]=round(_7[13]/65535,3);
- _7[14]=(_7[14]<=-1)?"*":_7[14];
- _7[15]=ffs(_7[15],2);
- }
- else
- {
- switch(_8)
- {
- case 2:
- _7=ffs(_7,2);
- break;
- case 3:
- _7=(_7/10)+"%";
- break;
- case 4:
- _7=ffs(_7);
- break;
- case 5:
- _7=ffs(_7);
- break;
- case 6:
- _7=(_7==-1)?"\u221e":round(_7/1000,3);
- break;
- case 7:
- _7=ffs(_7)+"/s";
- break;
- case 8:
- _7=ffs(_7)+"/s";
- break;
- case 9:
- _7=(_7<=-1)?"\u221e":ft(_7);
- break;
- case 13:
- "value", _7=round(_7/65535,3);
- break;
- case 14:
- _7=(_7<=-1)?"*":_7;
- break;
- case 15:
- _7=ffs(_7,2);
- break;
- }
- }
- return _7;
- }
- function getStatusIcon(_9,_a)
- {
- var _b="",status="";
- if (_9&1)
- {
- if (_9&32)
- {
- _b="Status_Paused";
- status="Pausing";
- }
- else
- {
- b=(_a==1000)?"Status_Up":"Status_Down";
- status=(_a==1000)?"Seeding":"Downloading";
- }
- }
- else
- {
- if (_9&2)
- {
- _b="Status_Checking";
- if (_9&32)
- {
- _b="Status_Paused";
- }
- status="Checking";
- }
- else
- {
- if (_9&16)
- {
- _b="Status_Error";
- status="Error";
- }
- else
- {
- if (_9&64)
- {
- _b=(_a==1000)?"Status_Queued_Up":"Status_Queued_Down";
- status="Queued";
- }
- }
- }
- }
- if (!(_9&64))
- {
- status+=" [F]";
- }
- if ((_a==1000) && (_b==""))
- {
- _b="Status_Completed";
- status="Finished";
- }
- if ((_a<1000) && (_b==""))
- {
- _b="Status_Incompleted";
- status="Stopped";
- }
- return [_b,status];
- }
- var utWebUI=new Object();
- utWebUI=
- {
- "init":function()
- {
- this.torrents=new Object();
- this.dID="";
- this.trtTable=new dxSTable();
- this.url=window.location.protocol+"//"+document.domain+":"+location.host.split(":")[1]+"/gui/";
- this.timer=new Timer();
- this.update=null;
- this.interval=-1;
- this.iLoad=true;
- this.cID="";
- this.bAltCol=0;
- this.bSpdDis=0;
- this.isLoading=false;
- this.noUpdate=false;
- this.pID="";
- this.trtSortR=0;
- this.minRows=50;
- this.updateInterval=3000;
- },
- "Request":function(qs,_d,_e)
- {
- new Ajax(
- this.url+qs,"GET",_e,_d,function()
- {
- utWebUI.Timeout();
- },
- 10000);
- },
- "Timeout":function()
- {
- alert("The request to \xb5Torrent has timed out.");
- },
- "getTorrents":function(qs)
- {
- if (this.update)
- {
- window.clearTimeout(this.update);
- }
- this.timer.start();
- if (qs!="list=1")
- {
- qs="action="+qs;
- }
- qs = (this.cID=="")?qs:(qs+"&cid="+this.cID);
- this.Request("?"+qs,[this.addTorrents,this]);
- },
- "addTorrents":function(_10)
- {
- var d=eval("("+_10+")");
- if (typeof d.torrents == "undefined")
- {
- d.torrents=new Array(d.torrentp.length);
- d.torrents=d.torrentp;
- }
- var i,l=d.torrents.length;
- this.noUpdate=true;
- var sl=this.trtTable.dBody.scrollLeft;
- for(i=0;
- i<l;
- i++)
- {
- var _14=d.torrents[i];
- var sId=_14[0];
- var _16=_14[1];
- var _17=_14[4];
- var _18=getStatusIcon(_16,_17);
- var _19=_18[0];
- var t=_14[8];
- _14[8]=_14[9];
- _14[9]=t;
- tdl+=_14[8];
- tul+=_14[9];
- _14.splice(3,0,_18[1]);
- if (typeof (this.torrents[sId]) == "undefined")
- {
- this.torrents[sId]=_14.slice(1);
- _14.splice(0,2);
- _14[11]=_14[11]+" ("+_14[12]+")";
- _14[12]=_14[13]+" ("+_14[14]+")";
- _14[13]=_14[15];
- _14.splice(13,2);
- this.trtTable.addRow(_14,sId,_19);
- this.noUpdate=false;
- }
- else
- {
- var ln=_14.length-7;
- var aD=this.torrents[sId];
- if ((aD[0] != _14[1]) || (aD[3] != _14[4]))
- {
- this.torrents[sId][0]=_14[1];
- this.trtTable.setIcon(sId,_19);
- this.trtTable.setValue(sId,1,_18[1]);
- }
- if ((aD[12] != _14[13]) || (aD[13] != _14[14]))
- {
- this.torrents[sId][12] = _14[13];
- this.torrents[sId][13] = _14[14];
- this.trtTable.setValue(sId,11,_14[13]+" ("+_14[14]+")");
- this.noUpdate=false;
- }
- if ((aD[14] != _14[15]) || (aD[15] != _14[16]))
- {
- this.torrents[sId][14] = _14[15];
- this.torrents[sId][15]=_14[16];
- this.trtTable.setValue(sId,12,_14[15]+" ("+_14[16]+")");
- this.noUpdate=false;
- }
- for (var j=16; j<20; j++)
- {
- if (aD[j]!=_14[j+1])
- {
- this.noUpdate=false;
- this.torrents[sId][j]=_14[j+1];
- this.trtTable.setValue(sId,j-3,_14[j+1]);
- }
- }
- for(var j=1; j<ln; j++)
- {
- if (aD[j]!=_14[j+1])
- {
- this.noUpdate=false;
- this.torrents[sId][j]=_14[j+1];
- if ((j==4) && (this.dID == sId))
- {
- this.updateFiles(sId);
- }
- this.trtTable.setValue(sId,j-1,_14[j+1]);
- }
- }
- }_14=null;
- }
- this.trtTable.dBody.scrollLeft=sl;
- },
- "loadTorrents": function()
- {
- if (this.iLoad)
- {
- this.iLoad=false;
- this.trtTable.calcSize();
- }
- if ((this.trtTable.sIndex!=-1) && !this.noUpdate)
- {
- this.trtTable.Sort();
- }
- this.setInterval();
- this.update=window.setTimeout("Update()",this.interval);
- this.noUpdate=false;
- },
- "setInterval": function()
- {
- this.timer.stop();
- if(this.interval==-1)
- {
- this.interval = this.updateInterval + this.timer.interval*4;
- }
- else
- {
- this.interval = parseInt((this.interval+this.updateInterval+this.timer.interval*4)/2);
- }
- }
- };
Add Comment
Please, Sign In to add comment