$(function(){ var onionshare = {} function update($msg) { var $line = $('
  • ').append($msg); $('#log').append($line); // scroll to bottom set_log_height(); $('#log').scrollTop($('#log').height()); } function copy_to_clipboard() { $.ajax({ url: '/copy_url', success: function(data, textStatus, jqXHR){ update(onionshare.strings['copied_url']); } }); } $('#copy-button').click(copy_to_clipboard); var REQUEST_LOAD = 0; var REQUEST_DOWNLOAD = 1; var REQUEST_PROGRESS = 2; var REQUEST_OTHER = 3; function check_for_requests() { $.ajax({ url: '/heartbeat', success: function(data, textStatus, jqXHR){ if(data != '') { var events = JSON.parse(data); for(var i=0; i').addClass('weblog').html(onionshare.strings['download_page_loaded'])); } else if(r.type == REQUEST_DOWNLOAD) { var $download = $('') .attr('id', 'download-'+r.data.id) .addClass('weblog').html(onionshare.strings['download_started']) .append($('').addClass('progress')); update($download); } else if(r.type == REQUEST_PROGRESS) { // is the download complete? if(r.data.bytes == onionshare.filesize) { $('#download-'+r.data.id).html(onionshare.strings['download_finished']); // close on finish? if($('#close-on-finish').is(':checked')) { function close_countdown(i) { $('#close-countdown').html(onionshare.strings['close_countdown'].replace('{0}', i)); if(i == 0) { // close program $.ajax({ url: '/close' }); } else { // continue countdown setTimeout(function(){ close_countdown(i-1) }, 1000); } } update($('').attr('id', 'close-countdown')); close_countdown(3); } } // still in progress else { var percent = Math.floor((r.data.bytes / onionshare.filesize) * 100); $('#download-'+r.data.id+' .progress').html(' '+human_readable_filesize(r.data.bytes)+', '+percent+'%'); } } else { if(r.path != '/favicon.ico') update($('').addClass('weblog-error').html(onionshare.strings['other_page_loaded']+': '+r.path)); } } } setTimeout(check_for_requests, 1000); } }); } // initialize $.ajax({ url: '/init_info', success: function(data, textStatus, jqXHR){ onionshare = JSON.parse(data); $('#basename').html(onionshare.basename); $('#filesize .label').html(onionshare.strings['filesize']+':'); $('#filehash .label').html(onionshare.strings['sha1_checksum']+':'); $('#close-on-finish-wrapper label').html(onionshare.strings['close_on_finish']); $('#loading .calculating').html(onionshare.strings['calculating_sha1']); // after getting the initial info, start the onionshare server $.ajax({ url: '/start_onionshare', success: function(data, textStatus, jqXHR){ var data_obj = JSON.parse(data); onionshare.filehash = data_obj.filehash; onionshare.filesize = data_obj.filesize; onionshare.url = data_obj.url; $('#loading').remove(); $('#filesize .value').html(human_readable_filesize(onionshare.filesize)); $('#filehash .value').html(onionshare.filehash); $('#filesize').show(500); $('#filehash').show(500); update(''+onionshare.strings['give_this_url']+'
    '+onionshare.url+''); copy_to_clipboard(); $('#copy-button').show(); setTimeout(check_for_requests, 1000); } }); } }); // make sure the log always has a height set, so it will have its own scrollbar function set_log_height() { var new_height = $(document).height() - 140; // header = 100, footer = 40 $('#log').css('height', new_height); } set_log_height(); $.resize(set_log_height); });