-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
44 lines (40 loc) · 1.26 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
function saveFile() {
let file = document.getElementById("file").files[0];
if (file) {
let reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = function (event) {
let files = JSON.parse(localStorage.getItem("files")) || [];
let fileData = {
name: file.name,
type: file.type,
data: event.target.result
};
files.push(fileData);
localStorage.setItem("files", JSON.stringify(files));
displayFiles();
alert("File saved to the cloud.");
}
}
}
function displayFiles() {
let files = JSON.parse(localStorage.getItem("files")) || [];
let list = document.getElementById("fileList");
list.innerHTML = "";
files.forEach(function (fileData) {
let li = document.createElement("li");
let a = document.createElement("a");
a.className = "textstyle3";
a.href = fileData.data;
a.download = fileData.name;
a.innerHTML = fileData.name;
li.appendChild(a);
list.appendChild(li);
});
}
function clearFiles() {
localStorage.removeItem("files");
displayFiles();
alert("All files removed from the cloud.");
}
displayFiles();