Skip to content

Commit

Permalink
Create index.html
Browse files Browse the repository at this point in the history
  • Loading branch information
GusInfiniteLinesOfCode authored Nov 4, 2023
1 parent 185115f commit 52d0053
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Text File Editor</title>
</head>
<body>

<textarea id="textArea" rows="10" cols="30"></textarea><br>

<button onclick="saveText()">Save</button>
<button onclick="loadText()">Load</button>

<script>
function saveText() {
var textToSave = document.getElementById('textArea').value;
var blob = new Blob([textToSave], { type: 'text/plain' });
var a = document.createElement('a');
a.href = URL.createObjectURL(blob);
a.download = 'textfile.txt';
a.click();
}

function loadText() {
var input = document.createElement('input');
input.type = 'file';
input.accept = 'text/plain';

input.onchange = function (event) {
var file = event.target.files[0];
if (!file) {
return;
}

var reader = new FileReader();
reader.onload = function (e) {
document.getElementById('textArea').value = e.target.result;
};
reader.readAsText(file);
};

input.click();
}
</script>

</body>
</html>

0 comments on commit 52d0053

Please sign in to comment.