diff --git a/public/js/lufi-down.js b/public/js/lufi-down.js index 0a8f863..af98a41 100644 --- a/public/js/lufi-down.js +++ b/public/js/lufi-down.js @@ -71,6 +71,7 @@ function spawnWebsocket() { pbd.innerHTML = ''+i18n.download+''; ws.send('{"ended":true}'); + window.onbeforeunload = null; } else { if (ws.readyState === 3) { ws = spawnWebsocket(); @@ -83,11 +84,14 @@ function spawnWebsocket() { console.log('error'); } } - // When it's ready document.addEventListener('DOMContentLoaded', function() { window.a = new Array(); window.key = pageKey(); + // Set websocket ws = spawnWebsocket(); + + // Prevent exiting page before full download + window.onbeforeunload = confirmExit; }); diff --git a/public/js/lufi-up.js b/public/js/lufi-up.js index 2897253..69d9fe2 100644 --- a/public/js/lufi-up.js +++ b/public/js/lufi-up.js @@ -93,6 +93,8 @@ function handleFiles(f) { // Create progress bar and call slicing and uploading function function uploadFile(i, delay, del_at_first_view) { + // Prevent exiting page before full upload + window.onbeforeunload = confirmExit; // Create a random key, different for all files var randomkey = sjcl.codec.base64.fromBits(sjcl.random.randomWords(8, 0), 0); @@ -211,6 +213,8 @@ function updateProgressBar(data) { if (i < window.files.length) { uploadFile(i, delay, del_at_first_view); } else { + // We have finished + document.onbeforeunload = null; document.getElementById('delete-day').removeAttribute('disabled'); document.getElementById('first-view').removeAttribute('disabled'); } diff --git a/templates/index.html.ep b/templates/index.html.ep index 2aeca69..a4bdfbd 100644 --- a/templates/index.html.ep +++ b/templates/index.html.ep @@ -65,6 +65,7 @@ var i18n = { delText: '<%= l('Deletion link') %>', dlText: '<%= l('Download link') %>', download: '<%= l('Download') %>', + confirmExit: '<%= l('You have attempted to leave this page. The upload will be canceled. Are you sure?') %>', hit: '<%= l('Hit Enter, then Ctrl+C to copy the download link') %>', hits: '<%= l('Hit Enter, then Ctrl+C to copy all the download links') %>', } diff --git a/templates/layouts/default.html.ep b/templates/layouts/default.html.ep index eee7d68..6672d4e 100644 --- a/templates/layouts/default.html.ep +++ b/templates/layouts/default.html.ep @@ -20,6 +20,12 @@ %= stylesheet '/css/cover.css' %= stylesheet '/css/lufi.css' %= stylesheet '/css/fontello.css' + %= javascript begin + function confirmExit() { + console.log(i18n.confirmExit); + return i18n.confirmExit; + } + % end