2014-06-06 21:20:57 -04:00
|
|
|
$(function(){
|
2014-06-06 21:54:08 -04:00
|
|
|
var onionshare = {}
|
2014-06-06 21:20:57 -04:00
|
|
|
|
|
|
|
function update($msg) {
|
2014-06-08 13:15:39 -04:00
|
|
|
var $line = $('<li>').append($msg);
|
|
|
|
$('#log').append($line);
|
2014-06-06 21:20:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function copy_to_clipboard() {
|
|
|
|
$.ajax({
|
|
|
|
url: '/copy_url',
|
|
|
|
success: function(data, textStatus, jqXHR){
|
2014-06-06 22:00:18 -04:00
|
|
|
update(onionshare.strings['copied_url']);
|
2014-06-06 21:20:57 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
$('#copy-button').click(copy_to_clipboard);
|
|
|
|
|
2014-06-06 21:54:08 -04:00
|
|
|
var REQUEST_LOAD = 0;
|
|
|
|
var REQUEST_DOWNLOAD = 1;
|
2014-06-11 19:45:10 -04:00
|
|
|
var REQUEST_PROGRESS = 2;
|
|
|
|
var REQUEST_OTHER = 3;
|
2014-06-06 21:54:08 -04:00
|
|
|
function check_for_requests() {
|
|
|
|
$.ajax({
|
2014-06-11 19:55:28 -04:00
|
|
|
url: '/heartbeat',
|
2014-06-06 21:54:08 -04:00
|
|
|
success: function(data, textStatus, jqXHR){
|
|
|
|
if(data != '') {
|
2014-06-11 19:55:28 -04:00
|
|
|
var events = JSON.parse(data);
|
|
|
|
for(var i=0; i<events.length; i++) {
|
|
|
|
var r = events[i];
|
|
|
|
|
|
|
|
if(r.type == REQUEST_LOAD) {
|
|
|
|
update($('<span>').addClass('weblog').html(onionshare.strings['download_page_loaded']));
|
|
|
|
} else if(r.type == REQUEST_DOWNLOAD) {
|
|
|
|
var $download = $('<span>')
|
|
|
|
.attr('id', 'download-'+r.data.id)
|
|
|
|
.addClass('weblog').html(onionshare.strings['download_started'])
|
|
|
|
.append($('<span>').addClass('progress'));
|
|
|
|
update($download);
|
|
|
|
} else if(r.type == REQUEST_PROGRESS) {
|
2014-06-11 20:05:15 -04:00
|
|
|
// is the download complete?
|
|
|
|
if(r.data.bytes == onionshare.filesize) {
|
|
|
|
$('#download-'+r.data.id).html(onionshare.strings['download_finished']);
|
2014-06-11 20:53:19 -04:00
|
|
|
|
|
|
|
// 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($('<span>').attr('id', 'close-countdown'));
|
|
|
|
close_countdown(3);
|
|
|
|
}
|
2014-06-11 20:05:15 -04:00
|
|
|
}
|
|
|
|
// still in progress
|
|
|
|
else {
|
2014-06-11 19:55:28 -04:00
|
|
|
var percent = Math.floor((r.data.bytes / onionshare.filesize) * 100);
|
|
|
|
$('#download-'+r.data.id+' .progress').html(' '+human_readable_filesize(r.data.bytes)+', '+percent+'%');
|
2014-06-11 20:05:15 -04:00
|
|
|
}
|
2014-06-11 19:55:28 -04:00
|
|
|
} else {
|
|
|
|
if(r.path != '/favicon.ico')
|
|
|
|
update($('<span>').addClass('weblog-error').html(onionshare.strings['other_page_loaded']+': '+r.path));
|
|
|
|
}
|
2014-06-06 21:54:08 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setTimeout(check_for_requests, 1000);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-06-09 21:07:18 -04:00
|
|
|
// initialize
|
2014-06-06 21:20:57 -04:00
|
|
|
$.ajax({
|
2014-06-09 21:07:18 -04:00
|
|
|
url: '/init_info',
|
2014-06-06 21:20:57 -04:00
|
|
|
success: function(data, textStatus, jqXHR){
|
|
|
|
onionshare = JSON.parse(data);
|
|
|
|
|
|
|
|
$('#basename').html(onionshare.basename);
|
2014-06-09 21:07:18 -04:00
|
|
|
$('#filesize .label').html(onionshare.strings['filesize']+':');
|
|
|
|
$('#filehash .label').html(onionshare.strings['sha1_checksum']+':');
|
2014-06-11 20:53:19 -04:00
|
|
|
$('#close-on-finish-wrapper label').html(onionshare.strings['close_on_finish']);
|
2014-06-09 21:07:18 -04:00
|
|
|
$('#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;
|
2014-06-06 21:20:57 -04:00
|
|
|
|
2014-06-09 21:07:18 -04:00
|
|
|
$('#loading').remove();
|
|
|
|
|
2014-06-11 19:45:10 -04:00
|
|
|
$('#filesize .value').html(human_readable_filesize(onionshare.filesize));
|
2014-06-09 21:07:18 -04:00
|
|
|
$('#filehash .value').html(onionshare.filehash);
|
|
|
|
$('#filesize').show(500);
|
|
|
|
$('#filehash').show(500);
|
|
|
|
|
|
|
|
update('<span>'+onionshare.strings['give_this_url']+'</span><br/><strong>'+onionshare.url+'</strong>');
|
|
|
|
copy_to_clipboard();
|
|
|
|
$('#copy-button').show();
|
|
|
|
|
|
|
|
setTimeout(check_for_requests, 1000);
|
|
|
|
}
|
|
|
|
});
|
2014-06-06 21:20:57 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|