12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- 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();
- });
- 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 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];
- }
- };
|