diff --git a/index.html b/index.html index 5a5a4c7..5452d71 100755 --- a/index.html +++ b/index.html @@ -1,646 +1,658 @@ - - - - - - - - - - - aria2 Web Client - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - -
- -
- -
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + aria2 Web Client + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+ +
+ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/js/libs/excanvas.compiled.js b/js/libs/excanvas.compiled.js new file mode 100644 index 0000000..a34ca1d --- /dev/null +++ b/js/libs/excanvas.compiled.js @@ -0,0 +1,35 @@ +// Copyright 2006 Google Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +document.createElement("canvas").getContext||(function(){var s=Math,j=s.round,F=s.sin,G=s.cos,V=s.abs,W=s.sqrt,k=10,v=k/2;function X(){return this.context_||(this.context_=new H(this))}var L=Array.prototype.slice;function Y(b,a){var c=L.call(arguments,2);return function(){return b.apply(a,c.concat(L.call(arguments)))}}var M={init:function(b){if(/MSIE/.test(navigator.userAgent)&&!window.opera){var a=b||document;a.createElement("canvas");a.attachEvent("onreadystatechange",Y(this.init_,this,a))}},init_:function(b){b.namespaces.g_vml_|| +b.namespaces.add("g_vml_","urn:schemas-microsoft-com:vml","#default#VML");b.namespaces.g_o_||b.namespaces.add("g_o_","urn:schemas-microsoft-com:office:office","#default#VML");if(!b.styleSheets.ex_canvas_){var a=b.createStyleSheet();a.owningElement.id="ex_canvas_";a.cssText="canvas{display:inline-block;overflow:hidden;text-align:left;width:300px;height:150px}g_vml_\\:*{behavior:url(#default#VML)}g_o_\\:*{behavior:url(#default#VML)}"}var c=b.getElementsByTagName("canvas"),d=0;for(;d','","");this.element_.insertAdjacentHTML("BeforeEnd",t.join(""))};i.stroke=function(b){var a=[],c=P(b?this.fillStyle:this.strokeStyle),d=c.color,f=c.alpha*this.globalAlpha;a.push("g.x)g.x=e.x;if(h.y==null||e.yg.y)g.y=e.y}}a.push(' ">');if(b)if(typeof this.fillStyle=="object"){var m=this.fillStyle,r=0,n={x:0,y:0},o=0,q=1;if(m.type_=="gradient"){var t=m.x1_/this.arcScaleX_,E=m.y1_/this.arcScaleY_,p=this.getCoords_(m.x0_/this.arcScaleX_,m.y0_/this.arcScaleY_), +z=this.getCoords_(t,E);r=Math.atan2(z.x-p.x,z.y-p.y)*180/Math.PI;if(r<0)r+=360;if(r<1.0E-6)r=0}else{var p=this.getCoords_(m.x0_,m.y0_),w=g.x-h.x,x=g.y-h.y;n={x:(p.x-h.x)/w,y:(p.y-h.y)/x};w/=this.arcScaleX_*k;x/=this.arcScaleY_*k;var R=s.max(w,x);o=2*m.r0_/R;q=2*m.r1_/R-o}var u=m.colors_;u.sort(function(ba,ca){return ba.offset-ca.offset});var J=u.length,da=u[0].color,ea=u[J-1].color,fa=u[0].alpha*this.globalAlpha,ga=u[J-1].alpha*this.globalAlpha,S=[],l=0;for(;l')}else a.push('');else{var K=this.lineScale_*this.lineWidth;if(K<1)f*=K;a.push("')}a.push("");this.element_.insertAdjacentHTML("beforeEnd",a.join(""))};i.fill=function(){this.stroke(true)};i.closePath=function(){this.currentPath_.push({type:"close"})};i.getCoords_=function(b,a){var c=this.m_;return{x:k*(b*c[0][0]+a*c[1][0]+c[2][0])-v,y:k*(b*c[0][1]+a*c[1][1]+c[2][1])-v}};i.save=function(){var b={};O(this,b);this.aStack_.push(b);this.mStack_.push(this.m_);this.m_=y(I(),this.m_)};i.restore=function(){O(this.aStack_.pop(), +this);this.m_=this.mStack_.pop()};function ha(b){var a=0;for(;a<3;a++){var c=0;for(;c<2;c++)if(!isFinite(b[a][c])||isNaN(b[a][c]))return false}return true}function A(b,a,c){if(!!ha(a)){b.m_=a;if(c)b.lineScale_=W(V(a[0][0]*a[1][1]-a[0][1]*a[1][0]))}}i.translate=function(b,a){A(this,y([[1,0,0],[0,1,0],[b,a,1]],this.m_),false)};i.rotate=function(b){var a=G(b),c=F(b);A(this,y([[a,c,0],[-c,a,0],[0,0,1]],this.m_),false)};i.scale=function(b,a){this.arcScaleX_*=b;this.arcScaleY_*=a;A(this,y([[b,0,0],[0,a, +0],[0,0,1]],this.m_),true)};i.transform=function(b,a,c,d,f,h){A(this,y([[b,a,0],[c,d,0],[f,h,1]],this.m_),true)};i.setTransform=function(b,a,c,d,f,h){A(this,[[b,a,0],[c,d,0],[f,h,1]],true)};i.clip=function(){};i.arcTo=function(){};i.createPattern=function(){return new U};function D(b){this.type_=b;this.r1_=this.y1_=this.x1_=this.r0_=this.y0_=this.x0_=0;this.colors_=[]}D.prototype.addColorStop=function(b,a){a=P(a);this.colors_.push({offset:b,color:a.color,alpha:a.alpha})};function U(){}G_vmlCanvasManager= +M;CanvasRenderingContext2D=H;CanvasGradient=D;CanvasPattern=U})(); diff --git a/js/libs/jquery.flot.min.js b/js/libs/jquery.flot.min.js new file mode 100644 index 0000000..4467fc5 --- /dev/null +++ b/js/libs/jquery.flot.min.js @@ -0,0 +1,6 @@ +/* Javascript plotting library for jQuery, v. 0.7. + * + * Released under the MIT license by IOLA, December 2007. + * + */ +(function(b){b.color={};b.color.make=function(d,e,g,f){var c={};c.r=d||0;c.g=e||0;c.b=g||0;c.a=f!=null?f:1;c.add=function(h,j){for(var k=0;k=1){return"rgb("+[c.r,c.g,c.b].join(",")+")"}else{return"rgba("+[c.r,c.g,c.b,c.a].join(",")+")"}};c.normalize=function(){function h(k,j,l){return jl?l:j)}c.r=h(0,parseInt(c.r),255);c.g=h(0,parseInt(c.g),255);c.b=h(0,parseInt(c.b),255);c.a=h(0,c.a,1);return c};c.clone=function(){return b.color.make(c.r,c.b,c.g,c.a)};return c.normalize()};b.color.extract=function(d,e){var c;do{c=d.css(e).toLowerCase();if(c!=""&&c!="transparent"){break}d=d.parent()}while(!b.nodeName(d.get(0),"body"));if(c=="rgba(0, 0, 0, 0)"){c="transparent"}return b.color.parse(c)};b.color.parse=function(c){var d,f=b.color.make;if(d=/rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(c)){return f(parseInt(d[1],10),parseInt(d[2],10),parseInt(d[3],10))}if(d=/rgba\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]+(?:\.[0-9]+)?)\s*\)/.exec(c)){return f(parseInt(d[1],10),parseInt(d[2],10),parseInt(d[3],10),parseFloat(d[4]))}if(d=/rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(c)){return f(parseFloat(d[1])*2.55,parseFloat(d[2])*2.55,parseFloat(d[3])*2.55)}if(d=/rgba\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\s*\)/.exec(c)){return f(parseFloat(d[1])*2.55,parseFloat(d[2])*2.55,parseFloat(d[3])*2.55,parseFloat(d[4]))}if(d=/#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(c)){return f(parseInt(d[1],16),parseInt(d[2],16),parseInt(d[3],16))}if(d=/#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(c)){return f(parseInt(d[1]+d[1],16),parseInt(d[2]+d[2],16),parseInt(d[3]+d[3],16))}var e=b.trim(c).toLowerCase();if(e=="transparent"){return f(255,255,255,0)}else{d=a[e]||[0,0,0];return f(d[0],d[1],d[2])}};var a={aqua:[0,255,255],azure:[240,255,255],beige:[245,245,220],black:[0,0,0],blue:[0,0,255],brown:[165,42,42],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgrey:[169,169,169],darkgreen:[0,100,0],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkviolet:[148,0,211],fuchsia:[255,0,255],gold:[255,215,0],green:[0,128,0],indigo:[75,0,130],khaki:[240,230,140],lightblue:[173,216,230],lightcyan:[224,255,255],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightyellow:[255,255,224],lime:[0,255,0],magenta:[255,0,255],maroon:[128,0,0],navy:[0,0,128],olive:[128,128,0],orange:[255,165,0],pink:[255,192,203],purple:[128,0,128],violet:[128,0,128],red:[255,0,0],silver:[192,192,192],white:[255,255,255],yellow:[255,255,0]}})(jQuery);(function(c){function b(av,ai,J,af){var Q=[],O={colors:["#edc240","#afd8f8","#cb4b4b","#4da74d","#9440ed"],legend:{show:true,noColumns:1,labelFormatter:null,labelBoxBorderColor:"#ccc",container:null,position:"ne",margin:5,backgroundColor:null,backgroundOpacity:0.85},xaxis:{show:null,position:"bottom",mode:null,color:null,tickColor:null,transform:null,inverseTransform:null,min:null,max:null,autoscaleMargin:null,ticks:null,tickFormatter:null,labelWidth:null,labelHeight:null,reserveSpace:null,tickLength:null,alignTicksWithAxis:null,tickDecimals:null,tickSize:null,minTickSize:null,monthNames:null,timeformat:null,twelveHourClock:false},yaxis:{autoscaleMargin:0.02,position:"left"},xaxes:[],yaxes:[],series:{points:{show:false,radius:3,lineWidth:2,fill:true,fillColor:"#ffffff",symbol:"circle"},lines:{lineWidth:2,fill:false,fillColor:null,steps:false},bars:{show:false,lineWidth:2,barWidth:1,fill:true,fillColor:null,align:"left",horizontal:false},shadowSize:3},grid:{show:true,aboveData:false,color:"#545454",backgroundColor:null,borderColor:null,tickColor:null,labelMargin:5,axisMargin:8,borderWidth:2,minBorderMargin:null,markings:null,markingsColor:"#f4f4f4",markingsLineWidth:2,clickable:false,hoverable:false,autoHighlight:true,mouseActiveRadius:10},hooks:{}},az=null,ad=null,y=null,H=null,A=null,p=[],aw=[],q={left:0,right:0,top:0,bottom:0},G=0,I=0,h=0,w=0,ak={processOptions:[],processRawData:[],processDatapoints:[],drawSeries:[],draw:[],bindEvents:[],drawOverlay:[],shutdown:[]},aq=this;aq.setData=aj;aq.setupGrid=t;aq.draw=W;aq.getPlaceholder=function(){return av};aq.getCanvas=function(){return az};aq.getPlotOffset=function(){return q};aq.width=function(){return h};aq.height=function(){return w};aq.offset=function(){var aB=y.offset();aB.left+=q.left;aB.top+=q.top;return aB};aq.getData=function(){return Q};aq.getAxes=function(){var aC={},aB;c.each(p.concat(aw),function(aD,aE){if(aE){aC[aE.direction+(aE.n!=1?aE.n:"")+"axis"]=aE}});return aC};aq.getXAxes=function(){return p};aq.getYAxes=function(){return aw};aq.c2p=C;aq.p2c=ar;aq.getOptions=function(){return O};aq.highlight=x;aq.unhighlight=T;aq.triggerRedrawOverlay=f;aq.pointOffset=function(aB){return{left:parseInt(p[aA(aB,"x")-1].p2c(+aB.x)+q.left),top:parseInt(aw[aA(aB,"y")-1].p2c(+aB.y)+q.top)}};aq.shutdown=ag;aq.resize=function(){B();g(az);g(ad)};aq.hooks=ak;F(aq);Z(J);X();aj(ai);t();W();ah();function an(aD,aB){aB=[aq].concat(aB);for(var aC=0;aC=O.colors.length){aG=0;++aF}}var aH=0,aN;for(aG=0;aGa3.datamax&&a1!=aB){a3.datamax=a1}}c.each(m(),function(a1,a2){a2.datamin=aO;a2.datamax=aI;a2.used=false});for(aU=0;aU0&&aT[aR-aP]!=null&&aT[aR-aP]!=aT[aR]&&aT[aR-aP+1]!=aT[aR+1]){for(aN=0;aNaM){aM=a0}}if(aX.y){if(a0aV){aV=a0}}}}if(aJ.bars.show){var aY=aJ.bars.align=="left"?0:-aJ.bars.barWidth/2;if(aJ.bars.horizontal){aQ+=aY;aV+=aY+aJ.bars.barWidth}else{aK+=aY;aM+=aY+aJ.bars.barWidth}}aF(aJ.xaxis,aK,aM);aF(aJ.yaxis,aQ,aV)}c.each(m(),function(a1,a2){if(a2.datamin==aO){a2.datamin=null}if(a2.datamax==aI){a2.datamax=null}})}function j(aB,aC){var aD=document.createElement("canvas");aD.className=aC;aD.width=G;aD.height=I;if(!aB){c(aD).css({position:"absolute",left:0,top:0})}c(aD).appendTo(av);if(!aD.getContext){aD=window.G_vmlCanvasManager.initElement(aD)}aD.getContext("2d").save();return aD}function B(){G=av.width();I=av.height();if(G<=0||I<=0){throw"Invalid dimensions for plot, width = "+G+", height = "+I}}function g(aC){if(aC.width!=G){aC.width=G}if(aC.height!=I){aC.height=I}var aB=aC.getContext("2d");aB.restore();aB.save()}function X(){var aC,aB=av.children("canvas.base"),aD=av.children("canvas.overlay");if(aB.length==0||aD==0){av.html("");av.css({padding:0});if(av.css("position")=="static"){av.css("position","relative")}B();az=j(true,"base");ad=j(false,"overlay");aC=false}else{az=aB.get(0);ad=aD.get(0);aC=true}H=az.getContext("2d");A=ad.getContext("2d");y=c([ad,az]);if(aC){av.data("plot").shutdown();aq.resize();A.clearRect(0,0,G,I);y.unbind();av.children().not([az,ad]).remove()}av.data("plot",aq)}function ah(){if(O.grid.hoverable){y.mousemove(aa);y.mouseleave(l)}if(O.grid.clickable){y.click(R)}an(ak.bindEvents,[y])}function ag(){if(M){clearTimeout(M)}y.unbind("mousemove",aa);y.unbind("mouseleave",l);y.unbind("click",R);an(ak.shutdown,[y])}function r(aG){function aC(aH){return aH}var aF,aB,aD=aG.options.transform||aC,aE=aG.options.inverseTransform;if(aG.direction=="x"){aF=aG.scale=h/Math.abs(aD(aG.max)-aD(aG.min));aB=Math.min(aD(aG.max),aD(aG.min))}else{aF=aG.scale=w/Math.abs(aD(aG.max)-aD(aG.min));aF=-aF;aB=Math.max(aD(aG.max),aD(aG.min))}if(aD==aC){aG.p2c=function(aH){return(aH-aB)*aF}}else{aG.p2c=function(aH){return(aD(aH)-aB)*aF}}if(!aE){aG.c2p=function(aH){return aB+aH/aF}}else{aG.c2p=function(aH){return aE(aB+aH/aF)}}}function L(aD){var aB=aD.options,aF,aJ=aD.ticks||[],aI=[],aE,aK=aB.labelWidth,aG=aB.labelHeight,aC;function aH(aM,aL){return c('
'+aM.join("")+"
").appendTo(av)}if(aD.direction=="x"){if(aK==null){aK=Math.floor(G/(aJ.length>0?aJ.length:1))}if(aG==null){aI=[];for(aF=0;aF'+aE+"")}}if(aI.length>0){aI.push('
');aC=aH(aI,"width:10000px;");aG=aC.height();aC.remove()}}}else{if(aK==null||aG==null){for(aF=0;aF'+aE+"")}}if(aI.length>0){aC=aH(aI,"");if(aK==null){aK=aC.children().width()}if(aG==null){aG=aC.find("div.tickLabel").height()}aC.remove()}}}if(aK==null){aK=0}if(aG==null){aG=0}aD.labelWidth=aK;aD.labelHeight=aG}function au(aD){var aC=aD.labelWidth,aL=aD.labelHeight,aH=aD.options.position,aF=aD.options.tickLength,aG=O.grid.axisMargin,aJ=O.grid.labelMargin,aK=aD.direction=="x"?p:aw,aE;var aB=c.grep(aK,function(aN){return aN&&aN.options.position==aH&&aN.reserveSpace});if(c.inArray(aD,aB)==aB.length-1){aG=0}if(aF==null){aF="full"}var aI=c.grep(aK,function(aN){return aN&&aN.reserveSpace});var aM=c.inArray(aD,aI)==0;if(!aM&&aF=="full"){aF=5}if(!isNaN(+aF)){aJ+=+aF}if(aD.direction=="x"){aL+=aJ;if(aH=="bottom"){q.bottom+=aL+aG;aD.box={top:I-q.bottom,height:aL}}else{aD.box={top:q.top+aG,height:aL};q.top+=aL+aG}}else{aC+=aJ;if(aH=="left"){aD.box={left:q.left+aG,width:aC};q.left+=aC+aG}else{q.right+=aC+aG;aD.box={left:G-q.right,width:aC}}}aD.position=aH;aD.tickLength=aF;aD.box.padding=aJ;aD.innermost=aM}function U(aB){if(aB.direction=="x"){aB.box.left=q.left;aB.box.width=h}else{aB.box.top=q.top;aB.box.height=w}}function t(){var aC,aE=m();c.each(aE,function(aF,aG){aG.show=aG.options.show;if(aG.show==null){aG.show=aG.used}aG.reserveSpace=aG.show||aG.options.reserveSpace;n(aG)});allocatedAxes=c.grep(aE,function(aF){return aF.reserveSpace});q.left=q.right=q.top=q.bottom=0;if(O.grid.show){c.each(allocatedAxes,function(aF,aG){S(aG);P(aG);ap(aG,aG.ticks);L(aG)});for(aC=allocatedAxes.length-1;aC>=0;--aC){au(allocatedAxes[aC])}var aD=O.grid.minBorderMargin;if(aD==null){aD=0;for(aC=0;aC=0){aD=0}}if(aF.max==null){aB+=aH*aG;if(aB>0&&aE.datamax!=null&&aE.datamax<=0){aB=0}}}}aE.min=aD;aE.max=aB}function S(aG){var aM=aG.options;var aH;if(typeof aM.ticks=="number"&&aM.ticks>0){aH=aM.ticks}else{aH=0.3*Math.sqrt(aG.direction=="x"?G:I)}var aT=(aG.max-aG.min)/aH,aO,aB,aN,aR,aS,aQ,aI;if(aM.mode=="time"){var aJ={second:1000,minute:60*1000,hour:60*60*1000,day:24*60*60*1000,month:30*24*60*60*1000,year:365.2425*24*60*60*1000};var aK=[[1,"second"],[2,"second"],[5,"second"],[10,"second"],[30,"second"],[1,"minute"],[2,"minute"],[5,"minute"],[10,"minute"],[30,"minute"],[1,"hour"],[2,"hour"],[4,"hour"],[8,"hour"],[12,"hour"],[1,"day"],[2,"day"],[3,"day"],[0.25,"month"],[0.5,"month"],[1,"month"],[2,"month"],[3,"month"],[6,"month"],[1,"year"]];var aC=0;if(aM.minTickSize!=null){if(typeof aM.tickSize=="number"){aC=aM.tickSize}else{aC=aM.minTickSize[0]*aJ[aM.minTickSize[1]]}}for(var aS=0;aS=aC){break}}aO=aK[aS][0];aN=aK[aS][1];if(aN=="year"){aQ=Math.pow(10,Math.floor(Math.log(aT/aJ.year)/Math.LN10));aI=(aT/aJ.year)/aQ;if(aI<1.5){aO=1}else{if(aI<3){aO=2}else{if(aI<7.5){aO=5}else{aO=10}}}aO*=aQ}aG.tickSize=aM.tickSize||[aO,aN];aB=function(aX){var a2=[],a0=aX.tickSize[0],a3=aX.tickSize[1],a1=new Date(aX.min);var aW=a0*aJ[a3];if(a3=="second"){a1.setUTCSeconds(a(a1.getUTCSeconds(),a0))}if(a3=="minute"){a1.setUTCMinutes(a(a1.getUTCMinutes(),a0))}if(a3=="hour"){a1.setUTCHours(a(a1.getUTCHours(),a0))}if(a3=="month"){a1.setUTCMonth(a(a1.getUTCMonth(),a0))}if(a3=="year"){a1.setUTCFullYear(a(a1.getUTCFullYear(),a0))}a1.setUTCMilliseconds(0);if(aW>=aJ.minute){a1.setUTCSeconds(0)}if(aW>=aJ.hour){a1.setUTCMinutes(0)}if(aW>=aJ.day){a1.setUTCHours(0)}if(aW>=aJ.day*4){a1.setUTCDate(1)}if(aW>=aJ.year){a1.setUTCMonth(0)}var a5=0,a4=Number.NaN,aY;do{aY=a4;a4=a1.getTime();a2.push(a4);if(a3=="month"){if(a0<1){a1.setUTCDate(1);var aV=a1.getTime();a1.setUTCMonth(a1.getUTCMonth()+1);var aZ=a1.getTime();a1.setTime(a4+a5*aJ.hour+(aZ-aV)*a0);a5=a1.getUTCHours();a1.setUTCHours(0)}else{a1.setUTCMonth(a1.getUTCMonth()+a0)}}else{if(a3=="year"){a1.setUTCFullYear(a1.getUTCFullYear()+a0)}else{a1.setTime(a4+aW)}}}while(a4aU){aP=aU}aQ=Math.pow(10,-aP);aI=aT/aQ;if(aI<1.5){aO=1}else{if(aI<3){aO=2;if(aI>2.25&&(aU==null||aP+1<=aU)){aO=2.5;++aP}}else{if(aI<7.5){aO=5}else{aO=10}}}aO*=aQ;if(aM.minTickSize!=null&&aO0){if(aM.min==null){aG.min=Math.min(aG.min,aL[0])}if(aM.max==null&&aL.length>1){aG.max=Math.max(aG.max,aL[aL.length-1])}}aB=function(aX){var aY=[],aV,aW;for(aW=0;aW1&&/\..*0$/.test((aD[1]-aD[0]).toFixed(aE)))){aG.tickDecimals=aE}}}}aG.tickGenerator=aB;if(c.isFunction(aM.tickFormatter)){aG.tickFormatter=function(aV,aW){return""+aM.tickFormatter(aV,aW)}}else{aG.tickFormatter=aR}}function P(aF){var aH=aF.options.ticks,aG=[];if(aH==null||(typeof aH=="number"&&aH>0)){aG=aF.tickGenerator(aF)}else{if(aH){if(c.isFunction(aH)){aG=aH({min:aF.min,max:aF.max})}else{aG=aH}}}var aE,aB;aF.ticks=[];for(aE=0;aE1){aC=aD[1]}}else{aB=+aD}if(aC==null){aC=aF.tickFormatter(aB,aF)}if(!isNaN(aB)){aF.ticks.push({v:aB,label:aC})}}}function ap(aB,aC){if(aB.options.autoscaleMargin&&aC.length>0){if(aB.options.min==null){aB.min=Math.min(aB.min,aC[0].v)}if(aB.options.max==null&&aC.length>1){aB.max=Math.max(aB.max,aC[aC.length-1].v)}}}function W(){H.clearRect(0,0,G,I);var aC=O.grid;if(aC.show&&aC.backgroundColor){N()}if(aC.show&&!aC.aboveData){ac()}for(var aB=0;aBaG){var aC=aH;aH=aG;aG=aC}return{from:aH,to:aG,axis:aE}}function N(){H.save();H.translate(q.left,q.top);H.fillStyle=am(O.grid.backgroundColor,w,0,"rgba(255, 255, 255, 0)");H.fillRect(0,0,h,w);H.restore()}function ac(){var aF;H.save();H.translate(q.left,q.top);var aH=O.grid.markings;if(aH){if(c.isFunction(aH)){var aK=aq.getAxes();aK.xmin=aK.xaxis.min;aK.xmax=aK.xaxis.max;aK.ymin=aK.yaxis.min;aK.ymax=aK.yaxis.max;aH=aH(aK)}for(aF=0;aFaC.axis.max||aI.toaI.axis.max){continue}aC.from=Math.max(aC.from,aC.axis.min);aC.to=Math.min(aC.to,aC.axis.max);aI.from=Math.max(aI.from,aI.axis.min);aI.to=Math.min(aI.to,aI.axis.max);if(aC.from==aC.to&&aI.from==aI.to){continue}aC.from=aC.axis.p2c(aC.from);aC.to=aC.axis.p2c(aC.to);aI.from=aI.axis.p2c(aI.from);aI.to=aI.axis.p2c(aI.to);if(aC.from==aC.to||aI.from==aI.to){H.beginPath();H.strokeStyle=aD.color||O.grid.markingsColor;H.lineWidth=aD.lineWidth||O.grid.markingsLineWidth;H.moveTo(aC.from,aI.from);H.lineTo(aC.to,aI.to);H.stroke()}else{H.fillStyle=aD.color||O.grid.markingsColor;H.fillRect(aC.from,aI.to,aC.to-aC.from,aI.from-aI.to)}}}var aK=m(),aM=O.grid.borderWidth;for(var aE=0;aEaB.max||(aQ=="full"&&aM>0&&(aO==aB.min||aO==aB.max))){continue}if(aB.direction=="x"){aN=aB.p2c(aO);aJ=aQ=="full"?-w:aQ;if(aB.position=="top"){aJ=-aJ}}else{aL=aB.p2c(aO);aP=aQ=="full"?-h:aQ;if(aB.position=="left"){aP=-aP}}if(H.lineWidth==1){if(aB.direction=="x"){aN=Math.floor(aN)+0.5}else{aL=Math.floor(aL)+0.5}}H.moveTo(aN,aL);H.lineTo(aN+aP,aL+aJ)}H.stroke()}if(aM){H.lineWidth=aM;H.strokeStyle=O.grid.borderColor;H.strokeRect(-aM/2,-aM/2,h+aM,w+aM)}H.restore()}function k(){av.find(".tickLabels").remove();var aG=['
'];var aJ=m();for(var aD=0;aD');for(var aE=0;aEaC.max){continue}var aK={},aI;if(aC.direction=="x"){aI="center";aK.left=Math.round(q.left+aC.p2c(aH.v)-aC.labelWidth/2);if(aC.position=="bottom"){aK.top=aF.top+aF.padding}else{aK.bottom=I-(aF.top+aF.height-aF.padding)}}else{aK.top=Math.round(q.top+aC.p2c(aH.v)-aC.labelHeight/2);if(aC.position=="left"){aK.right=G-(aF.left+aF.width-aF.padding);aI="right"}else{aK.left=aF.left+aF.padding;aI="left"}}aK.width=aC.labelWidth;var aB=["position:absolute","text-align:"+aI];for(var aL in aK){aB.push(aL+":"+aK[aL]+"px")}aG.push('
'+aH.label+"
")}aG.push("
")}aG.push("");av.append(aG.join(""))}function d(aB){if(aB.lines.show){at(aB)}if(aB.bars.show){e(aB)}if(aB.points.show){ao(aB)}}function at(aE){function aD(aP,aQ,aI,aU,aT){var aV=aP.points,aJ=aP.pointsize,aN=null,aM=null;H.beginPath();for(var aO=aJ;aO=aR&&aS>aT.max){if(aR>aT.max){continue}aL=(aT.max-aS)/(aR-aS)*(aK-aL)+aL;aS=aT.max}else{if(aR>=aS&&aR>aT.max){if(aS>aT.max){continue}aK=(aT.max-aS)/(aR-aS)*(aK-aL)+aL;aR=aT.max}}if(aL<=aK&&aL=aK&&aL>aU.max){if(aK>aU.max){continue}aS=(aU.max-aL)/(aK-aL)*(aR-aS)+aS;aL=aU.max}else{if(aK>=aL&&aK>aU.max){if(aL>aU.max){continue}aR=(aU.max-aL)/(aK-aL)*(aR-aS)+aS;aK=aU.max}}if(aL!=aN||aS!=aM){H.moveTo(aU.p2c(aL)+aQ,aT.p2c(aS)+aI)}aN=aK;aM=aR;H.lineTo(aU.p2c(aK)+aQ,aT.p2c(aR)+aI)}H.stroke()}function aF(aI,aQ,aP){var aW=aI.points,aV=aI.pointsize,aN=Math.min(Math.max(0,aP.min),aP.max),aX=0,aU,aT=false,aM=1,aL=0,aR=0;while(true){if(aV>0&&aX>aW.length+aV){break}aX+=aV;var aZ=aW[aX-aV],aK=aW[aX-aV+aM],aY=aW[aX],aJ=aW[aX+aM];if(aT){if(aV>0&&aZ!=null&&aY==null){aR=aX;aV=-aV;aM=2;continue}if(aV<0&&aX==aL+aV){H.fill();aT=false;aV=-aV;aM=1;aX=aL=aR+aV;continue}}if(aZ==null||aY==null){continue}if(aZ<=aY&&aZ=aY&&aZ>aQ.max){if(aY>aQ.max){continue}aK=(aQ.max-aZ)/(aY-aZ)*(aJ-aK)+aK;aZ=aQ.max}else{if(aY>=aZ&&aY>aQ.max){if(aZ>aQ.max){continue}aJ=(aQ.max-aZ)/(aY-aZ)*(aJ-aK)+aK;aY=aQ.max}}if(!aT){H.beginPath();H.moveTo(aQ.p2c(aZ),aP.p2c(aN));aT=true}if(aK>=aP.max&&aJ>=aP.max){H.lineTo(aQ.p2c(aZ),aP.p2c(aP.max));H.lineTo(aQ.p2c(aY),aP.p2c(aP.max));continue}else{if(aK<=aP.min&&aJ<=aP.min){H.lineTo(aQ.p2c(aZ),aP.p2c(aP.min));H.lineTo(aQ.p2c(aY),aP.p2c(aP.min));continue}}var aO=aZ,aS=aY;if(aK<=aJ&&aK=aP.min){aZ=(aP.min-aK)/(aJ-aK)*(aY-aZ)+aZ;aK=aP.min}else{if(aJ<=aK&&aJ=aP.min){aY=(aP.min-aK)/(aJ-aK)*(aY-aZ)+aZ;aJ=aP.min}}if(aK>=aJ&&aK>aP.max&&aJ<=aP.max){aZ=(aP.max-aK)/(aJ-aK)*(aY-aZ)+aZ;aK=aP.max}else{if(aJ>=aK&&aJ>aP.max&&aK<=aP.max){aY=(aP.max-aK)/(aJ-aK)*(aY-aZ)+aZ;aJ=aP.max}}if(aZ!=aO){H.lineTo(aQ.p2c(aO),aP.p2c(aK))}H.lineTo(aQ.p2c(aZ),aP.p2c(aK));H.lineTo(aQ.p2c(aY),aP.p2c(aJ));if(aY!=aS){H.lineTo(aQ.p2c(aY),aP.p2c(aJ));H.lineTo(aQ.p2c(aS),aP.p2c(aJ))}}}H.save();H.translate(q.left,q.top);H.lineJoin="round";var aG=aE.lines.lineWidth,aB=aE.shadowSize;if(aG>0&&aB>0){H.lineWidth=aB;H.strokeStyle="rgba(0,0,0,0.1)";var aH=Math.PI/18;aD(aE.datapoints,Math.sin(aH)*(aG/2+aB/2),Math.cos(aH)*(aG/2+aB/2),aE.xaxis,aE.yaxis);H.lineWidth=aB/2;aD(aE.datapoints,Math.sin(aH)*(aG/2+aB/4),Math.cos(aH)*(aG/2+aB/4),aE.xaxis,aE.yaxis)}H.lineWidth=aG;H.strokeStyle=aE.color;var aC=ae(aE.lines,aE.color,0,w);if(aC){H.fillStyle=aC;aF(aE.datapoints,aE.xaxis,aE.yaxis)}if(aG>0){aD(aE.datapoints,0,0,aE.xaxis,aE.yaxis)}H.restore()}function ao(aE){function aH(aN,aM,aU,aK,aS,aT,aQ,aJ){var aR=aN.points,aI=aN.pointsize;for(var aL=0;aLaT.max||aOaQ.max){continue}H.beginPath();aP=aT.p2c(aP);aO=aQ.p2c(aO)+aK;if(aJ=="circle"){H.arc(aP,aO,aM,0,aS?Math.PI:Math.PI*2,false)}else{aJ(H,aP,aO,aM,aS)}H.closePath();if(aU){H.fillStyle=aU;H.fill()}H.stroke()}}H.save();H.translate(q.left,q.top);var aG=aE.points.lineWidth,aC=aE.shadowSize,aB=aE.points.radius,aF=aE.points.symbol;if(aG>0&&aC>0){var aD=aC/2;H.lineWidth=aD;H.strokeStyle="rgba(0,0,0,0.1)";aH(aE.datapoints,aB,null,aD+aD/2,true,aE.xaxis,aE.yaxis,aF);H.strokeStyle="rgba(0,0,0,0.2)";aH(aE.datapoints,aB,null,aD/2,true,aE.xaxis,aE.yaxis,aF)}H.lineWidth=aG;H.strokeStyle=aE.color;aH(aE.datapoints,aB,ae(aE.points,aE.color),0,false,aE.xaxis,aE.yaxis,aF);H.restore()}function E(aN,aM,aV,aI,aQ,aF,aD,aL,aK,aU,aR,aC){var aE,aT,aJ,aP,aG,aB,aO,aH,aS;if(aR){aH=aB=aO=true;aG=false;aE=aV;aT=aN;aP=aM+aI;aJ=aM+aQ;if(aTaL.max||aPaK.max){return}if(aEaL.max){aT=aL.max;aB=false}if(aJaK.max){aP=aK.max;aO=false}aE=aL.p2c(aE);aJ=aK.p2c(aJ);aT=aL.p2c(aT);aP=aK.p2c(aP);if(aD){aU.beginPath();aU.moveTo(aE,aJ);aU.lineTo(aE,aP);aU.lineTo(aT,aP);aU.lineTo(aT,aJ);aU.fillStyle=aD(aJ,aP);aU.fill()}if(aC>0&&(aG||aB||aO||aH)){aU.beginPath();aU.moveTo(aE,aJ+aF);if(aG){aU.lineTo(aE,aP+aF)}else{aU.moveTo(aE,aP+aF)}if(aO){aU.lineTo(aT,aP+aF)}else{aU.moveTo(aT,aP+aF)}if(aB){aU.lineTo(aT,aJ+aF)}else{aU.moveTo(aT,aJ+aF)}if(aH){aU.lineTo(aE,aJ+aF)}else{aU.moveTo(aE,aJ+aF)}aU.stroke()}}function e(aD){function aC(aJ,aI,aL,aG,aK,aN,aM){var aO=aJ.points,aF=aJ.pointsize;for(var aH=0;aH")}aH.push("");aF=true}if(aN){aJ=aN(aJ,aM)}aH.push('
'+aJ+"")}if(aF){aH.push("")}if(aH.length==0){return}var aL=''+aH.join("")+"
";if(O.legend.container!=null){c(O.legend.container).html(aL)}else{var aI="",aC=O.legend.position,aD=O.legend.margin;if(aD[0]==null){aD=[aD,aD]}if(aC.charAt(0)=="n"){aI+="top:"+(aD[1]+q.top)+"px;"}else{if(aC.charAt(0)=="s"){aI+="bottom:"+(aD[1]+q.bottom)+"px;"}}if(aC.charAt(1)=="e"){aI+="right:"+(aD[0]+q.right)+"px;"}else{if(aC.charAt(1)=="w"){aI+="left:"+(aD[0]+q.left)+"px;"}}var aK=c('
'+aL.replace('style="','style="position:absolute;'+aI+";")+"
").appendTo(av);if(O.legend.backgroundOpacity!=0){var aG=O.legend.backgroundColor;if(aG==null){aG=O.grid.backgroundColor;if(aG&&typeof aG=="string"){aG=c.color.parse(aG)}else{aG=c.color.extract(aK,"background-color")}aG.a=1;aG=aG.toString()}var aB=aK.children();c('
').prependTo(aK).css("opacity",O.legend.backgroundOpacity)}}}var ab=[],M=null;function K(aI,aG,aD){var aO=O.grid.mouseActiveRadius,a0=aO*aO+1,aY=null,aR=false,aW,aU;for(aW=Q.length-1;aW>=0;--aW){if(!aD(Q[aW])){continue}var aP=Q[aW],aH=aP.xaxis,aF=aP.yaxis,aV=aP.datapoints.points,aT=aP.datapoints.pointsize,aQ=aH.c2p(aI),aN=aF.c2p(aG),aC=aO/aH.scale,aB=aO/aF.scale;if(aH.options.inverseTransform){aC=Number.MAX_VALUE}if(aF.options.inverseTransform){aB=Number.MAX_VALUE}if(aP.lines.show||aP.points.show){for(aU=0;aUaC||aK-aQ<-aC||aJ-aN>aB||aJ-aN<-aB){continue}var aM=Math.abs(aH.p2c(aK)-aI),aL=Math.abs(aF.p2c(aJ)-aG),aS=aM*aM+aL*aL;if(aS=Math.min(aZ,aK)&&aN>=aJ+aE&&aN<=aJ+aX):(aQ>=aK+aE&&aQ<=aK+aX&&aN>=Math.min(aZ,aJ)&&aN<=Math.max(aZ,aJ))){aY=[aW,aU/aT]}}}}if(aY){aW=aY[0];aU=aY[1];aT=Q[aW].datapoints.pointsize;return{datapoint:Q[aW].datapoints.points.slice(aU*aT,(aU+1)*aT),dataIndex:aU,series:Q[aW],seriesIndex:aW}}return null}function aa(aB){if(O.grid.hoverable){u("plothover",aB,function(aC){return aC.hoverable!=false})}}function l(aB){if(O.grid.hoverable){u("plothover",aB,function(aC){return false})}}function R(aB){u("plotclick",aB,function(aC){return aC.clickable!=false})}function u(aC,aB,aD){var aE=y.offset(),aH=aB.pageX-aE.left-q.left,aF=aB.pageY-aE.top-q.top,aJ=C({left:aH,top:aF});aJ.pageX=aB.pageX;aJ.pageY=aB.pageY;var aK=K(aH,aF,aD);if(aK){aK.pageX=parseInt(aK.series.xaxis.p2c(aK.datapoint[0])+aE.left+q.left);aK.pageY=parseInt(aK.series.yaxis.p2c(aK.datapoint[1])+aE.top+q.top)}if(O.grid.autoHighlight){for(var aG=0;aGaH.max||aIaG.max){return}var aF=aE.points.radius+aE.points.lineWidth/2;A.lineWidth=aF;A.strokeStyle=c.color.parse(aE.color).scale("a",0.5).toString();var aB=1.5*aF,aC=aH.p2c(aC),aI=aG.p2c(aI);A.beginPath();if(aE.points.symbol=="circle"){A.arc(aC,aI,aB,0,2*Math.PI,false)}else{aE.points.symbol(A,aC,aI,aB,false)}A.closePath();A.stroke()}function v(aE,aB){A.lineWidth=aE.bars.lineWidth;A.strokeStyle=c.color.parse(aE.color).scale("a",0.5).toString();var aD=c.color.parse(aE.color).scale("a",0.5).toString();var aC=aE.bars.align=="left"?0:-aE.bars.barWidth/2;E(aB[0],aB[1],aB[2]||0,aC,aC+aE.bars.barWidth,0,function(){return aD},aE.xaxis,aE.yaxis,A,aE.bars.horizontal,aE.bars.lineWidth)}function am(aJ,aB,aH,aC){if(typeof aJ=="string"){return aJ}else{var aI=H.createLinearGradient(0,aH,0,aB);for(var aE=0,aD=aJ.colors.length;aE12){n=n-12}else{if(n==0){n=12}}}for(var g=0;g').attr("src", url); - $('body').append(img); - img.remove(); - - setTimeout(function() { - $.ajax({ - url: url, - timeout: 1000, - data: { - jsonrpc: 2.0, - id: 'webui', - method: multicall? conf.func:'aria2.' + conf.func, - params: param_encode(conf.params) - }, - success: conf.success, - error: conf.error, - dataType: 'jsonp', - jsonp: 'jsoncallback' - }); - }, 1000); - } - else if(conf.error) { - conf.error(); - } - }, - dataType: 'jsonp', - jsonp: 'jsoncallback' - }); -} -var aria_syscall = function(conf, multicall) { - if(!WebSocket || server_conf.user.length || server_conf.pass.length) { - jsonp_syscall(conf, multicall); - } - else if(web_sock) { - web_sock_send(conf, multicall); - } - else { - web_sock_init(); - jsonp_syscall(conf, multicall); - } -} -var update_ui = function() { - updateDownloads(); -}; - -$(function() { - if (window.location.protocol === "http:") { - server_conf.host = window.location.hostname; - } - get_conf_cookie(); - var modal_conf = { - show: false, - backdrop: false - }; - modals.err_connect = $('#error_connect').modal(modal_conf); - modals.change_conf = $('#change_conf').modal(modal_conf); - modals.newDownload_modal = $('#newDownload_modal').modal(modal_conf); - modals.global_settings_modal = $('#global_settings_modal').modal(modal_conf); - modals.download_settings_modal = $('#download_settings_modal').modal(modal_conf); - modals.global_statistics_modal = $('#global_statistics_modal').modal(modal_conf); - modals.about_modal = $('#about_modal').modal(modal_conf); - modals.err_file_api_modal = $('#error_file_api').modal(modal_conf); - modals.new_torrent_modal = $('#new_torrent').modal(modal_conf); - modals.new_metalink_modal = $('#new_metalink').modal(modal_conf); - - if(WebSocket) - web_sock_init(); - - update_ui(); - $('#newDownload').click(function() { - $('#newDownload_url').val(""); - $('.download_urls').html(""); - modals.newDownload_modal.modal('show'); - }); - - $('#newDownload_torrent').click(function() { - $('#input_torrent').val(""); - if(window.File && window.FileReader && window.FileList && window.Blob) { - modals.new_torrent_modal.modal('show'); - } - else { - modals.err_file_api_modal.modal('show'); - } - }); - - $('#newDownload_metalink').click(function() { - $('#input_metalink').val(""); - if(window.File && window.FileReader && window.FileList && window.Blob) { - modals.new_metalink_modal.modal('show'); - - } - else { - modals.err_file_api_modal.modal('show'); - } - }); - $('#multiple_uris').click(function() { - var url = $('#newDownload_url').val(); - var html = '
  • '; - html += ''; - html += url; - html += ''; - html += ' '; - html += '
  • '; - $(html).appendTo('.download_urls'); - $('#newDownload_url').val(""); - $('.download_urls a').unbind('click').click(function() { - $(this).parents('li').remove(); - }); - }); - $('#addNewDownload').click(newDownload); - setInterval(update_ui, 1000); -}); -function check_global(name) { - for(var i = 0; i < global_settings_exclude.length; i++) { - if(global_settings_exclude[i] === name) { - return false; - } - } - return true; -} -function merge_settings_data(sets, res) { - for(var i in res) { - for(var j = 0; j < sets.length; j++) { - if(sets[j].name === i) { - sets[j].value = res[i].trim(); - sets[j].has_value = true; - if(sets[j].option) { - for(var k = 0; k < sets[j].options.length; k++) { - var tmp = { - val: sets[j].options[k], - disp: sets[j].options[k] - }; - - if(sets[j].options[k] === sets[j].value) { - tmp.val = sets[j].value + '" selected="true'; - } - sets[j].options[k] = tmp; - } - } - } - } - } -} -function get_global_settings(cb) { - var sets = []; - var tmp_set = []; - for(var i = 0; i < input_file_settings.length; i++) { - tmp_set = $.extend(true, {}, input_file_settings[i]); - if(check_global(tmp_set)) { - sets.push(tmp_set); - } - } - for(var i = 0; i < global_settings.length; i++) { - tmp_set = $.extend(true, {}, global_settings[i]); - if(check_global(tmp_set)) { - sets.push(tmp_set); - } - } - aria_syscall({ - func: 'getGlobalOption', - success: function(data) { - var res = data.result; - merge_settings_data(sets, res); - cb(sets); - }, - error: function() { - alert("Connection to aria server failed"); - } - }); -} -function custom_global_settings() { - var gen = function(name) { - return { name: name, values: [] }; - }; - var general_settings = gen("General Settings"); - var torrent_settings = gen("Bit-Torrent Settings"); - var ftp_settings = gen("FTP Settings"); - var http_settings = gen("HTTP(S) Settings"); - var metalink_settings = gen("Metalink Settings"); - - get_global_settings(function(sets) { - for(var i = 0; i < sets.length; i++) { - var set = sets[i]; - if(set.name.indexOf("bt") !== -1 || set.name.indexOf("torrent") !== -1) { - torrent_settings.values.push(set); - } - else if(set.name.indexOf("metalink") !== -1) { - metalink_settings.values.push(set); - } - else if(set.name.indexOf("http") !== -1) { - http_settings.values.push(set); - } - else if(set.name.indexOf("ftp") !== -1) { - ftp_settings.values.push(set); - } - else - general_settings.values.push(set); - - } - - var templ = $('#global_general_settings_template').text(); - var item = Mustache.render(templ, { - settings: [ - general_settings, - http_settings, - ftp_settings, - torrent_settings, - metalink_settings - ] - }); - $('#dynamic_global_settings').html(item); - modals.global_settings_modal.modal('show'); - $("#save_global_settings").one('click',function() { - var settings = {}; - for(var i = 0; i < sets.length; i++) { - var elem = $("#input_settings_" + sets[i].name); - if(sets[i].value) { - if(elem.val() !== sets[i].value) { - settings[sets[i].name] = elem.val(); - } - } - else if(elem.val() !== "no_val" && elem.val() !== "") { - settings[sets[i].name] = elem.val(); - } - } - if(!$.isEmptyObject(settings)) { - aria_syscall({ - func: 'changeGlobalOption', - params: [settings], - success: function(data) { - clear_dialogs(); - } - }); - } - else { - clear_dialogs(); - } - }); - }); -} - -function addDownload(uris) { - console.log("adding download:"); - console.log(uris); - aria_syscall({ - func: 'addUri', - params: uris, - success: function() { - clear_dialogs(); - update_ui(); - } - }); -} - -function newDownload() { - var li = $('.download_urls li'); - var urls = []; - for(var i = 0; i < li.length; i++) { - urls.push($(li[i]).text().trim()); - - } - var inp_url = $('#newDownload_url').val().trim(); - if(inp_url.length > 0) urls.push(inp_url); - addDownload([urls]); -} - -var d_files = { - active: [], - waiting: [], - stopped: [] -}; -function changeLength(len, pref) { - len = parseInt(len); - if(len <= (1<<10)) return len + " " + pref; - else if(len <= (1<<20)) return (len/(1<<10)).toFixed(1) + " K" + pref; - else if(len <= (1<<30)) return (len/(1<<20)).toFixed(1) + " M" + pref; - else return (len/(1<<30)).toFixed(1) + " G" + pref; -} -function changeTime(time) { - time = parseInt(time); - if(!time) return "infinite"; - if(time < 60) return time + " s"; - else if(time < 60*60) return (time/60).toFixed(2) + " min"; - else if(time < 60*60*24) return (time/(60*60)).toFixed(2) + " hours"; - else return (time/(60*60*24)).toFixed(2) + " days!!"; - -} -function getTemplateCtx(data) { - var percentage =(data.completedLength / data.totalLength)*100; - percentage = percentage.toFixed(2); - if(!percentage) percentage = 0; - var name; - var seed = (data.files[0].path || data.files[0].uris[0].uri).split(/[/\\]/); - name = seed[seed.length - 1]; - - var eta = changeTime((data.totalLength-data.completedLength)/data.downloadSpeed); - return { - name: name, - sett_name: name.substr(0,name.lastIndexOf('.')) || name, - status: data.status, - percentage:percentage, - gid: data.gid, - size: changeLength(data.totalLength, "B"), - down_speed: changeLength(data.downloadSpeed, "B/s"), - remaining: changeLength(data.totalLength - data.completedLength, "B"), - eta: eta, - downloaded: changeLength(data.completedLength, "B"), - dir: data.dir, - numPieces: data.numPieces, - pieceLength: changeLength(data.pieceLength, "B"), - uploadLength: changeLength(data.uploadLength, "B"), - connections: data.connections, - upload_speed: changeLength(data.uploadSpeed, "B/s"), - booleans: { - is_error: data.status === "error", - } - }; -} -function updateDownloadTemplates(elem, ctx) { - elem = $(elem); - for(var i in ctx) { - elem.find('.tmp_' + i).text(ctx[i]); - } - elem.find('.bar').css('width', ctx.percentage + '%'); -} -function deleteDownloadTemplates(top_elem, data) { - if(!data) { - $(top_elem).html(""); - } - else { - var elems = $(top_elem).find('[data-gid]'); - for(var i = 0; i < elems.length; i++) { - var elem = $(elems[i]); - var gid = elem.attr('data-gid').toString(); - var found = false; - for(var j = 0; j < data.length; j++) { - if(gid === data[j].gid.toString()) - found = true; - } - if(!found) - elem.remove(); - } - } -} -function refreshDownloadTemplates(top_elem, data) { - var down_template = $('#download_' + top_elem + '_template').text(); - deleteDownloadTemplates('#' + top_elem + '_downloads', data); - for(var i = 0; i < data.length; i++) { - var ctx = getTemplateCtx(data[i]); - var elem = $('[data-gid=' + ctx.gid + ']'); - if(elem.length) { - updateDownloadTemplates(elem, ctx); - } else { - var item = Mustache.render(down_template, ctx); - $('#' + top_elem + '_downloads').prepend(item); - } - } - $('#' + top_elem + '_downloads').children('.hero-unit').remove(); - -} -function getActiveSettings(gid, cb) { - var sets = []; - var tmp_set = []; - for(var i = 0; i < download_active_settings.length; i++) { - tmp_set = $.extend(true, {}, download_active_settings[i]); - sets.push(tmp_set); - } - aria_syscall({ - func: 'getOption', - params: [gid], - success: function(data) { - var res = data.result; - merge_settings_data(sets, res); - cb(sets); - }, - error: function() { - alert("Connection to aria server failed"); - } - }); -} -function check_waiting(name) { - for(var i = 0; i < download_waiting_exclude.length; i++) { - if(download_waiting_exclude[i] === name) { - return false; - } - } - return true; -} -function getWaitingSettings(gid, cb) { - var sets = []; - var tmp_set = []; - for(var i = 0; i < input_file_settings.length; i++) { - tmp_set = $.extend(true, {}, input_file_settings[i]); - if(check_waiting(tmp_set)) { - sets.push(tmp_set); - } - } - for(var i = 0; i < download_active_settings.length; i++) { - tmp_set = $.extend(true, {}, download_active_settings[i]); - if(check_waiting(tmp_set)) { - sets.push(tmp_set); - } - } - aria_syscall({ - func: 'getOption', - params: [gid], - success: function(data) { - var res = data.result; - merge_settings_data(sets, res); - cb(sets); - }, - error: function() { - alert("Connection to aria server failed"); - } - }); -} -function empty_download_set(elem) { - var len = d_files.active.length; - len += d_files.waiting.length; - len += d_files.stopped.length; - if(len === 0) { - var html = '

    '; - - html += 'Currently no downloads in line to display, use the Add download button to start downloading files!'; - html += '

    '; - $(elem).html(html); - } -} -function updateActiveDownloads(data) { - refreshDownloadTemplates('active', data); - empty_download_set('#active_downloads'); - $('.download_active_item .download_settings').unbind('click').click(function() { - var gid = $(this).parents('.download_active_item').attr('data-gid'); - var settings_name = $(this).parents('.download_active_item').attr('data-settingsName'); - var gen = function(name) { - return { name: name, values: [] }; - }; - var general_settings = gen("General Settings"); - var torrent_settings = gen("Bit-Torrent Settings"); - - getActiveSettings(gid, function(sets) { - for(var i = 0; i < sets.length; i++) { - var set = sets[i]; - if(set.name.indexOf("bt") !== -1 || set.name.indexOf("torrent") !== -1) { - torrent_settings.values.push(set); - } - else - general_settings.values.push(set); - - } - - var templ = $('#download_settings_template').text(); - var item = Mustache.render(templ, { - settings_name: settings_name, - gid: gid, - settings: [ - general_settings, - torrent_settings - ] - }); - $('#download_settings_modal').html(item); - modals.download_settings_modal.modal('show'); - $("#save_download_settings").one('click',function() { - var settings = {}; - for(var i = 0; i < sets.length; i++) { - var elem = $("#download_settings_" + sets[i].name); - if(sets[i].value) { - if(elem.val() !== sets[i].value) { - settings[sets[i].name] = elem.val(); - } - } - else if(elem.val() !== "no_val" && elem.val() !== "") { - settings[sets[i].name] = elem.val(); - } - } - if(!$.isEmptyObject(settings)) { - aria_syscall({ - func: 'changeOption', - params: [gid, settings], - success: function(data) { - clear_dialogs(); - } - }); - } - else { - clear_dialogs(); - } - }); - }); - }); - $('.download_active_item .download_pause').unbind('click').click(function() { - var gid = $(this).parents('.download_active_item').attr('data-gid'); - aria_syscall({ - func: 'forcePause', - params: [gid], - success: function() { - update_ui(); - }, - error: function(err) { - console.log("error pausing active download!!!"); - console.log(err); - } - }); - }); - $('.download_active_item .download_remove').unbind('click').click(function() { - var gid = $(this).parents('.download_active_item').attr('data-gid'); - aria_syscall({ - func: 'remove', - params: [gid], - success: function() { - update_ui(); - }, - error: function(err) { - console.log("error removing active download!!!"); - console.log(err); - } - }); - }); -} -function updateWaitingDownloads(data) { - refreshDownloadTemplates('waiting', data); - $('.download_waiting_item .download_settings').unbind('click').click(function() { - var gid = $(this).parents('.download_waiting_item').attr('data-gid'); - var settings_name = $(this).parents('.download_waiting_item').attr('data-settingsName'); - var gen = function(name) { - return { name: name, values: [] }; - }; - var general_settings = gen("General Settings"); - var torrent_settings = gen("Bit-Torrent Settings"); - var ftp_settings = gen("FTP Settings"); - var http_settings = gen("HTTP(S) Settings"); - var metalink_settings = gen("Metalink Settings"); - - getWaitingSettings(gid, function(sets) { - for(var i = 0; i < sets.length; i++) { - var set = sets[i]; - if(set.name.indexOf("bt") !== -1 || set.name.indexOf("torrent") !== -1) { - torrent_settings.values.push(set); - } - else if(set.name.indexOf("metalink") !== -1) { - metalink_settings.values.push(set); - } - else if(set.name.indexOf("http") !== -1) { - http_settings.values.push(set); - } - else if(set.name.indexOf("ftp") !== -1) { - ftp_settings.values.push(set); - } - else - general_settings.values.push(set); - - } - - var templ = $('#download_settings_template').text(); - var item = Mustache.render(templ, { - settings_name: settings_name, - gid: gid, - settings: [ - general_settings, - http_settings, - ftp_settings, - torrent_settings, - metalink_settings - ] - }); - $('#download_settings_modal').html(item); - modals.download_settings_modal.modal('show'); - $("#save_download_settings").one('click',function() { - var settings = {}; - for(var i = 0; i < sets.length; i++) { - var elem = $("#download_settings_" + sets[i].name); - if(sets[i].value) { - if(elem.val() !== sets[i].value) { - settings[sets[i].name] = elem.val(); - } - } - else if(elem.val() !== "no_val" && elem.val() !== "") { - settings[sets[i].name] = elem.val(); - } - } - if(!$.isEmptyObject(settings)) { - aria_syscall({ - func: 'changeOption', - params: [gid, settings], - success: function(data) { - clear_dialogs(); - } - }); - } - else { - clear_dialogs(); - } - }); - }); - }); - $('.download_waiting_item .download_play').unbind('click').click(function() { - var gid = $(this).parents('.download_waiting_item').attr('data-gid'); - aria_syscall({ - func: 'unpause', - params: [gid], - success: function(data) { - update_ui(); - }, - error: function(err) { - console.log("error playing waiting download!!!"); - console.log(err); - } - }); - }); - $('.download_waiting_item .download_remove').unbind('click').click(function() { - var gid = $(this).parents('.download_waiting_item').attr('data-gid'); - aria_syscall({ - func: 'remove', - params: [gid], - success: function() { - update_ui(); - }, - error: function(err) { - console.log("error removing waiting download!!!"); - console.log(err); - } - }); - }); -} - -function updateStoppedDownloads(data) { - refreshDownloadTemplates('stopped', data); - $('.download_stopped_item .download_remove').unbind('click').click(function() { - var gid = $(this).parents('.download_stopped_item').attr('data-gid'); - aria_syscall({ - func: 'removeDownloadResult', - params: [gid], - success: function() { - update_ui(); - }, - error: function(err) { - console.log("error removing stopped download!!!"); - console.log(err); - } - }); - }); - $('.download_stopped_item .download_restart').unbind('click').click(function() { - var gid = $(this).parents('.download_stopped_item').attr('data-gid'); - var files; - var uris = []; - for(var i = 0; i < d_files.stopped.length; i++) { - if(d_files.stopped[i].gid === gid) { - files = d_files.stopped[i].files; - break; - } - } - for(var i = 0; i < files.length; i++) { - var tmp_uris = []; - for(var j = 0; j < files[i].uris.length; j++) { - tmp_uris.push(files[i].uris[j].uri); - } - uris.push(tmp_uris); - } - addDownload(uris); - aria_syscall({ - func: 'removeDownloadResult', - params: [gid], - success: function() { - update_ui(); - }, - error: function(err) { - console.log("error removing stopped download!!!"); - console.log(err); - } - }); - }); -} - - -function mergeDownloads(data) { - d_files.active = data[0][0]; - d_files.waiting = data[1][0]; - d_files.stopped = data[2][0]; -} - -function updateDownloads() { - aria_syscall({ - func: 'system.multicall', - params:[[{ - methodName: 'aria2.tellActive' - }, { - methodName: 'aria2.tellWaiting', - params: [0,100] - }, { - methodName: 'aria2.tellStopped', - params: [0, 100] - }, { - methodName: "aria2.getGlobalStat" - }]], - success: function(data) { - mergeDownloads(data.result); - updateActiveDownloads(d_files.active); - updateWaitingDownloads(d_files.waiting); - updateStoppedDownloads(d_files.stopped); - updateGlobalStatistics(data.result[3][0]); - }, - error: function() { - modals.err_connect.modal('show'); - } - }, true); -} - -function updateGlobalStatistics(data) { - data.downloadSpeed = changeLength(data.downloadSpeed, "B/s"); - data.uploadSpeed = changeLength(data.uploadSpeed, "B/s"); - for(var i in data) { - $('.stat_' + i).text(data[i]); - } -} -function custom_global_statistics() { - var tmpl = $('#global_statistics_template').text(); - modals.global_statistics_modal.modal('show'); -} - -function show_about() { - aria_syscall({ - func: 'getVersion', - success: function(data) { - $('.about_aria_version').text(data.result.version); - $('.about_webclient_version').text('beta testing'); - modals.about_modal.modal('show'); - } - }); -} - -function force_pause_all() { - aria_syscall({ - func: 'forcePauseAll', - success: update_ui - }); -} - -function force_remove_all(cb) { - var remove_params = []; - var func = function(downs) { - for(var i = 0; i < downs.length; i++) { - remove_params.push({ - methodName: 'aria2.remove', - params: [downs[i].gid] - }); - } - } - func(d_files.active); - func(d_files.waiting); - aria_syscall({ - func: 'system.multicall', - params:[remove_params], - success: update_ui - }, true); -} - -function force_purge_all() { - var remove_params = []; - var func = function(downs) { - for(var i = 0; i < downs.length; i++) { - remove_params.push({ - methodName: 'aria2.remove', - params: [downs[i].gid] - }); - } - } - func(d_files.active); - func(d_files.waiting); - - aria_syscall({ - func: 'system.multicall', - params:[remove_params], - success: function() { - aria_syscall({ - func: "purgeDownloadResult", - success: update_ui - }); - } - }, true); - -} - -function add_torrent() { - var file_node = $('#input_torrent')[0]; - var files = file_node.files; - if (files.length) { - for (var i = 0, f; f = files[i]; i++) { - var reader = new FileReader(); - - reader.onload = function(e) { - var txt = e.target.result; - txt = txt.split(',')[1]; - aria_syscall({ - func: 'addTorrent', - params: [txt], - success: function() { - clear_dialogs(); - update_ui(); - } - }); - }; - reader.onerror = function(e) { - alert('error reading torrent, your browser policy does not allow to read local files, please change to firefox'); - }; - reader.readAsDataURL(f); - } - - } - else { - alert("please select a torrent first!"); - } -} -function add_metalink() { - var file_node = $('#input_metalink')[0]; - var files = file_node.files; - if (files.length) { - for (var i = 0, f; f = files[i]; i++) { - var reader = new FileReader(); - - reader.onload = function(e) { - var txt = e.target.result; - txt = txt.split(',')[1]; - aria_syscall({ - func: 'addMetalink', - params: [txt], - success: function() { - clear_dialogs(); - update_ui(); - } - }); - }; - reader.onerror = function(e) { - alert('error reading metalink, your browser policy does not allow to read local files, please change to firefox'); - }; - reader.readAsDataURL(f); - - } - } - else { - alert("please select a metalink first!"); - } -} +var graphSize = 5; +var graphData = []; +var graphSec = 0; +var modals = { + err_connect: undefined, + change_conf: undefined, + newDownload_modal: undefined, + global_settings_modal: undefined, + global_statistics_modal: undefined, + about_modal: undefined, + err_file_api_modal: undefined, + new_torrent_modal: undefined, + new_metalink_modal: undefined, + download_settings_modal: undefined +}; +var web_sock = undefined; +var web_sock_queue = []; +var web_sock_id = 0; +var clear_dialogs = function() { + for(var i in modals) { + modals[i].modal('hide'); + } +}; +var server_conf = { + host: 'localhost', + port: 6800, + user: "", + pass: "" +}; + +var set_conf_cookie = function() { + setCookie('aria2_server_conf', JSON.stringify(server_conf)); +} +var get_conf_cookie = function() { + if (getCookie('aria2_server_conf'.trim())) { + server_conf = JSON.parse(getCookie('aria2_server_conf')); + } +} +var custom_aria2_connect = function() { + clear_dialogs(); + modals.change_conf.modal('show'); +}; +var update_server_conf = function() { + var host = $('#input_host').val().trim(); + var port = $('#input_port').val().trim(); + server_conf.user = $('#input_user').val().trim(); + server_conf.pass = $('#input_pass').val().trim(); + if(host.length !== 0) { + server_conf.host = host; + } + if(port.length !== 0) { + server_conf.port = port; + } + web_sock = undefined; + set_conf_cookie(); + clear_dialogs(); + update_ui(); +}; + +function param_encode(param) { + if(param) { + param = base64.btoa(JSON.stringify(param)); + } + return param; +} + +var web_sock_error = function() { + for(var i = 0; i < web_sock_queue.length; i++) { + web_sock_queue[i].error(); + web_sock_queue.splice(i, 1); + } +} +var web_sock_message = function(message) { + var data = JSON.parse(message.data); + for(var i = 0; i < web_sock_queue.length; i++) { + if(web_sock_queue[i].id === data.id) { + if(data.error) { + if(web_sock_queue[i].error) + web_sock_queue[i].error(); + } + else { + web_sock_queue[i].success(data); + } + web_sock_queue.splice(i, 1); + } + } +} +var web_sock_send = function(conf, multicall) { + var id = 'webui_' + (web_sock_id++).toString(); + var data = { + jsonrpc: 2.0, + id: id, + method: multicall? conf.func:'aria2.' + conf.func, + params: conf.params + }; + web_sock_queue.push({ + success: conf.success, + error: conf.error, + id: id + }); + web_sock.send(JSON.stringify(data)); +} +var web_sock_init = function() { + if(!web_sock) { + var sock = new WebSocket('ws://' + server_conf.host + ':' + server_conf.port + '/jsonrpc'); + sock.onopen = function() { + console.log('websocket connected!!!'); + web_sock = sock; + }; + sock.onclose = function() { + web_sock_error(); + web_sock = undefined; + }; + sock.onerror = web_sock_error; + sock.onmessage = web_sock_message; + } +} + +var jsonp_syscall = function(conf, multicall) { + $.ajax({ + url: 'http://' + server_conf.host + ':' + server_conf.port + '/jsonrpc', + timeout: 1000, + data: { + jsonrpc: 2.0, + id: 'webui', + method: multicall? conf.func:'aria2.' + conf.func, + params: param_encode(conf.params) + }, + success: conf.success, + error: function() { + if(server_conf.user.length) { + var url = 'http://' + + server_conf.user + ":" + + server_conf.pass + "@" + + server_conf.host + ':' + + server_conf.port + '/jsonrpc'; + + /* hack for http authentication */ + var img = $('').attr("src", url); + $('body').append(img); + img.remove(); + + setTimeout(function() { + $.ajax({ + url: url, + timeout: 1000, + data: { + jsonrpc: 2.0, + id: 'webui', + method: multicall? conf.func:'aria2.' + conf.func, + params: param_encode(conf.params) + }, + success: conf.success, + error: conf.error, + dataType: 'jsonp', + jsonp: 'jsoncallback' + }); + }, 1000); + } + else if(conf.error) { + conf.error(); + } + }, + dataType: 'jsonp', + jsonp: 'jsoncallback' + }); +} +var aria_syscall = function(conf, multicall) { + if(!WebSocket || server_conf.user.length || server_conf.pass.length) { + jsonp_syscall(conf, multicall); + } + else if(web_sock) { + web_sock_send(conf, multicall); + } + else { + web_sock_init(); + jsonp_syscall(conf, multicall); + } +} +var update_ui = function() { + updateDownloads(); +}; + +$(function() { + if (window.location.protocol === "http:") { + server_conf.host = window.location.hostname; + } + get_conf_cookie(); + var modal_conf = { + show: false, + backdrop: false + }; + modals.err_connect = $('#error_connect').modal(modal_conf); + modals.change_conf = $('#change_conf').modal(modal_conf); + modals.newDownload_modal = $('#newDownload_modal').modal(modal_conf); + modals.global_settings_modal = $('#global_settings_modal').modal(modal_conf); + modals.download_settings_modal = $('#download_settings_modal').modal(modal_conf); + modals.global_statistics_modal = $('#global_statistics_modal').modal(modal_conf); + modals.about_modal = $('#about_modal').modal(modal_conf); + modals.err_file_api_modal = $('#error_file_api').modal(modal_conf); + modals.new_torrent_modal = $('#new_torrent').modal(modal_conf); + modals.new_metalink_modal = $('#new_metalink').modal(modal_conf); + + if(WebSocket) + web_sock_init(); + + update_ui(); + $('#newDownload').click(function() { + $('#newDownload_url').val(""); + $('.download_urls').html(""); + modals.newDownload_modal.modal('show'); + }); + + $('#newDownload_torrent').click(function() { + $('#input_torrent').val(""); + if(window.File && window.FileReader && window.FileList && window.Blob) { + modals.new_torrent_modal.modal('show'); + } + else { + modals.err_file_api_modal.modal('show'); + } + }); + + $('#newDownload_metalink').click(function() { + $('#input_metalink').val(""); + if(window.File && window.FileReader && window.FileList && window.Blob) { + modals.new_metalink_modal.modal('show'); + + } + else { + modals.err_file_api_modal.modal('show'); + } + }); + $('#multiple_uris').click(function() { + var url = $('#newDownload_url').val(); + var html = '
  • '; + html += ''; + html += url; + html += ''; + html += ' '; + html += '
  • '; + $(html).appendTo('.download_urls'); + $('#newDownload_url').val(""); + $('.download_urls a').unbind('click').click(function() { + $(this).parents('li').remove(); + }); + }); + $('#addNewDownload').click(newDownload); + setInterval(update_ui, 1000); +}); +function check_global(name) { + for(var i = 0; i < global_settings_exclude.length; i++) { + if(global_settings_exclude[i] === name) { + return false; + } + } + return true; +} +function merge_settings_data(sets, res) { + for(var i in res) { + for(var j = 0; j < sets.length; j++) { + if(sets[j].name === i) { + sets[j].value = res[i].trim(); + sets[j].has_value = true; + if(sets[j].option) { + for(var k = 0; k < sets[j].options.length; k++) { + var tmp = { + val: sets[j].options[k], + disp: sets[j].options[k] + }; + + if(sets[j].options[k] === sets[j].value) { + tmp.val = sets[j].value + '" selected="true'; + } + sets[j].options[k] = tmp; + } + } + } + } + } +} +function get_global_settings(cb) { + var sets = []; + var tmp_set = []; + for(var i = 0; i < input_file_settings.length; i++) { + tmp_set = $.extend(true, {}, input_file_settings[i]); + if(check_global(tmp_set)) { + sets.push(tmp_set); + } + } + for(var i = 0; i < global_settings.length; i++) { + tmp_set = $.extend(true, {}, global_settings[i]); + if(check_global(tmp_set)) { + sets.push(tmp_set); + } + } + aria_syscall({ + func: 'getGlobalOption', + success: function(data) { + var res = data.result; + merge_settings_data(sets, res); + cb(sets); + }, + error: function() { + alert("Connection to aria server failed"); + } + }); +} +function custom_global_settings() { + var gen = function(name) { + return { name: name, values: [] }; + }; + var general_settings = gen("General Settings"); + var torrent_settings = gen("Bit-Torrent Settings"); + var ftp_settings = gen("FTP Settings"); + var http_settings = gen("HTTP(S) Settings"); + var metalink_settings = gen("Metalink Settings"); + + get_global_settings(function(sets) { + for(var i = 0; i < sets.length; i++) { + var set = sets[i]; + if(set.name.indexOf("bt") !== -1 || set.name.indexOf("torrent") !== -1) { + torrent_settings.values.push(set); + } + else if(set.name.indexOf("metalink") !== -1) { + metalink_settings.values.push(set); + } + else if(set.name.indexOf("http") !== -1) { + http_settings.values.push(set); + } + else if(set.name.indexOf("ftp") !== -1) { + ftp_settings.values.push(set); + } + else + general_settings.values.push(set); + + } + + var templ = $('#global_general_settings_template').text(); + var item = Mustache.render(templ, { + settings: [ + general_settings, + http_settings, + ftp_settings, + torrent_settings, + metalink_settings + ] + }); + $('#dynamic_global_settings').html(item); + modals.global_settings_modal.modal('show'); + $("#save_global_settings").one('click',function() { + var settings = {}; + for(var i = 0; i < sets.length; i++) { + var elem = $("#input_settings_" + sets[i].name); + if(sets[i].value) { + if(elem.val() !== sets[i].value) { + settings[sets[i].name] = elem.val(); + } + } + else if(elem.val() !== "no_val" && elem.val() !== "") { + settings[sets[i].name] = elem.val(); + } + } + if(!$.isEmptyObject(settings)) { + aria_syscall({ + func: 'changeGlobalOption', + params: [settings], + success: function(data) { + clear_dialogs(); + } + }); + } + else { + clear_dialogs(); + } + }); + }); +} + +function addDownload(uris) { + console.log("adding download:"); + console.log(uris); + aria_syscall({ + func: 'addUri', + params: uris, + success: function() { + clear_dialogs(); + update_ui(); + } + }); +} + +function newDownload() { + var li = $('.download_urls li'); + var urls = []; + for(var i = 0; i < li.length; i++) { + urls.push($(li[i]).text().trim()); + + } + var inp_url = $('#newDownload_url').val().trim(); + if(inp_url.length > 0) urls.push(inp_url); + addDownload([urls]); +} + +var d_files = { + active: [], + waiting: [], + stopped: [] +}; +function changeLength(len, pref) { + len = parseInt(len); + if(len <= (1<<10)) return len + " " + pref; + else if(len <= (1<<20)) return (len/(1<<10)).toFixed(1) + " K" + pref; + else if(len <= (1<<30)) return (len/(1<<20)).toFixed(1) + " M" + pref; + else return (len/(1<<30)).toFixed(1) + " G" + pref; +} +function changeTime(time) { + time = parseInt(time); + if(!time) return "infinite"; + if(time < 60) return time + " s"; + else if(time < 60*60) return (time/60).toFixed(2) + " min"; + else if(time < 60*60*24) return (time/(60*60)).toFixed(2) + " hours"; + else return (time/(60*60*24)).toFixed(2) + " days!!"; + +} +function getTemplateCtx(data) { + var percentage =(data.completedLength / data.totalLength)*100; + percentage = percentage.toFixed(2); + if(!percentage) percentage = 0; + var name; + var seed = (data.files[0].path || data.files[0].uris[0].uri).split(/[/\\]/); + name = seed[seed.length - 1]; + + var eta = changeTime((data.totalLength-data.completedLength)/data.downloadSpeed); + return { + name: name, + sett_name: name.substr(0,name.lastIndexOf('.')) || name, + status: data.status, + percentage:percentage, + gid: data.gid, + size: changeLength(data.totalLength, "B"), + down_speed: changeLength(data.downloadSpeed, "B/s"), + remaining: changeLength(data.totalLength - data.completedLength, "B"), + eta: eta, + downloaded: changeLength(data.completedLength, "B"), + dir: data.dir, + numPieces: data.numPieces, + pieceLength: changeLength(data.pieceLength, "B"), + uploadLength: changeLength(data.uploadLength, "B"), + connections: data.connections, + upload_speed: changeLength(data.uploadSpeed, "B/s"), + booleans: { + is_error: data.status === "error", + } + }; +} +function updateDownloadTemplates(elem, ctx) { + elem = $(elem); + for(var i in ctx) { + elem.find('.tmp_' + i).text(ctx[i]); + } + elem.find('.bar').css('width', ctx.percentage + '%'); +} +function deleteDownloadTemplates(top_elem, data) { + if(!data) { + graphData = []; + $(top_elem).html(""); + } + else { + var elems = $(top_elem).find('[data-gid]'); + for(var i = 0; i < elems.length; i++) { + var elem = $(elems[i]); + var gid = elem.attr('data-gid').toString(); + var found = false; + for(var j = 0; j < data.length; j++) { + if(gid === data[j].gid.toString()) + found = true; + } + if(!found) { + elem.remove(); + } + } + } +} +function refreshDownloadTemplates(top_elem, data) { + var down_template = $('#download_' + top_elem + '_template').text(); + deleteDownloadTemplates('#' + top_elem + '_downloads', data); + for(var i = 0; i < data.length; i++) { + var ctx = getTemplateCtx(data[i]); + var elem = $('[data-gid=' + ctx.gid + ']'); + if(elem.length) { + updateDownloadTemplates(elem, ctx); + } else { + var item = Mustache.render(down_template, ctx); + $('#' + top_elem + '_downloads').prepend(item); + } + } + $('#' + top_elem + '_downloads').children('.hero-unit').remove(); + +} +function updateGraph(gid) { + var elem = $('[data-gid=' + gid + ']'); + for (var i = 0; i < graphData.length; i++) { + if (graphData[i].gid == gid) { + var moreInfo = $(elem).find(".more_info"); + if (moreInfo.hasClass("in")) { + graphData[i].plot.setData([{ + label: "Download Speed", + data: graphData[i].downSpeed, + color: "#ff0000", + lines: { show: true } + }, { + label: "Upload Speed", + data: graphData[i].uploadSpeed, + color: "#00ff00", + lines: { show: true } + }]); + graphData[i].plot.setupGrid(); + graphData[i].plot.draw(); + } + } + } +} +function createGraph(gid) { + return $.plot('[data-gid=' + gid + '] .active_graph', [{ + label: "Download Speed", + data: [], + color: "#ff0000", + lines: { show: true } + }, { + label: "Upload Speed", + data: [], + color: "#00ff00", + lines: { show: true } + }], { + legend: { show: true }, + xaxis: { show: true }, + yaxis: { + tickFormatter: function(val, axis) { + return changeLength(val, "B/s"); + }, + min: 0 + } + }); +} +function updateGraphData(data) { + for (var i = 0; i < data.length; i++) { + var gid = data[i].gid; + var graph; + for (var i = 0; i < graphData.length; i++) { + if (graphData[i].gid == gid) { + graph = graphData[i]; + break; + } + } + var downSpeed = data[i].downloadSpeed; + var upSpeed = data[i].uploadSpeed; + var that = this; + graphSec++; + if (!graph) { + graphData.push((function() { + return { + gid: gid, + downSpeed: [], + upSpeed: [], + add: function(arr, val) { + if (arr.length == graphSize) { + arr.shift(); + } + arr.push([((new Date - this.start)/1000).toFixed(0), val]); + }, + addDown: function(val) { + this.add(this.downSpeed, val); + return this; + }, + addUp: function(val) { + this.add(this.upSpeed, val); + return this; + }, + plot: that.createGraph(gid), + start: new Date() + } + })().addDown(downSpeed).addUp(upSpeed)); + } + else { + graph.addDown(downSpeed).addUp(upSpeed); + } + this.updateGraph(gid); + } +} +function getActiveSettings(gid, cb) { + var sets = []; + var tmp_set = []; + for(var i = 0; i < download_active_settings.length; i++) { + tmp_set = $.extend(true, {}, download_active_settings[i]); + sets.push(tmp_set); + } + aria_syscall({ + func: 'getOption', + params: [gid], + success: function(data) { + var res = data.result; + merge_settings_data(sets, res); + cb(sets); + }, + error: function() { + alert("Connection to aria server failed"); + } + }); +} +function check_waiting(name) { + for(var i = 0; i < download_waiting_exclude.length; i++) { + if(download_waiting_exclude[i] === name) { + return false; + } + } + return true; +} +function getWaitingSettings(gid, cb) { + var sets = []; + var tmp_set = []; + for(var i = 0; i < input_file_settings.length; i++) { + tmp_set = $.extend(true, {}, input_file_settings[i]); + if(check_waiting(tmp_set)) { + sets.push(tmp_set); + } + } + for(var i = 0; i < download_active_settings.length; i++) { + tmp_set = $.extend(true, {}, download_active_settings[i]); + if(check_waiting(tmp_set)) { + sets.push(tmp_set); + } + } + aria_syscall({ + func: 'getOption', + params: [gid], + success: function(data) { + var res = data.result; + merge_settings_data(sets, res); + cb(sets); + }, + error: function() { + alert("Connection to aria server failed"); + } + }); +} +function empty_download_set(elem) { + var len = d_files.active.length; + len += d_files.waiting.length; + len += d_files.stopped.length; + if(len === 0) { + var html = '

    '; + + html += 'Currently no downloads in line to display, use the Add download button to start downloading files!'; + html += '

    '; + $(elem).html(html); + } +} +function updateActiveDownloads(data) { + refreshDownloadTemplates('active', data); + updateGraphData(data); + empty_download_set('#active_downloads'); + $('.download_active_item .download_settings').unbind('click').click(function() { + var gid = $(this).parents('.download_active_item').attr('data-gid'); + var settings_name = $(this).parents('.download_active_item').attr('data-settingsName'); + var gen = function(name) { + return { name: name, values: [] }; + }; + var general_settings = gen("General Settings"); + var torrent_settings = gen("Bit-Torrent Settings"); + + getActiveSettings(gid, function(sets) { + for(var i = 0; i < sets.length; i++) { + var set = sets[i]; + if(set.name.indexOf("bt") !== -1 || set.name.indexOf("torrent") !== -1) { + torrent_settings.values.push(set); + } + else + general_settings.values.push(set); + + } + + var templ = $('#download_settings_template').text(); + var item = Mustache.render(templ, { + settings_name: settings_name, + gid: gid, + settings: [ + general_settings, + torrent_settings + ] + }); + $('#download_settings_modal').html(item); + modals.download_settings_modal.modal('show'); + $("#save_download_settings").one('click',function() { + var settings = {}; + for(var i = 0; i < sets.length; i++) { + var elem = $("#download_settings_" + sets[i].name); + if(sets[i].value) { + if(elem.val() !== sets[i].value) { + settings[sets[i].name] = elem.val(); + } + } + else if(elem.val() !== "no_val" && elem.val() !== "") { + settings[sets[i].name] = elem.val(); + } + } + if(!$.isEmptyObject(settings)) { + aria_syscall({ + func: 'changeOption', + params: [gid, settings], + success: function(data) { + clear_dialogs(); + } + }); + } + else { + clear_dialogs(); + } + }); + }); + }); + $('.download_active_item .download_pause').unbind('click').click(function() { + var gid = $(this).parents('.download_active_item').attr('data-gid'); + aria_syscall({ + func: 'forcePause', + params: [gid], + success: function() { + update_ui(); + }, + error: function(err) { + console.log("error pausing active download!!!"); + console.log(err); + } + }); + }); + $('.download_active_item .download_remove').unbind('click').click(function() { + var gid = $(this).parents('.download_active_item').attr('data-gid'); + aria_syscall({ + func: 'remove', + params: [gid], + success: function() { + update_ui(); + }, + error: function(err) { + console.log("error removing active download!!!"); + console.log(err); + } + }); + }); +} +function updateWaitingDownloads(data) { + refreshDownloadTemplates('waiting', data); + $('.download_waiting_item .download_settings').unbind('click').click(function() { + var gid = $(this).parents('.download_waiting_item').attr('data-gid'); + var settings_name = $(this).parents('.download_waiting_item').attr('data-settingsName'); + var gen = function(name) { + return { name: name, values: [] }; + }; + var general_settings = gen("General Settings"); + var torrent_settings = gen("Bit-Torrent Settings"); + var ftp_settings = gen("FTP Settings"); + var http_settings = gen("HTTP(S) Settings"); + var metalink_settings = gen("Metalink Settings"); + + getWaitingSettings(gid, function(sets) { + for(var i = 0; i < sets.length; i++) { + var set = sets[i]; + if(set.name.indexOf("bt") !== -1 || set.name.indexOf("torrent") !== -1) { + torrent_settings.values.push(set); + } + else if(set.name.indexOf("metalink") !== -1) { + metalink_settings.values.push(set); + } + else if(set.name.indexOf("http") !== -1) { + http_settings.values.push(set); + } + else if(set.name.indexOf("ftp") !== -1) { + ftp_settings.values.push(set); + } + else + general_settings.values.push(set); + + } + + var templ = $('#download_settings_template').text(); + var item = Mustache.render(templ, { + settings_name: settings_name, + gid: gid, + settings: [ + general_settings, + http_settings, + ftp_settings, + torrent_settings, + metalink_settings + ] + }); + $('#download_settings_modal').html(item); + modals.download_settings_modal.modal('show'); + $("#save_download_settings").one('click',function() { + var settings = {}; + for(var i = 0; i < sets.length; i++) { + var elem = $("#download_settings_" + sets[i].name); + if(sets[i].value) { + if(elem.val() !== sets[i].value) { + settings[sets[i].name] = elem.val(); + } + } + else if(elem.val() !== "no_val" && elem.val() !== "") { + settings[sets[i].name] = elem.val(); + } + } + if(!$.isEmptyObject(settings)) { + aria_syscall({ + func: 'changeOption', + params: [gid, settings], + success: function(data) { + clear_dialogs(); + } + }); + } + else { + clear_dialogs(); + } + }); + }); + }); + $('.download_waiting_item .download_play').unbind('click').click(function() { + var gid = $(this).parents('.download_waiting_item').attr('data-gid'); + aria_syscall({ + func: 'unpause', + params: [gid], + success: function(data) { + update_ui(); + }, + error: function(err) { + console.log("error playing waiting download!!!"); + console.log(err); + } + }); + }); + $('.download_waiting_item .download_remove').unbind('click').click(function() { + var gid = $(this).parents('.download_waiting_item').attr('data-gid'); + aria_syscall({ + func: 'remove', + params: [gid], + success: function() { + update_ui(); + }, + error: function(err) { + console.log("error removing waiting download!!!"); + console.log(err); + } + }); + }); +} + +function updateStoppedDownloads(data) { + refreshDownloadTemplates('stopped', data); + $('.download_stopped_item .download_remove').unbind('click').click(function() { + var gid = $(this).parents('.download_stopped_item').attr('data-gid'); + aria_syscall({ + func: 'removeDownloadResult', + params: [gid], + success: function() { + update_ui(); + }, + error: function(err) { + console.log("error removing stopped download!!!"); + console.log(err); + } + }); + }); + $('.download_stopped_item .download_restart').unbind('click').click(function() { + var gid = $(this).parents('.download_stopped_item').attr('data-gid'); + var files; + var uris = []; + for(var i = 0; i < d_files.stopped.length; i++) { + if(d_files.stopped[i].gid === gid) { + files = d_files.stopped[i].files; + break; + } + } + for(var i = 0; i < files.length; i++) { + var tmp_uris = []; + for(var j = 0; j < files[i].uris.length; j++) { + tmp_uris.push(files[i].uris[j].uri); + } + uris.push(tmp_uris); + } + addDownload(uris); + aria_syscall({ + func: 'removeDownloadResult', + params: [gid], + success: function() { + update_ui(); + }, + error: function(err) { + console.log("error removing stopped download!!!"); + console.log(err); + } + }); + }); +} + + +function mergeDownloads(data) { + d_files.active = data[0][0]; + d_files.waiting = data[1][0]; + d_files.stopped = data[2][0]; +} + +function updateDownloads() { + aria_syscall({ + func: 'system.multicall', + params:[[{ + methodName: 'aria2.tellActive' + }, { + methodName: 'aria2.tellWaiting', + params: [0,100] + }, { + methodName: 'aria2.tellStopped', + params: [0, 100] + }, { + methodName: "aria2.getGlobalStat" + }]], + success: function(data) { + mergeDownloads(data.result); + updateActiveDownloads(d_files.active); + updateWaitingDownloads(d_files.waiting); + updateStoppedDownloads(d_files.stopped); + updateGlobalStatistics(data.result[3][0]); + }, + error: function() { + modals.err_connect.modal('show'); + } + }, true); +} + +function updateGlobalStatistics(data) { + data.downloadSpeed = changeLength(data.downloadSpeed, "B/s"); + data.uploadSpeed = changeLength(data.uploadSpeed, "B/s"); + for(var i in data) { + $('.stat_' + i).text(data[i]); + } +} +function custom_global_statistics() { + var tmpl = $('#global_statistics_template').text(); + modals.global_statistics_modal.modal('show'); +} + +function show_about() { + aria_syscall({ + func: 'getVersion', + success: function(data) { + $('.about_aria_version').text(data.result.version); + $('.about_webclient_version').text('beta testing'); + modals.about_modal.modal('show'); + } + }); +} + +function force_pause_all() { + aria_syscall({ + func: 'forcePauseAll', + success: update_ui + }); +} + +function force_remove_all(cb) { + var remove_params = []; + var func = function(downs) { + for(var i = 0; i < downs.length; i++) { + remove_params.push({ + methodName: 'aria2.remove', + params: [downs[i].gid] + }); + } + } + func(d_files.active); + func(d_files.waiting); + aria_syscall({ + func: 'system.multicall', + params:[remove_params], + success: update_ui + }, true); +} + +function force_purge_all() { + var remove_params = []; + var func = function(downs) { + for(var i = 0; i < downs.length; i++) { + remove_params.push({ + methodName: 'aria2.remove', + params: [downs[i].gid] + }); + } + } + func(d_files.active); + func(d_files.waiting); + + aria_syscall({ + func: 'system.multicall', + params:[remove_params], + success: function() { + aria_syscall({ + func: "purgeDownloadResult", + success: update_ui + }); + } + }, true); + +} + +function add_torrent() { + var file_node = $('#input_torrent')[0]; + var files = file_node.files; + if (files.length) { + for (var i = 0, f; f = files[i]; i++) { + var reader = new FileReader(); + + reader.onload = function(e) { + var txt = e.target.result; + txt = txt.split(',')[1]; + aria_syscall({ + func: 'addTorrent', + params: [txt], + success: function() { + clear_dialogs(); + update_ui(); + } + }); + }; + reader.onerror = function(e) { + alert('error reading torrent, your browser policy does not allow to read local files, please change to firefox'); + }; + reader.readAsDataURL(f); + } + + } + else { + alert("please select a torrent first!"); + } +} +function add_metalink() { + var file_node = $('#input_metalink')[0]; + var files = file_node.files; + if (files.length) { + for (var i = 0, f; f = files[i]; i++) { + var reader = new FileReader(); + + reader.onload = function(e) { + var txt = e.target.result; + txt = txt.split(',')[1]; + aria_syscall({ + func: 'addMetalink', + params: [txt], + success: function() { + clear_dialogs(); + update_ui(); + } + }); + }; + reader.onerror = function(e) { + alert('error reading metalink, your browser policy does not allow to read local files, please change to firefox'); + }; + reader.readAsDataURL(f); + + } + } + else { + alert("please select a metalink first!"); + } +}