window.setInterval(function(){ refreshUpDownTotal(); refreshList(); }, 5000); $(document).ready(function() { $.ajaxSetup({ cache: false }); $("a[data-torrent-id]").click(function() { var hash = $(this).attr("data-torrent-id"); $.ajax({ type: "POST", url: "share", data: { hash: hash } }) .done(function( msg ) { $.notify( "URL : " + msg); }); }); refreshList(); refreshUpDownTotal(); diskInfo(); }); function refreshUpDownTotal() { $.getJSON( "api/get_updown_total", function( data ) { $("#up-info").text(bytesToSize(data["up"], true)); $("#down-info").text(bytesToSize(data["down"], true)); }); } function refreshList(){ $.getJSON( "api/get_list", function ( data ) { $.each( data, function( key, val ) { percent = (val['completed_bytes'] / val['size_bytes']) * 100; if(percent == 100) { space = bytesToSize(val['size_bytes'], false); } else { space = bytesToSize(val['completed_bytes'], false) + ' | ' + bytesToSize(val['size_bytes'], false); } $("tr[data-torrent-id='" + val['hash'] + "'] > td.name").css('background', 'linear-gradient(to right, #43ac6a ' + percent + '%, #f9f9f9 ' + percent + '%, #f9f9f9'); $("tr[data-torrent-id='" + val['hash'] + "'] > td > span.space").html(space); $("tr[data-torrent-id='" + val['hash'] + "'] > td.ratio").html(val['ratio']/1000); $("tr[data-torrent-id='" + val['hash'] + "'] > td.downspeed").html(bytesToSize(val['down'], true)); $("tr[data-torrent-id='" + val['hash'] + "'] > td.upspeed").html(bytesToSize(val['up'], true)); }); }); } function diskInfo(){ $.getJSON( "api/get_diskinfo", function ( data ) { percent = 100 - (data['free'] / data['total'] * 100); $(".disk-info > .text-info").html(bytesToSize(data['free'], false) + ' Free'); $(".disk-bar > .inner-bar").css('width', percent + '%'); }); } function bytesToSize(bytes, speed) { var sizes = ['o', 'Ko', 'Mo', 'Go', 'To']; var speeds = ['o/s', 'Ko/s', 'Mo/s']; if (bytes == 0) return '-'; var i = parseFloat(Math.floor(Math.log(bytes) / Math.log(1024))); if(speed) { return Math.round(bytes / Math.pow(1024, i) * 10) / 10 + ' ' + speeds[i]; } else { return Math.round(bytes / Math.pow(1024, i) * 100) / 100 + ' ' + sizes[i]; } }; function poppupAddTorrent(){ window.open("/add", "Ajout d'un torrent", config='height=100, width=400, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no'); }