custom.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. window.setInterval(function(){
  2. refreshUpDownTotal();
  3. refreshList();
  4. }, 5000);
  5. $(document).ready(function() {
  6. $.ajaxSetup({ cache: false });
  7. $("a[data-torrent-id]").click(function() {
  8. var hash = $(this).attr("data-torrent-id");
  9. $.ajax({
  10. type: "POST",
  11. url: "share",
  12. data: { hash: hash }
  13. })
  14. .done(function( msg ) {
  15. $.notify( "URL : " + msg);
  16. });
  17. });
  18. refreshList();
  19. refreshUpDownTotal();
  20. diskInfo();
  21. });
  22. function refreshUpDownTotal() {
  23. $.getJSON( "api/get_updown_total", function( data ) {
  24. $("#up-info").text(bytesToSize(data["up"], true));
  25. $("#down-info").text(bytesToSize(data["down"], true));
  26. });
  27. }
  28. function refreshList(){
  29. $.getJSON( "api/get_list", function ( data ) {
  30. $.each( data, function( key, val ) {
  31. percent = (val['completed_bytes'] / val['size_bytes']) * 100;
  32. if(percent == 100) {
  33. space = bytesToSize(val['size_bytes'], false);
  34. } else {
  35. space = bytesToSize(val['completed_bytes'], false) + ' | ' + bytesToSize(val['size_bytes'], false);
  36. }
  37. $("tr[data-torrent-id='" + val['hash'] + "'] > td.name").css('background', 'linear-gradient(to right, #43ac6a ' + percent + '%, #f9f9f9 ' + percent + '%, #f9f9f9');
  38. $("tr[data-torrent-id='" + val['hash'] + "'] > td > span.space").html(space);
  39. $("tr[data-torrent-id='" + val['hash'] + "'] > td.ratio").html(val['ratio']/1000);
  40. $("tr[data-torrent-id='" + val['hash'] + "'] > td.downspeed").html(bytesToSize(val['down'], true));
  41. $("tr[data-torrent-id='" + val['hash'] + "'] > td.upspeed").html(bytesToSize(val['up'], true));
  42. });
  43. });
  44. }
  45. function diskInfo(){
  46. $.getJSON( "api/get_diskinfo", function ( data ) {
  47. percent = 100 - (data['free'] / data['total'] * 100);
  48. $(".disk-info > .text-info").html(bytesToSize(data['free'], false) + ' Free');
  49. $(".disk-bar > .inner-bar").css('width', percent + '%');
  50. });
  51. }
  52. function bytesToSize(bytes, speed) {
  53. var sizes = ['o', 'Ko', 'Mo', 'Go', 'To'];
  54. var speeds = ['o/s', 'Ko/s', 'Mo/s'];
  55. if (bytes == 0) return '-';
  56. var i = parseFloat(Math.floor(Math.log(bytes) / Math.log(1024)));
  57. if(speed) {
  58. return Math.round(bytes / Math.pow(1024, i) * 10) / 10 + ' ' + speeds[i];
  59. } else {
  60. return Math.round(bytes / Math.pow(1024, i) * 100) / 100 + ' ' + sizes[i];
  61. }
  62. };
  63. function poppupAddTorrent(){
  64. 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');
  65. }