-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
26 lines (23 loc) · 836 Bytes
/
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
var fileName;
var loadFile = function() {
const inputFile = document.getElementById('fileInput').files[0];
fileName = inputFile.name
const reader = new FileReader();
reader.readAsText(inputFile);
reader.onload = function(e) {
document.getElementById('editor').value = e.target.result
document.getElementById('fileName').value = fileName
};
}
var downloadNewFile = function() {
updatedText = document.getElementById('editor').value;
var outputFile = new Blob([updatedText], {type: 'text/plain'});
var downloadLink = document.createElement('a');
downloadLink.setAttribute('href', URL.createObjectURL(outputFile));
downloadLink.setAttribute('download', fileName);
downloadLink.click();
document.body.removeChild(downloadLink);
}
var updateFileName = function() {
fileName = document.getElementById('fileName').value
}