65 lines
1.9 KiB
JavaScript
65 lines
1.9 KiB
JavaScript
var fileobj;
|
|
function file_dropped(e)
|
|
{
|
|
e.preventDefault();
|
|
fileobj = e.dataTransfer.files[0];
|
|
filename = e.dataTransfer.files[0].name;
|
|
upload_file(fileobj,filename);
|
|
}
|
|
|
|
function file_explorer() {
|
|
document.getElementById('uploadfile').click();
|
|
document.getElementById('uploadfile').onchange = function()
|
|
{
|
|
fileobj = document.getElementById('uploadfile').files[0];
|
|
filename = document.getElementById('uploadfile').files[0].name;
|
|
upload_file(fileobj,filename);
|
|
};
|
|
}
|
|
|
|
function copytoclipboard()
|
|
{
|
|
var elm = document.getElementById("divresponse");
|
|
var selection = window.getSelection();
|
|
var range = document.createRange();
|
|
range.selectNodeContents(elm);
|
|
selection.removeAllRanges();
|
|
selection.addRange(range);
|
|
document.execCommand("Copy");
|
|
}
|
|
|
|
function upload_file(file_obj,file_name)
|
|
{
|
|
var divresponse = document.getElementById('divresponse');
|
|
divresponse.innerHTML = "Uploading file..." ;
|
|
const request = async () => {
|
|
var response = await fetch('/index.php?name=' + file_name, {
|
|
method: 'PUT',
|
|
body: file_obj
|
|
});
|
|
var text = await response.text();
|
|
console.log(text);
|
|
divresponse.innerHTML = text ;
|
|
document.getElementById('copytoclipboard').style.visibility = "visible";
|
|
|
|
}
|
|
request();
|
|
|
|
}
|
|
|
|
|
|
function change_color_ondrag(event)
|
|
{
|
|
if (event === "ondragenter")
|
|
{
|
|
var element = document.getElementById('dragzone');
|
|
element.classList.add("dragover");
|
|
}
|
|
else if (event === "ondragleave")
|
|
{
|
|
var element = document.getElementById('dragzone');
|
|
element.classList.remove("dragover");
|
|
}
|
|
}
|
|
|