Guest User

Untitled

a guest
Feb 21st, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.03 KB | None | 0 0
  1. var resizeTimeout=null;
  2. var version="0.300";
  3.  
  4. function init()
  5. {
  6. if (arguments.callee.done)
  7. {
  8. return;
  9. }
  10.  
  11. arguments.callee.done = true;
  12.  
  13. if (_timer)
  14. {
  15. clearInterval(_timer);
  16. }
  17.  
  18. document.title = "\xb5Torrent WebUI v"+version;
  19.  
  20. window.onresize = function(e)
  21. {
  22. if (browser.isIE && (resizing==false))
  23. {
  24. if (resizeTimeout!=null)
  25. {
  26. window.clearTimeout(resizeTimeout);
  27. }
  28. resizeTimeout=window.setTimeout("resizeUI()",500);
  29. }
  30. else
  31. {
  32. resizeUI();
  33. }
  34. };
  35.  
  36. if (browser.isIE && !browser.isIE7x)
  37. {
  38. $("List").style.width="99%";
  39. }
  40.  
  41. utWebUI.init();
  42. var _2=new Array();
  43. var _3= [ {"text":"Name","width":"200px","type":TYPE_STRING},
  44. {"text":"Status","width":"100px","type":TYPE_STRING},
  45. {"text":"Size","width":"60px","type":TYPE_NUMBER},
  46. {"text":"Done","width":"80px","type":TYPE_NUMBER},
  47. {"text":"Downloaded","width":"100px","type":TYPE_NUMBER},
  48. {"text":"Uploaded","width":"80px","type":TYPE_NUMBER},
  49. {"text":"Ratio","width":"60px","type":TYPE_NUMBER},
  50. {"text":"DL","width":"60px","type":TYPE_NUMBER},
  51. {"text":"UL","width":"60px","type":TYPE_NUMBER},
  52. {"text":"ETA","width":"60px","type":TYPE_NUMBER},
  53. {"text":"Label","width":"60px","type":TYPE_STRING},
  54. {"text":"Peers","width":"60px","type":TYPE_NUMBER},
  55. {"text":"Seeds","width":"60px","type":TYPE_NUMBER},
  56. {"text":"Avail.","width":"60px","type":TYPE_NUMBER},
  57. {"text":"#","width":"30px","type":TYPE_NUMBER,
  58. "align":ALIGN_LEFT},
  59. {"text":"Remaining","width":"90px","type":TYPE_NUMBER}];
  60.  
  61. var ol=$("List");
  62. utWebUI.trtTable.format = FormatTL;
  63. utWebUI.trtTable.create(ol,_3);
  64. utWebUI.trtTable.reverse = utWebUI.trtSortR;
  65. Update();
  66. resizeUI();
  67. }
  68.  
  69. if (document.addEventListener)
  70. {
  71. document.addEventListener("DOMContentLoaded",init,false);
  72. }
  73.  
  74. if (/WebKit/i.test(navigator.userAgent))
  75. {
  76. var _timer = setInterval( function(){
  77. if (/loaded|complete/.test(document.readyState))
  78. {
  79. init();
  80. }
  81. },10);
  82. }
  83. window.onload = init;
  84.  
  85. function resizeUI()
  86. {
  87. resizing = true;
  88. window.clearTimeout(resizeTimeout);
  89. var ww = getWindowWidth(),wh = getWindowHeight();
  90. utWebUI.trtTable.resize(ww-13,wh-13);
  91. resizing=false;
  92. }
  93.  
  94. function Update()
  95. {
  96. utWebUI.getTorrents("list=1");
  97. tdl = 0;
  98. tul = 0;
  99. }
  100.  
  101. function UpdateStatus()
  102. {
  103. if ((tdl == 0) && (tul == 0))
  104. {
  105. return;
  106. }
  107.  
  108. var s = "Download: " + ffs(tdl)+"/s | Upload: "+ffs(tul)+"/s";
  109.  
  110. if(utWebUI.bSpdDis==1)
  111. {
  112. window.status=s;
  113. window.defaultStatus=s;
  114. }
  115. else
  116. {
  117. if (utWebUI.bSpdDis==2)
  118. {
  119. document.title="\xb5Torrent WebUI v"+version+" - "+s;
  120. }
  121. }
  122. }
  123.  
  124. function FormatTL(_7,_8)
  125. {
  126. if (_8==null)
  127. {
  128. _7[2]=ffs(_7[2],2);
  129. _7[3]=(_7[3]/10)+"%";
  130. _7[4]=ffs(_7[4]);
  131. _7[5]=ffs(_7[5]);
  132. _7[6]=(_7[6]==-1)?"\u221e":round(_7[6]/1000,3);
  133. _7[7]=ffs(_7[7])+"/s";
  134. _7[8]=ffs(_7[8])+"/s";
  135. _7[9]=(_7[9]<=-1)?"\u221e":ft(_7[9]);
  136. _7[13]=round(_7[13]/65535,3);
  137. _7[14]=(_7[14]<=-1)?"*":_7[14];
  138. _7[15]=ffs(_7[15],2);
  139. }
  140. else
  141. {
  142. switch(_8)
  143. {
  144. case 2:
  145. _7=ffs(_7,2);
  146. break;
  147. case 3:
  148. _7=(_7/10)+"%";
  149. break;
  150. case 4:
  151. _7=ffs(_7);
  152. break;
  153. case 5:
  154. _7=ffs(_7);
  155. break;
  156. case 6:
  157. _7=(_7==-1)?"\u221e":round(_7/1000,3);
  158. break;
  159. case 7:
  160. _7=ffs(_7)+"/s";
  161. break;
  162. case 8:
  163. _7=ffs(_7)+"/s";
  164. break;
  165. case 9:
  166. _7=(_7<=-1)?"\u221e":ft(_7);
  167. break;
  168. case 13:
  169. "value", _7=round(_7/65535,3);
  170. break;
  171. case 14:
  172. _7=(_7<=-1)?"*":_7;
  173. break;
  174. case 15:
  175. _7=ffs(_7,2);
  176. break;
  177. }
  178. }
  179. return _7;
  180. }
  181.  
  182. function getStatusIcon(_9,_a)
  183. {
  184. var _b="",status="";
  185. if (_9&1)
  186. {
  187. if (_9&32)
  188. {
  189. _b="Status_Paused";
  190. status="Pausing";
  191. }
  192. else
  193. {
  194. b=(_a==1000)?"Status_Up":"Status_Down";
  195. status=(_a==1000)?"Seeding":"Downloading";
  196. }
  197. }
  198. else
  199. {
  200. if (_9&2)
  201. {
  202. _b="Status_Checking";
  203. if (_9&32)
  204. {
  205. _b="Status_Paused";
  206. }
  207.  
  208. status="Checking";
  209. }
  210. else
  211. {
  212. if (_9&16)
  213. {
  214. _b="Status_Error";
  215. status="Error";
  216. }
  217. else
  218. {
  219. if (_9&64)
  220. {
  221. _b=(_a==1000)?"Status_Queued_Up":"Status_Queued_Down";
  222. status="Queued";
  223. }
  224. }
  225. }
  226. }
  227.  
  228. if (!(_9&64))
  229. {
  230. status+=" [F]";
  231. }
  232.  
  233. if ((_a==1000) && (_b==""))
  234. {
  235. _b="Status_Completed";
  236. status="Finished";
  237. }
  238.  
  239. if ((_a<1000) && (_b==""))
  240. {
  241. _b="Status_Incompleted";
  242. status="Stopped";
  243. }
  244.  
  245. return [_b,status];
  246. }
  247.  
  248. var utWebUI=new Object();
  249. utWebUI=
  250. {
  251. "init":function()
  252. {
  253. this.torrents=new Object();
  254. this.dID="";
  255. this.trtTable=new dxSTable();
  256. this.url=window.location.protocol+"//"+document.domain+":"+location.host.split(":")[1]+"/gui/";
  257. this.timer=new Timer();
  258. this.update=null;
  259. this.interval=-1;
  260. this.iLoad=true;
  261. this.cID="";
  262. this.bAltCol=0;
  263. this.bSpdDis=0;
  264. this.isLoading=false;
  265. this.noUpdate=false;
  266. this.pID="";
  267. this.trtSortR=0;
  268. this.minRows=50;
  269. this.updateInterval=3000;
  270. },
  271.  
  272. "Request":function(qs,_d,_e)
  273. {
  274. new Ajax(
  275. this.url+qs,"GET",_e,_d,function()
  276. {
  277. utWebUI.Timeout();
  278. },
  279. 10000);
  280. },
  281.  
  282. "Timeout":function()
  283. {
  284. alert("The request to \xb5Torrent has timed out.");
  285. },
  286.  
  287. "getTorrents":function(qs)
  288. {
  289. if (this.update)
  290. {
  291. window.clearTimeout(this.update);
  292. }
  293.  
  294. this.timer.start();
  295. if (qs!="list=1")
  296. {
  297. qs="action="+qs;
  298. }
  299. qs = (this.cID=="")?qs:(qs+"&cid="+this.cID);
  300. this.Request("?"+qs,[this.addTorrents,this]);
  301. },
  302.  
  303. "addTorrents":function(_10)
  304. {
  305. var d=eval("("+_10+")");
  306. if (typeof d.torrents == "undefined")
  307. {
  308. d.torrents=new Array(d.torrentp.length);
  309. d.torrents=d.torrentp;
  310. }
  311.  
  312. var i,l=d.torrents.length;
  313. this.noUpdate=true;
  314. var sl=this.trtTable.dBody.scrollLeft;
  315. for(i=0;
  316. i<l;
  317. i++)
  318. {
  319. var _14=d.torrents[i];
  320. var sId=_14[0];
  321. var _16=_14[1];
  322. var _17=_14[4];
  323. var _18=getStatusIcon(_16,_17);
  324. var _19=_18[0];
  325. var t=_14[8];
  326. _14[8]=_14[9];
  327. _14[9]=t;
  328. tdl+=_14[8];
  329. tul+=_14[9];
  330. _14.splice(3,0,_18[1]);
  331. if (typeof (this.torrents[sId]) == "undefined")
  332. {
  333. this.torrents[sId]=_14.slice(1);
  334. _14.splice(0,2);
  335. _14[11]=_14[11]+" ("+_14[12]+")";
  336. _14[12]=_14[13]+" ("+_14[14]+")";
  337. _14[13]=_14[15];
  338. _14.splice(13,2);
  339. this.trtTable.addRow(_14,sId,_19);
  340. this.noUpdate=false;
  341. }
  342. else
  343. {
  344. var ln=_14.length-7;
  345. var aD=this.torrents[sId];
  346. if ((aD[0] != _14[1]) || (aD[3] != _14[4]))
  347. {
  348. this.torrents[sId][0]=_14[1];
  349. this.trtTable.setIcon(sId,_19);
  350. this.trtTable.setValue(sId,1,_18[1]);
  351. }
  352.  
  353. if ((aD[12] != _14[13]) || (aD[13] != _14[14]))
  354. {
  355. this.torrents[sId][12] = _14[13];
  356. this.torrents[sId][13] = _14[14];
  357. this.trtTable.setValue(sId,11,_14[13]+" ("+_14[14]+")");
  358. this.noUpdate=false;
  359. }
  360.  
  361. if ((aD[14] != _14[15]) || (aD[15] != _14[16]))
  362. {
  363. this.torrents[sId][14] = _14[15];
  364. this.torrents[sId][15]=_14[16];
  365. this.trtTable.setValue(sId,12,_14[15]+" ("+_14[16]+")");
  366. this.noUpdate=false;
  367. }
  368.  
  369. for (var j=16; j<20; j++)
  370. {
  371. if (aD[j]!=_14[j+1])
  372. {
  373. this.noUpdate=false;
  374. this.torrents[sId][j]=_14[j+1];
  375. this.trtTable.setValue(sId,j-3,_14[j+1]);
  376. }
  377. }
  378.  
  379. for(var j=1; j<ln; j++)
  380. {
  381. if (aD[j]!=_14[j+1])
  382. {
  383. this.noUpdate=false;
  384. this.torrents[sId][j]=_14[j+1];
  385. if ((j==4) && (this.dID == sId))
  386. {
  387. this.updateFiles(sId);
  388. }
  389. this.trtTable.setValue(sId,j-1,_14[j+1]);
  390. }
  391. }
  392. }_14=null;
  393. }
  394. this.trtTable.dBody.scrollLeft=sl;
  395. },
  396.  
  397. "loadTorrents": function()
  398. {
  399. if (this.iLoad)
  400. {
  401. this.iLoad=false;
  402. this.trtTable.calcSize();
  403. }
  404.  
  405. if ((this.trtTable.sIndex!=-1) && !this.noUpdate)
  406. {
  407. this.trtTable.Sort();
  408. }
  409.  
  410. this.setInterval();
  411. this.update=window.setTimeout("Update()",this.interval);
  412. this.noUpdate=false;
  413. },
  414.  
  415. "setInterval": function()
  416. {
  417. this.timer.stop();
  418. if(this.interval==-1)
  419. {
  420. this.interval = this.updateInterval + this.timer.interval*4;
  421. }
  422. else
  423. {
  424. this.interval = parseInt((this.interval+this.updateInterval+this.timer.interval*4)/2);
  425. }
  426. }
  427. };
Add Comment
Please, Sign In to add comment