// vim:set sw=4 ts=4 sts=4 ft=javascript expandtab: window.fc = 0; // Copy a link to clipboard function copyToClipboard(el) { el = el.previousSibling; var textArea = document.createElement('textarea'); textArea.style.position = 'fixed'; textArea.style.top = 0; textArea.style.left = 0; textArea.style.width = '2em'; textArea.style.height = '2em'; textArea.style.padding = 0; textArea.style.border = 'none'; textArea.style.outline = 'none'; textArea.style.boxShadow = 'none'; textArea.style.background = 'transparent'; textArea.value = el.value; document.body.appendChild(textArea); textArea.select(); try { var successful = document.execCommand('copy'); var msg = successful ? 'successful' : 'unsuccessful'; console.log('Copying text command was ' + msg); } catch (err) { el.focus(); var len = el.value.length * 2; el.setSelectionRange(0, len); alert(i18n.hit); } document.body.removeChild(textArea); } // Copy all links to clipboard function copyAllToClipboard() { var text = new Array(); var a = document.getElementsByClassName('link-input'); var i; for (i = 0; i < a.length; i++) { text.push(a[i].value); } var textArea = document.createElement('textarea'); textArea.style.position = 'fixed'; textArea.style.top = 0; textArea.style.left = 0; textArea.style.width = '2em'; textArea.style.height = '2em'; textArea.style.padding = 0; textArea.style.border = 'none'; textArea.style.outline = 'none'; textArea.style.boxShadow = 'none'; textArea.style.background = 'transparent'; textArea.value = text.join("\n"); document.body.appendChild(textArea); textArea.select(); try { var successful = document.execCommand('copy'); var msg = successful ? 'successful' : 'unsuccessful'; console.log('Copying text command was ' + msg); } catch (err) { textArea.style.width = ''; textArea.style.height = ''; textArea.style.background = '#FFFFFF'; alert(i18n.hits); } document.body.removeChild(textArea); } // Add item to localStorage function addItem(name, url, size, del_at_first_view, created_at, delay, short, token) { var files = localStorage.getItem('files'); if (files === null) { files = new Array(); } else { files = JSON.parse(files); } files.push({ name: name, short: short, url: url, size: size, del_at_first_view: del_at_first_view, created_at: created_at, delay: delay, token: token }); localStorage.setItem('files', JSON.stringify(files)); } // Remove a file block function destroyBlock(el) { el.parentNode.parentNode.remove(); var a = document.getElementsByClassName('link-input'); var l = document.getElementById('results').querySelector('li'); if (a.length === 0) { document.getElementById('misc').innerHTML = ''; if (l === null) { document.getElementById('results').style.display = 'none'; } } else { updateMailLink(); } } // Update the mail link function updateMailLink() { var a = document.getElementsByClassName('link-input'); var l = new Array(); var i; for (i = 0; i < a.length; i++) { l.push(a[i].id); } var u = baseURL+'m?links='+JSON.stringify(l); document.getElementById('mailto').href = u; } // Start uploading the files (called from and from drop zone) function handleFiles(f) { window.files = f; var r = document.getElementById('results'); r.style.display = 'block'; var delay = document.getElementById('delete-day'); var del_at_first_view = document.getElementById('first-view'); delay.setAttribute('disabled', 'disabled'); del_at_first_view.setAttribute('disabled', 'disabled'); uploadFile(0, delay.value, del_at_first_view.checked); } // 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); // Get the file and properties var file = window.files[i]; var name = file.name; var parts = Math.ceil(file.size/window.sliceLength); if (parts === 0) { parts = 1; } // Create a progress bar for the file var r = document.getElementById('ul-results'); var w = document.createElement('li'); w.setAttribute('class', 'list-group-item'); w.innerHTML='