-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
42 lines (30 loc) · 1.01 KB
/
main.js
File metadata and controls
42 lines (30 loc) · 1.01 KB
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
const saveButton = document.querySelector('#saveButton');
const writerContent = document.getElementById('writerContent')
saveButton.addEventListener('click', () =>
{
// Open input dialogue
const fileName = prompt('Enter the name of the file:');
// Save file with name and contents
const fileContents = writerContent.value;
const blob = new Blob([fileContents], { type: 'text/plain' });
const link = document.createElement('a');
link.href = URL.createObjectURL(blob);
link.download = fileName;
link.click();
});
document.getElementById("openFile").addEventListener("click", function()
{
var input = document.createElement("input");
input.type = "file";
input.onchange = function(event)
{
var file = event.target.files[0];
var reader = new FileReader();
reader.onload = function() {
var text = reader.result;
writerContent.value = text;
};
reader.readAsText(file);
};
input.click();
});